didjs Posted April 25, 2015 Share Posted April 25, 2015 Hi there! I'm trying to use p2.js plugin with panda, and I can't figured out why collisions are not working. I've got two objects : game.module('game.squary').require( 'plugins.p2').body(function() {console.log('load squary'); game.createClass("Squary", { init: function(x, y) { this.sprite = new game.Sprite('images/squary.png', x / game.scene.world.ratio, y / game.scene.world.ratio); this.sprite.anchor.set(0.5, 0.5); this.body = new game.Body({ mass: 0.1, position: [ x / game.scene.world.ratio, y / game.scene.world.ratio ] }); this.body.addShape(new game.Rectangle(this.sprite.width, this.sprite.height)); game.scene.addObject(this); game.scene.stage.addChild(this.sprite); game.scene.world.addBody(this.body); }, update: function() { this.sprite.position.x = this.body.position[0] * game.scene.world.ratio; this.sprite.position.y = this.body.position[1] * game.scene.world.ratio; } }); });And : game.module('game.block').require( 'plugins.p2').body(function() {console.log('load block'); game.createClass("Block", { init: function(x, y) { this.sprite = new game.Sprite('images/block.png', x, y); this.body = new game.Body({ mass: 0.1, position: [ x , y ] }); this.body.addShape(new game.Rectangle(this.sprite.width, this.sprite.height)); game.scene.addObject(this); game.scene.stage.addChild(this.sprite); game.scene.world.addBody(this.body); } }); });Then, I do this : game.module('game.scenes').require('game.squary','game.block').body(function() {game.createScene('Main', {backgroundColor: 0xffffff, init: function() { this.world = new game.World({gravity: [0, 9]}); this.world.ratio = 100; this.block = new game.Block(95, 500); this.squary = new game.Squary(100, 200); }});});But collision is not working. Nothing happens. The little square is passing through the bigger one. I took the code from http://www.pandajs.net/demos/p2.html. What am I doing wrong? I really don't understand... Thanks for your help,Did Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted April 25, 2015 Share Posted April 25, 2015 I think the problem is in this line:this.sprite.position.x = this.body.position[0] * game.scene.world.ratio;this.sprite.position.y = this.body.position[1] * game.scene.world.ratio;Why [0] & [1] ? Why not just use .x and .y ? Quote Link to comment Share on other sites More sharing options...
didjs Posted April 25, 2015 Author Share Posted April 25, 2015 With p2.js, x and y are at position 0 and 1 of the position array : this.body = new game.Body({ mass: 0.1, position: [ x / game.scene.world.ratio, y / game.scene.world.ratio ] }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.