Ok so I have this little problem. The hud of the game follows the camera.And the camera follows player. Everithing worked good and nice but suddenly I got this bug.When the player moves,the camera follows him,but the hud is like rendered 1 frame after,becose it moves after camera 1 frame after the camera actually moves. There is any way to fix this problem? Thx guys .
Render on the world problems[SOLVED]
I guess you’re doing something like this in your hud entity:
override public function update():void
{
hud.x = camera.x
hud.y = camera.y
}
You could either change this to happen inside the render() function instead of update() like this:
override public function render():void
{
hud.x = camera.x
hud.y = camera.y
}
I think that should work. Or you could do it a lot more elegantly by not changing the x and y coordinates at all but instead using scrollX and scrollY. So, remove the hud.x = camera.x, hud.y = camera.y from you update() / render() function and instead do this:
private var myhudimage:Image = new Image(...);
public function Hud()
{
x = 0;
y = 0;
myhudimage.scrollX = 0;
myhudimage.scrollY = 0;
graphic = (myhudimage);
super();
}
If you use this scrollX and scrollY property (which every Image, Spritemap… has) the hud/image will always stay on the same position even if your camera moves. Where the value 0 = stick to the screen and the value 1 = move independent from the camera.
I hope this helps.
very nice O: never thought to use scroolx and y but ill go with render one cuz i make some other changes with the entity’s y and i need the image to go after entity . Thx bro :D.