How do I detect if sprite should be going up or down?
Posted
by
Geore Shg
on Game Development
See other posts from Game Development
or by Geore Shg
Published on 2012-04-03T00:51:42Z
Indexed on
2012/04/03
5:41 UTC
Read the original article
Hit count: 243
I use the following code to detect if a sprite should be going up or down:
If (pos.Y + 100) >= Sprite.BottomY Then
Going_up = True
pos.Y = Sprite.BottomY - 130
End If
If pos.Y <= Sprite.TopY Then
Going_up = False
pos.Y = Sprite.TopY - 1
Vel.Y = 3
End If
Then my response code:
If Going_up Then
Vel.Y -= CSng(gameTime.ElapsedGameTime.TotalMilliseconds / 40)
pos.Y -= Vel.Y
Else
Vel.Y += CSng(gameTime.ElapsedGameTime.TotalMilliseconds / 40)
pos.Y += Vel.Y
End If
Sprite.velocity = Vel
Sprite.position = pos
But it's pretty terrible. It only works when the sprite starts at the top, and when I want to change the BottomY
and TopY
, it just starts glitching. What is a better to detect if the sprite should be going up or down?
© Game Development or respective owner