axman Posted October 3, 2014 Share Posted October 3, 2014 hello ! I have a problem to make collision between 2 sprites works. I use P2 physics system and my main sprite is a player and the other sprite is also player but they are loaded after (it's a multi player game). Init of the map :this.game.stage.backgroundColor = '#2f8136'; this.map = this.game.add.tilemap('map'); // Preloaded tilemap this.map.addTilesetImage('grass'); // Preloaded tileset this.map.addTilesetImage('treetop'); // Preloaded tileset this.map.addTilesetImage('trunk'); // Preloaded tileset this.map.addTilesetImage('watergrass'); // Preloaded tileset this.layerBackground = this.map.createLayer('background'); // This is the default name of the first layer in Tiled this.layerBackground.resizeWorld(); // Sets the world size to match the size of this layer. this.layerForeground = this.map.createLayer('foreground'); // This is the default name of the first layer in Tiled this.layerForeground.resizeWorld(); // Sets the world size to match the size of this layer. this.layerTop = this.map.createLayer('top'); // This is the default name of the first layer in Tiled this.layerTop.resizeWorld(); // Sets the world size to match the size of this layer. this.map.setCollisionBetween(1, 300, true, 'foreground');Init of the game :this.game.world.setBounds(0, 0, 2000, 2000); //Permet de definir la taille et les bords de la carte this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.setBoundsToWorld(true, true, true, true, false);this.game.physics.p2.updateBoundsCollisionGroup();Init of collision group :playerCG = this.game.physics.p2.createCollisionGroup();Init of player (create) :this.sprite = this.game.add.sprite(200, 200, 'player'); //Definition de l'echelle : this.sprite.scale.x = 0.9; this.sprite.scale.y = 0.9; //Definition des animations : this.sprite.animations.add('left', [9, 10, 11, 12, 13, 14, 15, 16, 17], 20, true); this.sprite.animations.add('right', [27, 28, 29, 30, 31, 32, 33, 34, 35], 20, true); this.sprite.animations.add('up', [0, 1, 2, 3, 4, 5, 6, 7, 8], 20, true); this.sprite.animations.add('down', [18, 19, 20, 21, 22, 23, 24, 25, 26], 20, true); //On active le physic sur le sprite (permet d'utiliser fixedRotation....) this.game.physics.p2.enable(this.sprite); this.sprite.body.setRectangle(22, 7); //permet de redefinir la taille du body du perso(util pour les collisions par ex) this.sprite.anchor.setTo(0.5, 0.95); //permet de redifinir la position du sprite this.sprite.body.fixedRotation = true; //permet de fixer la rotation du perso (cela arrive en bordure de terrain que le perso tourne sur lui meme !) this.sprite.body.setZeroDamping(); this.sprite.id = index; //Permet de prendre en charge le clavier : this.cursors = this.game.input.keyboard.createCursorKeys(); //Gestion des collisions : this.sprite.body.setCollisionGroup(playerCG); this.sprite.body.collides([levelCG, playerCG]); this.game.physics.p2.updateBoundsCollisionGroup();Player collision work with tiles and word bound but do not work with other player and I don't understand why...Someone can help me please ? Link to comment Share on other sites More sharing options...
axman Posted October 4, 2014 Author Share Posted October 4, 2014 For information, I use the last Phaser version : 2.1.1feel free to ask me questions if necessary. Link to comment Share on other sites More sharing options...
Recommended Posts