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 Axel

Hey guys!

I'm stuck on something which might have a super simple answer but need help...

I'm working a pong (the basics!) and right now I'm trying to add bonuses, more precisely a bonus which would make the paddle bigger (92px height instead of 64px), I tried to change the animsheet and create new animation but sprite won't change.

The problem is only visual as I see the paddle collide correctly (so its height was correctly set to 92px)

any help would be greatly appreciated!

thank you

1 decade ago by Hareesun

Is the image the right height and everything? I've found using the BoxOutline plugin is really helpful when measuring up images and seeing whats wrong. :)

1 decade ago by Axel

thank you for your answer,

basically, the height is good, the problem is the animation.

This is my paddle class

animSheet: new ig.AnimationSheet( 'media/paddlepong.png', 16, 64 ),

and then, in my update function, I tried to do that:

ig.game.kevin.size.y = 92;
ig.game.kevin.animSheet = new ig.AnimationSheet( 'media/bigpaddle.png', 16, 92 );
ig.game.kevin.anims.idle = new ig.Animation(ig.game.kevin.animSheet, 'idle', 1, [0] );

it won't change the view.

1 decade ago by dominic

I think the problem is that the entities&039;s #.currentAnim is not updated. I.e. just swapping out the animation in .anims won&039;t help, when #.currentAnim still points to the old one.

You could also specify the big paddle as another animation when the entity is created, so that you have this.anims.idle and this.anims.idleBig. Then when you change the size, just set this.currentAnim = this.anims.idleBig;


By the way: you should have your second animation sheet as a class property, to ensure that it's loaded by the preloader. See Working with Assets.
E.g.:

MyEntity = ig.Entity.extend({
	animSheet: new ig.AnimationSheet( 'media/paddle.png', 16, 64 ),
	animSheetBig: new ig.AnimationSheet( 'media/bigpaddle.png', 16, 96 ),
	…
});

1 decade ago by Axel

Thank you for your answer,

sorry to bother you, but i'm new to programming...

I have created those 2 animSheets in the paddle Entity:
animSheet: new ig.AnimationSheet( 'media/paddlepong.png', 16, 64 ),
animSheetBig: new ig.AnimationSheet( 'media/bigpaddle.png', 16, 96 ),

and then, wrote this in the init function:

this.addAnim( 'idle', 1, [0] );
this.anims['idleBig']= new ig.Animation(this.animSheetBig, 'idleBig', 1, [0] );

this in the update function:

update: function() {
	if(this.state == "bigger" && this.reduce.delta() >= 0) {
		this.state = "normal";
		this.currentAnim = this.anims.idle;
		this.size.y = 64;
		this.reduce = null;
	}
	this.parent();
}

and this in the check function of the puck:

} else
if (other instanceof EntityBigger) {
	ig.game.kevin.state = "bigger";
	ig.game.kevin.size.y = 96;
	ig.game.kevin.currentAnim = ig.game.kevin.anims.idleBig;
	ig.game.kevin.reduce = new ig.Timer (5);
	other.kill();
}

but when i run the game, i get this error:

An invalid or illegal string was specified" code: "12
tileHeightScaled

and when the state of the paddle comes back "normal", i don't have errors anymore.

Thank you Dominic

1 decade ago by dominic

The second parameter in your ig.Animation constructor shouldn't be there. See ig.Animation. It's just
new ig.Animation( sheet, frameTime, sequence, [stop] )

Have a look at what addAnim() in lib/impact/entity.js does - you need to specify a name there, because the newly created animation is automatically put into this.anims[name] (see .addAnim). The animation constructor itself has no use for a name.

You could also use the Animation constructor instead of addAnim() for your "normal" animation. This will make it a bit more clear what's going on:

this.anims.idle = new ig.Animation(this.animSheet, 1, [0] );
this.anims.idleBig = new ig.Animation(this.animSheetBig, 1, [0] );

One more thing: I noticed you wrote anims['idleBig'] instead of anims.idleBig - that's not wrong in any way, but the dot notation is a bit shorter :)
var name = 'bar';

// These three lines all do the same:
foo.bar= 'baz';
foo['bar'] = 'baz';
foo[name] = 'baz';

1 decade ago by Axel

thank you very much!

everything works now.
Page 1 of 1
« first « previous next › last »