The updated code doesn&
039;t seem to be working properly just yet. I think it might be a problem that the #update()
method of the
EntityWeapon
is checking for whether there&
039;s an #owner
or not. So if we're spawning, there won't be one until collection, right? Bit confused on that one.
I&
039;m guessing there should there be a #check()
method in
EntityWeapon
that executes
pickup()
at some point when the player collides with it?
Also when would
drop()
execute? When a different weapon is picked up I guess?
I will have a bit more of a play around, I've been trying to get it working while on the train to work and it's not the best environment to code in. ;-)
So far this is the entire
EntityWeapon
class:
ig.module('game.entities.weapon').requires('impact.entity').defines(function() {
EntityWeapon = ig.Entity.extend({
size: { x: 7, y: 6 },
offset: { x: 10, y: 80 },
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.ACTIVE,
bounciness: 0.1,
//gravityFactor: 1,
owner: null,
weapon: null,
//zIndex: 2,
animSheet: new ig.AnimationSheet('media/sprites/laser-gun.png', 7, 6),
init: function(x, y, settings) {
this.parent(x, y, settings);
this.addAnim('idle', 1, [0], true);
console.log('spawned.x=' + this.pos.x);
console.log('spawned.y=' + this.pos.y);
},
pickup: function(other) {
if (other instanceof EntityWeapon) {
this.weapon = other;
other.owner = this;
other.zIndex = this.zIndex + 1;
}
},
drop: function(weapon) {
this.weapon = null;
weapon.owner = null;
},
update: function() {
if (this.owner) {
if (this.owner.flip) {
this.pos.x = this.owner.pos.x + 4;
} else {
this.pos.x = this.owner.pos.x + 23;
}
this.pos.y = this.owner.pos.y + 90;
this.currentAnim.flip.x = this.owner.currentAnim.flip.x;
} else {
this.parent();
}
}
});
});
EDIT: The weapon itself does spawn, however it's floating above the player and also moves on the Y-axis when the player is near it. Very strange.