1 decade ago by hschillig
I have a trigger (exit into new level and then they can exit back out). So it's similar to Pokemon where you can enter a building and then leave it. However, when it goes back to the previous map, I want the entity to spawn right by the trigger (in this case, below it).
How would I go about doing that with an entity?
How would I go about doing that with an entity?
EntityGirl = ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/game2/player.png', 16, 16 ),
size: {x: 16, y: 16},
flip: false,
friction: {x: 800, y: 800},
accelGround: 300,
accelAir: 150,
health: 100,
lastAction: 0,
type: ig.Entity.TYPE.A,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
this.addAnim( 'run', 0.05, [0,1,2] );
this.addAnim( 'runUp', 0.05, [6,7,8] );
this.addAnim( 'runDown', 0.05, [3,4,5] );
this.addAnim( 'upIdle', 1, [6]);
this.addAnim( 'downIdle', 1, [3]);
},
update: function() {
if( ig.input.state('left') ) {
this.accel = {x: -this.accelGround, y: 0};
this.flip = true;
this.lastAction = 0;
}
else if( ig.input.state('right') ) {
this.accel = {x: this.accelGround, y: 0};
this.flip = false;
this.lastAction = 0;
}
else if( ig.input.state('up') ) {
this.accel = {x: 0, y: -this.accelAir};
this.flip = false;
this.lastAction = 'up';
}
else if( ig.input.state('down') ) {
this.accel = {x: 0, y: this.accelAir};
this.flip = false;
this.lastAction = 'down';
}
else {
this.accel = {x: 0, y: 0};
}
// set the current animation, based on the player's speed
if( this.accel.x != 0 ) {
this.currentAnim = this.anims.run;
}
else if( this.accel.y > 0 ) {
this.currentAnim = this.anims.runDown;
}
else if( this.accel.y < 0 ) {
this.currentAnim = this.anims.runUp;
}
else {
if( this.lastAction == 'up' )
{
this.currentAnim = this.anims.upIdle;
}
else if( this.lastAction == 'down' )
{
this.currentAnim = this.anims.downIdle;
}
else
{
this.currentAnim = this.anims.idle;
}
}
this.currentAnim.flip.x = this.flip;
// move!
this.parent();
}
});
