henrikkee Posted September 23, 2015 Share Posted September 23, 2015 Hello, I'm new to phaser and i'm having some problems in this part code:create: function(){map = game.add.tilemap('mapa2');map.addTilesetImage('tilechao', 'tilesCenario');map.setCollisionBetween(1,10000);colide = map.createLayer('colide');colide.resizeWorld();naocolide= map.createLayer('naocolide');spike = map.createLayer('spikes');spike.resizeWorld();}update: function () { game.physics.arcade.collide(player, colide);game.physics.arcade.collide(player, spike);}i'm trying to make the player collide with the layer 'colide' and the layer 'spike', but when i start the player just collide with the layer 'colide'. Can anyone help me with this? Link to comment Share on other sites More sharing options...
DonFrag Posted September 24, 2015 Share Posted September 24, 2015 could you post the full code? Link to comment Share on other sites More sharing options...
henrikkee Posted September 24, 2015 Author Share Posted September 24, 2015 could you post the full code? game.stage.backgroundColor = '#ABFFFF'; campo = game.add.image(0,0, 'fundo'); botaopausar = game.add.button(690, 10, 'pausar', this.actionOnClickpausar, this, 2, 1, 0); botaopausar.fixedToCamera = true; map = game.add.tilemap('mapa'); player = game.add.sprite(100,560 , 'boneco'); game.physics.arcade.enable(player) player.body.collideWorldBounds =true; player.animations.add('frente' , [8,9,10,11],10, true); player.animations.add('tras' , [4,5,6,7], 10, true); player.animations.add('paradoE' , [4]); player.animations.add('paradoD' , [8]); game.camera.follow(player); map.addTilesetImage('chao', 'tilesCenario'); map.setCollisionBetween(1,6); map.setCollisionBetween(9,11); layer = map.createLayer('cenario'); layer.resizeWorld(); bandeira = game.add.sprite(3800,308 , 'bandeira'); bandeira.animations.add('vento' , [0,1,2,3],4); bandeira.enableBody = true; game.physics.arcade.enable(bandeira) agua = game.add.group(); agua.enableBody = true; map.createFromObjects('agua', 13, 'agua', 0, true, false, agua); agua.callAll('animations.add', 'animations', 'onda', [0, 1, 2, 3, 4], 10, true); agua.callAll('animations.play', 'animations', 'onda'); inimigo = game.add.sprite(1300,560 , 'inimigo'); game.physics.arcade.enable(inimigo) inimigo.body.collideWorldBounds =true; inimigo.enableBody = true; inimigo.animations.add('andar' , [0,1,2],4,true); inimigo1 = game.add.sprite(1500,560 , 'inimigo'); game.physics.arcade.enable(inimigo1) inimigo1.body.collideWorldBounds =true; inimigo1.enableBody = true; inimigo1.animations.add('andar' , [0,1,2],4,true); inimigo2 = game.add.sprite(1800,560 , 'inimigo'); game.physics.arcade.enable(inimigo2) inimigo2.body.collideWorldBounds =true; inimigo2.enableBody = true; inimigo2.animations.add('andar' , [0,1,2],4,true); inimigo.body.velocity.x = -80; inimigo1.body.velocity.x = 80; inimigo2.body.velocity.x = -80; // Cria Balão balao = game.add.sprite(-1200,160 , 'balao'); game.physics.arcade.enable(balao) balao.body.velocity.x = 250; balao.body.velocity.y = -50; balao.alpha = 0.8; this.criaMoedas(); moedaponto = game.add.sprite(10,10 , 'coin'); moedaponto.scale.setTo(0.8,0.8); textoMoedas = game.add.text(39, 12, pontos , { font: "16px Arial"}); textoMoedas.fixedToCamera = true; moedaponto.fixedToCamera = true; coracoes = game.add.sprite(10,35 , 'coracao'); coracoes.scale.setTo(0.6,0.6); quantvidas = game.add.text(39, 40, vidas , { font: "16px Arial"}); coracoes.fixedToCamera = true; quantvidas.fixedToCamera = true; }, update: function () { player.body.bounce.y = 0.2; player.body.velocity.x = 0; bandeira.animations.play('vento'); game.physics.arcade.collide(player, layer); game.physics.arcade.collide(player, inimigo, this.morreuplayer, null ,this); game.physics.arcade.collide(player, inimigo1,this.morreuplayer, null ,this); game.physics.arcade.collide(player, inimigo2,this.morreuplayer, null ,this); game.physics.arcade.collide(inimigo, layer, this.inimigoColidiuTile, null,this); game.physics.arcade.collide(inimigo1, layer, this.inimigoColidiuTile1, null , this); game.physics.arcade.collide(inimigo2, layer,this.inimigoColidiuTile2, null, this); game.physics.arcade.collide(coins, layer); game.physics.arcade.overlap(player, coins, this.encostouEmMoeda, null, this); game.physics.arcade.overlap(player, agua, this.morreuplayer, null, this); game.physics.arcade.overlap(player, bandeira, this.passou, null, this); if(countpause == 0){ if(balao.y < 70){balao.body.velocity.y = 40;}if(balao.y > 180){balao.body.velocity.y = -40;} if(balao.x > 4000) {balao.reset(0,160);balao.body.velocity.y = -50;balao.body.velocity.x = 250;} player.body.gravity.y = 300; inimigo.body.gravity.y = 300;inimigo2.body.gravity.y = 300;inimigo1.body.gravity.y = 300; if(direcaoinimigo == "esquerda"){inimigo.body.velocity.x = -80}else{inimigo.body.velocity.x =80} if(direcaoinimigo1 == "esquerda"){inimigo1.body.velocity.x = -80}else{inimigo1.body.velocity.x =80} if(direcaoinimigo2 == "esquerda"){inimigo2.body.velocity.x = -80}else{inimigo2.body.velocity.x =80} if (cursors.left.isDown) {player.body.velocity.x = -150; if (facing != 'left') {player.animations.play('tras'); facing = 'left'; }} else if (cursors.right.isDown) {player.body.velocity.x = 150; if (facing != 'right'){ player.animations.play('frente'); facing = 'right'; } } else {if (facing != 'idle') {player.animations.play('paradoD'); facing = 'idle';}} if (jumpButton.isDown && player.body.onFloor()){ player.body.velocity.y = -250; jumpTimer = game.time.now + 700; console.log('funciona' + countpause + vidas);} if (pauseButton.isDown && player.body.onFloor) { if(countpause == 0) {menugame = game.add.sprite(320,100 , 'menupause'); menugame.fixedToCamera = true; console.log("xim"); botaopausar.kill botaopausar.reset(0,600) botaocontinuar = game.add.button(370,150, 'continuar', this.actionOnClickcontinuar, this, 2, 1, 0) botaosairmenu = game.add.button(370,200, 'sairmenu', this.actionOnClicksairmenu, this, 2, 1, 0) botaocontinuar.fixedToCamera = true; botaosairmenu.fixedToCamera = true; countpause = 1 coins.callAll('animations.stop', 'animations', 'giraMoeda'); agua.callAll('animations.stop', 'animations', 'onda'); } } } else{ player.body.velocity.y = 0; player.body.gravity.y = 0; inimigo.body.gravity.y = 0; inimigo1.body.gravity.y = 0; inimigo2.body.gravity.y = 0; inimigo.body.velocity.y = 0; inimigo1.body.velocity.y = 0; inimigo2.body.velocity.y = 0; inimigo.body.velocity.x = 0;inimigo1.body.velocity.x = 0; inimigo2.body.velocity.x = 0;} }, Here is it but i dont think that will change something Link to comment Share on other sites More sharing options...
DonFrag Posted September 24, 2015 Share Posted September 24, 2015 after you create layersgame.physics.arcade.enable(this.layer1);game.physics.arcade.enable(this.layer2);//set collision setTileIndexCallback after thisin updateupdate: function() { game.physics.arcade.collide(this.player, this.layer1); game.physics.arcade.collide(this.player, this.layer2); }how ever i think your code it's very expensive somehow Link to comment Share on other sites More sharing options...
Recommended Posts