I have a scene that is 2000 x 2000. I have the background and objects in place, the solid objects and collision masks are working fine and I have made good headway on the player movement but my main issue is the game view not scrolling with the player.
I have tried to set the view at 2000 x 2000 and set the camera to focus on player at start but the view opens to the bottom right corner and not on the player. I can find no solid info on this in the Wiki so I set the view back to 800 x 600 which does allow me to start on the player but now I cannot get the game view to scroll with the player as the player moves off the edge of the current view window. I know how to set the bounds and all, that is not the problem. I cannot scroll with the player to the boundaries of the scene. I read the turret game tutorial but this nor any other tutorial addresses player movement in top down, these always seem to deal with a stationary player with other objects moving around it. I want my player to move freely with player input. I have WASD set up and mostly have the physics working right (still trying to get the player to stop completely when multiple directions are being used to move around corners, force needs a better breaking system)
This is top down so I need more flexibility than just left and right scrolling as with a platform. Any help will be mucho appreciated.
In the game I’m currently writing, I have a setup like this:
Moving up
Conditions:
The key w is pressed :[/code]
Actions: [code]Do -32 to y position of player
Do +1 to Variable(playerymoves)
Sub-Event - Conditions:
Variable(playerymoves) > 8)
Sub-Event - Actions:
Centre Camera on player
Moving down
The key s is pressed :[/code]
Actions: [code]Do +32 to y position of player
Do -1 to Variable(playerymoves)
Sub-Event - Conditions:
Variable(playerymoves) < -8)
Sub-Event - Actions:
Centre Camera on player
And a similar thing for moving left/right. Obviously, this is not the only way to do this, but it works quite nicely. You have to adjust the values (where I put an 8) according to your game. In my game, when you’re about 3 tiles from the edge the screen scrolls.
Note however that is generally a bad idea to do things like “+5 to the X/Y position of something”, because it is dependant of the framerate of your game (usually 60fps).
See the last paragraph of this article : wiki.compilgames.net/doku.ph … s_concepts
The good way of doing this is to replace “+5 to the X/Y position of something” with “+100*TimeDelta() to the X/Y position of something”. Here 100 is the number of pixel per second that will be added to the position, so you can indicate exactly the speed you want and the speed won’t be altered on other computer that might render the game faster or slower.
Yes what 4ian said is true and very important. I have my function (that I explained above) set to a timer (of 0.15s), so it is not dependent on frame rate. It has to be set to a timer or timedelta() otherwise it will have inconsistent behavior.