This is my player1.js file
ig.module(
'game.entities.player1'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer1 = ig.Entity.extend({
animSheet: new ig.AnimationSheet('media/ship1.png',100,100),
//angle: 0.76,
speed: 350,
maxVel: {x:500,y:500},
init: function( x, y, settings ) {
// Add animations for the animation sheet
//ig.setNocache(true);
this.addAnim( 'idle',1,[0] );
//this.currentAnim.angle = 2.96;
//this.gravityFactor = 3;
// this.friction.y = 3;
//this.friction.x = 3;
this.parent( x, y, settings );
},
update: function() {
// This method is called for every frame on each entity.
// React to input, or compute the entity's AI here.
//var test = this.angleTo(EntityPlayer2);
var angle = null;
var players = ig.game.getEntitiesByType(EntityPlayer2);
//
if (players && players.length > 0) {
angle = this.angleTo(players[0]);
}
if (angle != null) {
this.currentAnim.angle = angle;
}
if(ig.input.state('right'))
this.vel.x = this.speed;
if(ig.input.released('right'))
this.vel.x = 0;
if(ig.input.state('left'))
this.vel.x = -this.speed;
if(ig.input.released('left'))
this.vel.x = 0;
if(ig.input.state('up'))
this.vel.y = -this.speed;
if(ig.input.released('up'))
this.vel.y = 0;
if(ig.input.state('down'))
this.vel.y = this.speed;
if(ig.input.released('down'))
this.vel.y = 0;
//console.log("V="+this.vel.x+" "+"F="+this.friction.x);
if(ig.input.state('right') && ig.input.state('left'))
this.vel.x = 0;
if(ig.input.pressed('player1_fire')){
//var bullet = ig.game.spawnEntity(EntityLaser, this.pos.x,this.pos.y);
var bullet = ig.game.spawnEntity( EntityLaser, this.pos.x, this.pos.y, {} );
//console.log("Bullet pos "+bullet.pos.x+" "+bullet.pos.y);
console.log(bullet.pos.x);
}
//this.currentAnim.angle = this.angle += 0.01;
this.parent();
}
});
EntityLaser = ig.Entity.extend({
maxVel: {x: 600, y:600},
vel: {x:500, y:500},
name: 'laser',
animSheet: new ig.AnimationSheet('media/laser.png',10,30),
init: function( x, y, settings ) {
// Call the parent constructor
this.parent( x, y, settings );
this.addAnim( 'idle',1,[0] );
},
update: function() {
this.parent();
if(this.pos.x>300 && this.pos.y>300){
this.kill();
//console.log("killed");
}
}
});
});
As you can see, under the
var bullet = ig.game.spawnEntity( EntityLaser, this.pos.x, this.pos.y, {} );
This line of code works. But once browser is refreshed, the bullet entity.pos.x or y shows as 0. If anyone could help me check it, greatly appreciate it.