Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision Issues: Only Background detected as being collide. #189

Open
acarlstein opened this issue Nov 15, 2016 · 0 comments
Open

Collision Issues: Only Background detected as being collide. #189

acarlstein opened this issue Nov 15, 2016 · 0 comments

Comments

@acarlstein
Copy link

acarlstein commented Nov 15, 2016

If I introduce in any way the background, the hit event of the player always gets activated since Quintus believes that the player is colliding with the background always.

http://codepen.io/acarlstein/pen/yVaBzv

  1. How can I prevent any object to "collide" with the background?
  2. How can you handle multiple collision.
    For example, two objects have already collide. We make the "glued" together and a third object collides?

Code:

`
/**

var backgroundUrl = "http://www.elblender.com/wordpress/wp-content/uploads/2016/11/bg5.jpg";
var player1WalkUrl = "http://www.elblender.com/wordpress/wp-content/uploads/2016/11/p1_walk.png";
var player2WalkUrl = "http://www.elblender.com/wordpress/wp-content/uploads/2016/11/p2_walk.png";
var resourcesUrlList = [backgroundUrl, player1WalkUrl, player2WalkUrl];

// Include Sprite module and set game's canvas size
var Q = Quintus().include("Sprites, Anim, UI, 2D, Input, Scenes, Touch")
.setup({width: 800, height: 480})
.controls();

Q.Sprite.extend("Background", {
init: function(background){
this._super(background, {
asset: backgroundUrl,
x: Q.el.width / 2,
y: Q.el.height / 2,
collisionLayer: 0,
type: Q.SPRITE_NONE
});
}
});

Q.Sprite.extend("Player1", {
init: function(player){
this._super(player, {
sprite: "player1",
sheet: "player1",
speed: 50,
type: Q.SPRITE_FRIENDLY
});
this.p.x = this.p.w;
this.p.y = (Q.el.height / 2) - this.p.h;
this.add("animation");
this.play("default");
this.on("hit", "collision");
},
"step" : function(dt){
this.p.x += this.p.speed * dt;
this.stage.collide(this);
},
"collision" : function(col){
console.log(col.obj);
if (col.obj.isA("Player2")){
col.obj.destroy();
this.destroy();
Q.clearStages();
Q.stageScene("level1");
}
}
});

Q.Sprite.extend("Player2", {
init: function(player){
this._super(player, {
sprite: "player2",
sheet: "player2",
speed: 50,
flip: "x",
type: Q.SPRITE_ENEMY
});
this.p.x = Q.el.width - this.p.w;
this.p.y = (Q.el.height / 2) - this.p.h;
this.add("animation");
this.play("default");
},
"step" : function(dt){
this.p.x -= this.p.speed * dt;
}
});

Q.scene("level1", function(stage){
// Trying to find the right one
//stage.insert(new Q.Background());
//stage.insert(new Q.Repeater({asset: backgroundUrl}));
//stage.collisionLayer(new Q.Background());
//stage.insert(new Q.UI.Container({x: Q.width/2, y: Q.height/2, fill: "rgba(255,0,0,1)"}));
//stage.insert(new Q.Sprite({asset: backgroundUrl}));
stage.insert(new Q.Player1());
stage.insert(new Q.Player2());
});

var playerSheet = {
tilew: 66, tileh: 92,
sx: 0, sy: 0,
w: 256, h: 512
};

var playerAnimationFrame = {
default: {
frames: [0, 1, 2, 4],
rate: 1/4
}
};

Q.load(resourcesUrlList, function(){
Q.sheet("player1", player1WalkUrl, playerSheet);
Q.sheet("player2", player2WalkUrl, playerSheet);
Q.animations("player1", playerAnimationFrame);
Q.animations("player2", playerAnimationFrame);
Q.clearStages();
Q.stageScene("level1");
});

`

@acarlstein acarlstein changed the title Player always collide with background Collision Issues: Only Background detected as being collide. Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant