dbckd999

body.touch is not work

Recommended Posts

 

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);
	
	////////////////////////////////////

}

 

 

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.