[Solved] Synchronize programmatically created animation with Spritemap


(Vampir) #1

Hello :smile: I have an entity which is a soldier. I use Graphiclist for it’s Graphic. When soldier stands he is breathing (this is 1st layer of his animation), so his hands are moving up and down. Second layer of soldier’s graphic is a gun which I want move up and down to follow soldier’s hands. This is an array of gun’s y-offset values for “stand” animation:

private static const gun_offset_y_frames:Array =
		[0, -1, 0, 1];

This is a part of update() function where I’m trying to move gun to follow soldier’s hands:

grp_gun.y = gun_base_y + gun_offset_y_frames[grp_anim.frame];

But gun changing it’s position in the next frame, so I can’t achieve full syncronization, and gun is like flying near soldier. Please tell me what is my mistake? Should I choose another place (event/function) to move gun?

Sorry for my english… I hope my question is understandable.


(Ultima2876) #2

Firstly, try moving your code to the other side of the super.update() call in your update() function (if you don’t have super.update(), you should add it. This is where the entity position stuff is usually worked out).

If that doesn’t work, you can override render() in the entity and put your code there (again, make sure to have super.render() in that function and try putting your code before/after it).


(Vampir) #3

I tried it today. Before super.update(), after it - doesn’t work like I want it to work. So ok I will work with render function. Thank you :smile:


(Vampir) #4

I’ve put gun-moving line of code inside overrided render function just before super.render() and woo-hoo now it works fine :slight_smile: