D
Drago Supremo
Guest
Hi everyone,
I've recently added a view system in my game (here's the code):
The horizontal view works fine, but using the vertical view i get a strange effect when the player is jumping and is about to reach its maximum jump height. In fact it's like it shift for some pixels higher.
Here's the code for variable jump and gravity:
Jump:
Gravity:
Things i've already tried:
- I know that Game Maker has some problems drawing objects at non-integer coordinates, so i tried setting the gravity to 1 instead of 0.4 (even if it was much better);
- I tried setting room's speed to 60 fps to make the game smoother, but it didn't work.
I hope i explained myself sufficiently well and thank you in advance for your help.
I've recently added a view system in my game (here's the code):
Code:
//Sets the view borders
leftBorderAxis = view_xview + view_hborder;
rightBorderAxis = view_xview + view_wview - view_hborder;
//Calculates player's relative position to the borders
difLeft = spr_player.x - leftBorderAxis;
difRight = spr_player.x - rightBorderAxis;
//Sets the view's speed if player's direction and the touching border coincide
if ((difLeft < 0) and (spr_player.hsp < 0)) or ((difRight > 0) and (spr_player.hsp > 0)) viewHoSpeed = spr_player.hsp else viewHoSpeed = 0;
//Checks if the view is about to exit the room and moves it to the edge
if (view_xview + viewHoSpeed < 0) or (view_xview + view_wview + viewHoSpeed > room_width)
{
while !(view_xview + viewHoSpeed < 0) and !(view_xview + view_wview + viewHoSpeed > room_width) view_xview += sign(viewHoSpeed)
viewHoSpeed = 0;
}
//Moves the view
view_xview += viewHoSpeed;
//Sets the view borders
topBorderAxis = view_yview + view_vborder;
bottomBorderAxis = view_yview + view_hview - view_vborder;
//Calculates player's relative position to the borders
difTop = spr_player.y - topBorderAxis;
difBottom = spr_player.y + view_yview - bottomBorderAxis;
//Sets the view's speed if player's direction and the touching border coincide
if ((difTop < 0) and (spr_player.vsp < 0)) or ((difBottom > 0) and (spr_player.vsp > 0)) viewVoSpeed = spr_player.vsp else viewVoSpeed = 0;
//Checks if the view is about to exit the room and moves it to the edge
if (view_yview + viewVoSpeed < 0) or (view_yview + view_hview + viewVoSpeed > room_height)
{
while !(view_yview + viewVoSpeed < 0) and !(view_yview + view_hview + viewVoSpeed > room_height) view_yview += sign(viewVoSpeed)
viewVoSpeed = 0;
}
//Moves the view
view_yview += viewVoSpeed;
Here's the code for variable jump and gravity:
Jump:
Code:
if (vsp < 0) and !(key_jump) vsp = max(vsp, 0);
Code:
if (vsp <= 10)
{
vsp += grav;
}
- I know that Game Maker has some problems drawing objects at non-integer coordinates, so i tried setting the gravity to 1 instead of 0.4 (even if it was much better);
- I tried setting room's speed to 60 fps to make the game smoother, but it didn't work.
I hope i explained myself sufficiently well and thank you in advance for your help.