Jump to content

Arcade collision issue


Ghonsha
 Share

Recommended Posts

Hello, I am new in this community, my name is Gonzalo.

 

I started this weekend to develop with Phaser, I dont have experience in game development but i decided to start with this framework..

 

I did the tutorial without problems, and all worked as expected, but now im writing my own code and i have some issues.

 

I loaded two spritesheet, a player and a flag and i want to set a collision handler with a callback function between them. But it doesn't work as expected, and the callback is never called.

 

I followed the basic project template, and here is the code of the Game.js which i think that is important:

 

BasicGame.Game.prototype = {

    create: function () {

       this.physics.startSystem(Phaser.Physics.ARCADE);

 

       this.flag = this.add.sprite(this.world.centerX, this.world.centerY, "flag");
       this.flag.animations.add('vuela', [4, 5, 6, 7], 10, true);
       this.physics.enable(this.flag, Phaser.Physics.ARCADE);

       this.player.sprite = this.add.sprite(0, this.world.height, 'dude');
       this.player.flag = false;

       this.physics.enable(this.player.sprite, Phaser.Physics.ARCADE);

       this.player.sprite.body.bounce.y = 0.0;
       this.player.sprite.body.gravity.y = 1;
       this.player.sprite.body.collideWorldBounds = true;

        //  Our controls.
        this.cursors = this.input.keyboard.createCursorKeys();

    },

    update: function () {

        this.physics.arcade.collide(this.player.spite, this.flag, this.takeFlag, null, this);

        // apply velocity over player's body

    },

    takeFlag: function(player, flag) {
        alert("flag");
        this.player.flag = true;
        this.flag.kill();
    },

};

 

I also attached the entire project, in case that the code that i showed it isn't enough.

 

Thanks in advance guys!!

 

PS: i recomment run the project on Chrome, because on Firefox im having problems with this issue too: https://github.com/photonstorm/phaser/issues/1932

 

PS2: Sorry for my english, it isn't my native lenguage.

 

 

 

 

first.zip

Link to comment
Share on other sites

Woo that was the problem, i spent hours on that and i couldn't see it.

 

Sory, for spend your time!

 

 

Note to self: Add spite property to entities.

 

By the way, this should throw an error. Make sure you're checking a console to see if javascript errors come up!

 

I checked the console but no error was shown.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...