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).
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).
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 .
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
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)