Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by davidx

Hi,

I am trying to animate a background but I am having no joy.

I have a simple level with my player background collision and a placeholder background (same dimensions as background).

I have a changeState function in main.js and this is where I am trying to add the animation sheet.
var blink = new ig.AnimationSheet('media/hi_res/eyes.png', 64, 64);
				this.backgroundAnims['media/hi_res/placeholder.png'] = {
				    1: new ig.Animation( blink, 0.1, [0,1,2] )
				};
				
				//goto next level of exists else game over
				if(!this.myDirector.nextLevel()) {
					this.changeState(this.STATE.GAMEOVER);
				}

As per the doc, I am doing this prior to loading the level (I am using a members director plug in)

My placeholder is a single red square for illustrative purposes and looks like this in the level:

{"name":"placeholder","width":20,"height":10,"linkWithCollision":false,"visible":true,"tilesetName":"media/hi_res/placeholder.png","repeat":true,"distance":"1","tilesize":64,"foreground":false,"data":[[1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
...

I would expect the above code to have replaced the second tile with the animation, but it remains as a red block. I have tried putting a load of animations, just in case I am missing it, but to no avail:

var blink = new ig.AnimationSheet('media/hi_res/eyes.png', 64, 64);
				this.backgroundAnims['media/hi_res/placeholder.png'] = {
				    1: new ig.Animation( blink, 0.1, [0,1,2] ),
				    11: new ig.Animation( blink, 0.1, [0,1,2] ),
				    21: new ig.Animation( blink, 0.1, [0,1,2] ),
				    31: new ig.Animation( blink, 0.1, [0,1,2] ),
				    41: new ig.Animation( blink, 0.1, [0,1,2] ),
				    51: new ig.Animation( blink, 0.1, [0,1,2] ),
				    61: new ig.Animation( blink, 0.1, [0,1,2] ),
				    71: new ig.Animation( blink, 0.1, [0,1,2] ),
				    81: new ig.Animation( blink, 0.1, [0,1,2] )
				};

Can anyone point me in the direction of what I am doing wrong.

NOTE: I have not set the backgrounds to prerender.

Thanks,

D

1 decade ago by samgreen

Are you updating and drawing the animation in your game update and draw methods? You will probably need to refactor the blink variable to a class variable. Can you post your entire class on pastebin?

1 decade ago by davidx

Hi Sam,
no, I'm not updating in the draw or update. Do you have a simple example?

When you say post the entire class, do you mean main or the animation class? As I have no animation class...? Dok need to define a separate obj for that background?
thanks.

1 decade ago by davidx

I have solved this by using a larger placeholder background tile set, not sure why this works, but it does!
Page 1 of 1
« first « previous next › last »