I need help implimenting sprite movement in gage.
I can’t seem to get the sprite to stop at map boundaries.
here is some code, but the sprite still goes past the map. Also I can only return to the sprites origin. i.e. if
i start at 400,300, I cant walk back to 0,0.
public static void render(Graphics g)
{
if(parallax != null)
{
parallax.render(g);
// heroSprite.render(g, -parallax.getX(), -parallax.getY());
heroSprite.render(g, 0, 0);
if(heroSprite.getX() < parallax.getX()+parallax.getWidth() )
{
//Move fighter
heroSprite.setX(heroSprite.getX()+dirx+40);
}
if(heroSprite.getY() < parallax.getPixelsY())
{
heroSprite.setY(heroSprite.getY()+diry+40);
}
}
}