The tiles are 48x48 in size and I have a section of collision shapes aligned on the Y axis. (each tile has a unique collision shape of equal size)
If my entity is on the LEFT side of the tiles and moves to the RIGHT, collision happens as expected and the player can't pass through the collision shape from LEFT to RIGHT. If the entity moves RIGHT and DOWN simultaneously the character moves down (as expected) until reaching the next tile (again on the y axis). The player gets stuck and no longer moves DOWN. I'm not sure how to simulate collision in a manner similar to the old system. (The old system worked as expected)
Again my collision shapes are equal in size and aligned pixel perfect on the Y axis. I am expecting the character to basically scale vertically as the RIGHT/DOWN or RIGHT/UP combos are pressed .
If this is not a bug, can you please offer suggestions?
game.PlayerEntity = me.Entity.extend({
init: function(x, y, settings) {
// call the constructor
this._super(me.Entity, "init", [x, y, settings]);
// set the default horizontal & vertical speed (accel vector)
this.body.setVelocity(4, 4);
// set the gravity
this.body.gravity = 0;
// set the display to follow our position on both axis
me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
// ensure the player is updated even when outside of the viewport
this.alwaysUpdate = true;
// define animations
this.renderable.addAnimation("push_left", [5,6], 120);
this.renderable.addAnimation("push_right", [9,10], 120);
this.renderable.addAnimation("push_down", [1,2], 120);
this.renderable.addAnimation("push_up", [13,14], 120);
this.renderable.addAnimation("run_left", [5,6], 120);
this.renderable.addAnimation("run_right", [9,10], 120);
this.renderable.addAnimation("run_down", [1,2], 120);
this.renderable.addAnimation("run_up", [13,14], 120);
this.renderable.addAnimation("idle_left", [4]);
this.renderable.addAnimation("idle_right", [8]);
this.renderable.addAnimation("idle_down", [0]);
this.renderable.addAnimation("idle_up", [12]);
// set starting animation
this.renderable.setCurrentAnimation("idle_down");
// possible key commands
this.directions = {
"down": [0, 1],
"left": [-1, 0],
"right": [1, 0],
"up": [0, -1]
};
// current key commands
this.keys = [];
},
update: function(dt) {
move = { x:0, y:0 };
this.pushing = false;
// create array of current commands
for (var d in this.directions) {
var index = this.keys.indexOf(d);
if (me.input.isKeyPressed(d)) {
move.x+= this.directions[d][0];
move.y+= this.directions[d][1];
if (index < 0) {
this.keys.push(d);
}
} else if (index >= 0) {
this.keys.splice(index, 1);
}
}
if (this.keys[0]) {
animation = "run_" + this.keys[0];
}
// assign an idle animation
if (move.x === 0 && move.y === 0) {
animation = "idle_" + currentAnimation.split("_")[1];
if (animation !== currentAnimation) {
this.renderable.setCurrentAnimation(animation);
}
}
// assign a running animation
if (this.keys.length === 3) {
for (var d in this.directions) {
if (this.directions[d][0] === move.x &&
this.directions[d][1] === move.y) {
animation = "run_" + d;
}
}
}
// assign the velocity
this.body.vel.x = move.x * this.body.accel.x * me.timer.tick;
this.body.vel.y = move.y * this.body.accel.y * me.timer.tick;
// apply physics to the body (this moves the entity)
this.body.update();
// handle collisions against other shapes
if (me.collision.check(this)) {
this.pushing = true;
}
// assign a push animation of moving colliding against pushable objects tiles
if (this.pushing && this.keys.length < 2) {
animation = animation.replace("run", "push");
}
// reset the current animation
if (animation !== currentAnimation) {
this.renderable.setCurrentAnimation(animation);
this.renderable.setAnimationFrame(0);
}
// update animation if necessary
return this._super(me.Entity, "update", [dt]) ||
move.x !== 0 ||
move.y !== 0 ||
animation !== currentAnimation;
},
/**
* The collision handler, called when colliding with other objects
*/
onCollision: function (response, other) {
if (this.alive && response.b.body.collisionType == me.collision.types.ENEMY_OBJECT) {
this.renderable.flicker(750);
return true;
}
return true;
}
});