Jump to content

Changing frames in Phaser


Artuki
 Share

Recommended Posts

Hi guys,

 

I have this code in create()

lootCrates = this.physics.add.staticGroup();
lootCrates.create(600, 362, 'crate', frame = 1);

this.physics.add.overlap(player, lootCrates, brokenCrate, null, this);

I then have this function for when the player touches the crate: 

function brokenCrate(player, crate) {
            crate.frame = 0;
        }

I simply want to change the frame to the crate being broken.... However, I get this error: "Cannot read property 'source' of undefined"

 

But earlier I did the exact same thing for a speedPotion where I did speedPotion.disableBody(true, true) and that worked perfectly.

 

Why is changing frame giving me an error? Thanks!

Link to comment
Share on other sites

Just to quickly explain why the way you did it before caused an error - 'frame' is a property of Game Objects and it contains a reference to an AnimationFrame object. The renderer uses this to draw the Sprite with. So when you set it to a zero it freaked the renderer out, because it was expecting a Frame object and instead it got a number.

Also, to change a texture you can use setTexture (which takes a frame parameter as well)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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