[Solved] Camera Goes To Wrong Position When Going Full Screen

I have been working on a game where I need 2d functionality for some levels and 3d for others (I am very excited to show you all the finished game once I have it done).

To do this, I have been trying to combine elements from: Dragosha’s lights and shadows project:
Releases · Dragosha/defold-light-and-shadows · GitHub

With the simple 2d lighting from Britzl.
Simple 2D Lighting - Questions - Defold game engine forum

This worked fine for a while, but I took a month break from the project. When I came back, the full screen functionality had issues.
On the 2d stage, it zoomed into the corner (it looks like it’s just focusing on point 0,0,0).
On the 3d stage, the camera looks in a slightly different direction (up and to the right).

Game running at normal size:

Game running at full screen:

I don’t see anything in the release notes that would have changed anything.

Render scripts are mostly beyond my level, so I have a hard time trying to trouble shoot or locate issues.

Any ideas for what might be causing this?

I can share a copy of what I have so far if needed.

I may go back to a previous version of the engine which was working for me for the time being.

1 Like

I think this is caused by the camera’s position , I see that it stuck and does not follow the player , check the game-object’s position

Maybe there is a way to make the camera automatically pick the center of the world

what is clear is the the world got bigger but the camera’s position is still the same , interesting .

I’ll wait just next to you until someone can help

What if you make the camera follow an invisible game-object that is always in the center of the level ? this way it will always centered because you centered the game-object , is it possible ?

I’m assuming that you do not want the camera to follow the player .

Thanks for the idea! The camera is following the player when it goes to full screen, it seems as if there is some sort of offset occurring.

Here is a video that helps show what I am dealing with:

I was able to figure out the 2d issue, in my render script I had forgotten to include the code:

-- recreate render targets if screen size has changed
local window_width = render.get_window_width()
		local window_height = render.get_window_height()
		if self.width ~= window_width or self.height ~= window_height then
			self.width = window_width
			self.height = window_height
			create_render_targets(self)
			render.set_viewport(0, 0, self.width, self.height)
		end

I am still looking into my 3d issue

1 Like

I was able to track down the 3d issue too!

When the window resized to fullscreen, the game was recalculating the mouse pos and was adjusting the camera to where it believed the player had moved the mouse (the mouse had not moved, just the window expanding to fullscreen).

I’ve added a 1 second delay to prevent mouse input from being utilized when expanding the window. It is not ideal, and I’ll find a better solution as I continue to play around with this. But currently this is the best solution I have.

self.resizeDelay = false
	window.set_listener(function(self, event, data)
		if event == window.WINDOW_EVENT_RESIZED then
			self.resizeDelay = true
			timer.delay(1, false, function(self)
				self.resizeDelay = false
			end)
		end
	end)
2 Likes