dami54 Posted April 28, 2017 Share Posted April 28, 2017 Hey Guys! The problem is that I can not get the boxes to collide with the platforms. Any solution? Image: Game My code: var Background; var Player; var PlayerFrame = 30; var Platforms; var Platform = []; var PlatformsData = "0:740:PlatformKey:true|448:740:PlatformKey:true|896:740:PlatformKey:true"; var Boxs; var Box = []; var BoxsData = "200:0:BoxKey:true|500:0:BoxKey:true|800:0:BoxKey:true"; Level1 = { preload : function(){ PhaserGame.load.image("BackgroundKey", "./images/background.jpg"); PhaserGame.load.spritesheet("PlayerKey", "./images/characters/Player.png", 120, 130); PhaserGame.load.image("PlatformKey", "./images/Platform.png"); PhaserGame.load.image("BoxKey", "./images/Box.png"); }, create : function(){ PhaserGame.physics.startSystem(Phaser.Physics.ARCADE); Background = PhaserGame.add.tileSprite(0, 0, PhaserGame.world.width, PhaserGame.world.height, "BackgroundKey"); // ########## PLATFORMS ########## \\ Platforms = PhaserGame.add.group(); Platforms.enableBody = true; var Vueltas = PlatformsData.split("|"); for(var i = 0; i < Vueltas.length; i++){ var GetInfo = Vueltas[i].split(":"); Platform[i] = Platforms.create(parseInt(GetInfo[0]), parseInt(GetInfo[1]), GetInfo[2]); Platform[i].body.collideWorldBounds = true; if(GetInfo[3] == "true"){ Platform[i].body.immovable = true; } } // ########## BOXES ########## \\ Boxs = PhaserGame.add.group(); Boxs.enableBody = true; var Vueltas = BoxsData.split("|"); for(var i = 0; i < Vueltas.length; i++){ var GetInfo = Vueltas[i].split(":"); Box[i] = Boxs.create(parseInt(GetInfo[0]), parseInt(GetInfo[1]), GetInfo[2]); Box[i].body.collideWorldBounds = true; if(GetInfo[3] == "true"){ Box[i].body.immovable = true; } Box[i].body.gravity.y = 1000; } // #### PLAYER #### \\ Player = PhaserGame.add.sprite(50, 50, "PlayerKey"); PhaserGame.physics.arcade.enable(Player); Player.body.collideWorldBounds = true; Player.scale.setTo(0.5, 0.5); Player.body.gravity.y = 1000; Player.animations.add("Move-Left", [50, 51, 52, 53, 54, 55, 56, 57, 58, 59], 80, true); Player.animations.add("Move-Right", [70, 71, 72, 73, 74, 75, 76, 77, 78, 79], 80, true); Player.frame = PlayerFrame; }, update : function(){ PhaserGame.physics.arcade.collide(Player, Platforms); PhaserGame.physics.arcade.collide(Player, Boxs); PhaserGame.physics.arcade.collide(Platforms, Boxs); PlayerControls(); } } function PlayerControls(){ if(PhaserGame.input.keyboard.addKey(Phaser.Keyboard.UP).isDown && Player.body.touching.down){ Player.body.velocity.y = -600; } if(PhaserGame.input.keyboard.addKey(Phaser.Keyboard.LEFT).isDown){ Player.animations.play("Move-Left"); Player.animations.currentAnim.speed = 20; Player.body.velocity.x = -200; PlayerFrame = 10; }else if(PhaserGame.input.keyboard.addKey(Phaser.Keyboard.RIGHT).isDown){ Player.animations.play("Move-Right"); Player.animations.currentAnim.speed = 20; Player.body.velocity.x = 200; PlayerFrame = 30; }else{ Player.body.velocity.x = 0; Player.frame = PlayerFrame; } } Link to comment Share on other sites More sharing options...
samme Posted April 28, 2017 Share Posted April 28, 2017 You mustn't make the boxes immovable. Two immovables (box/platform) can never separate. Link to comment Share on other sites More sharing options...
Recommended Posts