dbckd999 Posted February 10, 2020 Share Posted February 10, 2020 bandicam 2020-02-10 23-22-28-566.mp4 What I want is to damage the building. It works well when on the ground but not when in the air. There is no response from the body.touch when the character is stuck in the building while jumping. I created debug-only text for reference. it's my codes //game config var config = { type: Phaser.CANVAS, backgroundColor: '#FFCCCC', parent: 'phaser-game', width: 640, height: 800, physics: { default: 'arcade', arcade: { gravity: { y: 1800 }, overlapBias: 100, debug: true } }, scene: { preload: preload, create: create, update: update //, resize: this.resize } }; function create() { this.cameras.main.setBounds(0, 0, 640, 1440); this.physics.world.setBounds(0, 0, 640, 1440); this.add.tileSprite(0, 0, 640, 1440, 'background').setOrigin(0); platforms = this.physics.add.staticImage(320, 1440, 'ground'); //player sprite sheet player = this.physics.add.sprite(320, 1300, 'anim_player'); player.setBounce(0); player.setCollideWorldBounds(true); player.isWait = false; text = this.add.text(0, 1200, 'score: 0', { fontSize: '32px', fill: '#000' }); buildings = this.physics.add.group(); buildings = this.physics.add.sprite(320, 0, 'building1'); buildings.setBounce(0.0); buildings.setCollideWorldBounds(false); buildings.setActive(true); buildings.hp = 100; this.physics.add.collider(player, platforms); this.physics.add.collider(buildings, platforms); this.physics.add.collider(buildings, player); //////////////////////////////////// //////////////////////////////////// //////////////////////////////////// //keyInput //////////////////////////////////// cursors = this.input.keyboard.createCursorKeys(); key_attack = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); key_jump = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP); key_headOff = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN); //////////////////////////////////// //////////////////////////////////// //Input Action //////////////////////////////////// //attack key_attack.on('down', function() { if (player.body.touching.down) { player.isWait = true; player.play('anim_attack', true); } else { player.isWait = true; player.play('anim_attack_jump', true); } if(player.body.touching.up || buildings.body.touching.down) { if(buildings.hp < 0) { buildings.destroy(); console.log('destroy: ' + buildings); } else { buildings.hp -= 10; } } }); //jump // key_jump.on('down', function() { // if (player.body.touching.down) { // player.isWait = true; // player.setVelocityY(-2000); // player.play('anim_jump'); // } // }); //////////////////////////////////// //////////////////////////////////// //Camera //////////////////////////////////// this.cameras.main.startFollow(player); //physics this.physics.add.collider(player, platforms); container = this.add.container(player); this.physics.world.enable(container); container.body.setVelocity(0, 0).setBounce(1, 1).setCollideWorldBounds(true); //////////////////////////////////// } Link to comment Share on other sites More sharing options...
Recommended Posts