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 anasbud

Hi everyone,

I would like to create a kind of floating effect on my entities.

Something like this : http://i.imgur.com/RqS1iRt.gif

How can I proceed ?


Thanks

1 decade ago by stillen

It would probably be better to have the animation actually handle the bounce if its going to be simple like your example.

You could also do something like this. This was a simple bouncy laser I made for a game.
EntityBlueshot = EntityBaseammo.extend({
	animSheet: new ig.AnimationSheet('media/Ammo.png',32,32),
	size: {x :16, y:16},
	offset:{x:8,y:8},
	maxVel:{x:600, y:0},
	maxHeight:null,
	minHeight:null,
	movingUp:true,
	init: function(x,y,settings){
		this.parent(x,y,settings);
		this.addAnim('idle',0.1,"6-7");
		this.currentAnim = this.anims.idle;
		this.currentAnim.alpha = 0.4;
		this.maxHeight = this.pos.y-20;
		this.minHeight = this.pos.y +5;
		this.lifeTime = new ig.Timer();
	},
	handleMovementTrace: function( res ) {
		this.parent( res );
		if( res.collision.x || res.collision.y ){
			this.kill();
		}
	},
	check: function( other ) {
		other.receiveDamage(this.damageGiven, this );
		this.kill();
	},
	kill:function(){
		ig.game.spawnEntity(EntitySmallblueboom,this.pos.x,this.pos.y-20);
		this.parent();
	},
	update:function(){
		if(this.lifeTime.delta() > 1.5){
			this.kill();
		}
		if(this.flip){
			this.vel.x = this.maxVel.x;
		}else{
			this.vel.x = - this.maxVel.x;
		}
		if(this.pos.y > this.maxHeight && this.movingUp){
			this.pos.y = this.pos.y -3;
		}else{
			this.pos.y = this.pos.y +3;
			this.movingUp = false;
		}
		if(this.pos.y > this.minHeight && !this.movingUp){
			this.movingUp = true;
		}
		this.parent();
	}
});

1 decade ago by anasbud

Thanks a lot ! Works perfectly !
Page 1 of 1
« first « previous next › last »