NimonoSolenze
Member
I'm trying to make a small horizontal shmup right now, in the style of Gradius- the camera will move along a track, but the position of the player and their shots will be fixed relative to the screen- so if, for example, the player is 200 pixels away from the left edge of the screen, they'll always appear there, unmoving unless the player makes an input, even as the screen scrolls one pixel to the right every 2 frames.
For some reason, though, I just cannot make this work properly- before, I tried keeping track of when the camera's changed position and added that to the player's position so it'd look as if the player was unmoving but the world moves around them. This worked...until you touched the edge of the screen, then suddenly it all desynced- the frame the camera moved, the player thought it didn't, so the visuals would jitter. Thus, I changed it to where now every frame it's placed at a position relative to the position of the camera, which makes sense...and it jitters every single frame now. I've tried putting that in Step. I've tried Begin Step. I've tried End Step. Nope, it still jitters. I move the camera by letting the engine do that for me- it follows an object that moves on its own- so I've tried changing which of those its movement coded uses- same effect. I just do NOT understand what the hell is going on!
My code is simple: on the player object, every frame I set its X and Y to
camX and camY are the positions from the top-left corner of the camera that the player should sit at. I floor them because I want to use fractional values for slower speeds, but I also want to stick to actual pixels instead of getting into weird subpixel stuff.
The code for positioning the camera object:
xreal and yreal are done similarly as camX and camY on the player- used to store fractional values, which are then floored to get the actual x and y position in full pixels. (Typing this, I realize I could probably use frac() somehow to simply remove the decimal value so something like -0.5 won't be floored down to -1, but whatever.)
The speed variables are set by player input only for the player object and are reset after use so no input will always be no movement, and are set by other triggers for the camera and are not reset until changed so the camera keeps moving. The view is set to follow this object, and movement of THAT is smooth- just nothing else. I've even set up a dummy object whose only code is to be 64 pixels from the left of the camera and 128 pixels from the top, and even that jitters around! If I set the camera's speed to a whole number, the jittering is gone, but it still lags behind by a frame, which I do not want. Even changing the Instance Creation Order so the player object is created first changes nothing What am I doing wrong? Is there even a way to fix this? I've been told before when talking about me coding in collisions myself to just enable engine physics so the engine can do that itself, but in this case, is the opposite the best choice- would it be better for me to just manually control the screen scrolling, even though that also means having to manually stop the camera from going out-of-bounds?
For some reason, though, I just cannot make this work properly- before, I tried keeping track of when the camera's changed position and added that to the player's position so it'd look as if the player was unmoving but the world moves around them. This worked...until you touched the edge of the screen, then suddenly it all desynced- the frame the camera moved, the player thought it didn't, so the visuals would jitter. Thus, I changed it to where now every frame it's placed at a position relative to the position of the camera, which makes sense...and it jitters every single frame now. I've tried putting that in Step. I've tried Begin Step. I've tried End Step. Nope, it still jitters. I move the camera by letting the engine do that for me- it follows an object that moves on its own- so I've tried changing which of those its movement coded uses- same effect. I just do NOT understand what the hell is going on!
My code is simple: on the player object, every frame I set its X and Y to
GML:
camX += HorzSpeed;
camY += VertSpeed;
x = camera_get_view_x(view_camera[0]) + floor(camX);
y = camera_get_view_y(view_camera[0]) + floor(camY);
The code for positioning the camera object:
Code:
xreal += xspeed;
yreal += yspeed;
x = floor(xreal);
y = floor(yreal);
The speed variables are set by player input only for the player object and are reset after use so no input will always be no movement, and are set by other triggers for the camera and are not reset until changed so the camera keeps moving. The view is set to follow this object, and movement of THAT is smooth- just nothing else. I've even set up a dummy object whose only code is to be 64 pixels from the left of the camera and 128 pixels from the top, and even that jitters around! If I set the camera's speed to a whole number, the jittering is gone, but it still lags behind by a frame, which I do not want. Even changing the Instance Creation Order so the player object is created first changes nothing What am I doing wrong? Is there even a way to fix this? I've been told before when talking about me coding in collisions myself to just enable engine physics so the engine can do that itself, but in this case, is the opposite the best choice- would it be better for me to just manually control the screen scrolling, even though that also means having to manually stop the camera from going out-of-bounds?
Last edited: