Artuki Posted March 1, 2018 Share Posted March 1, 2018 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 More sharing options...
rich Posted March 1, 2018 Share Posted March 1, 2018 crate.setFrame(0) mattasaurus 1 Link to comment Share on other sites More sharing options...
Artuki Posted March 1, 2018 Author Share Posted March 1, 2018 Are you actually joking me? Thanks! xD Link to comment Share on other sites More sharing options...
rich Posted March 2, 2018 Share Posted March 2, 2018 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 More sharing options...
Recommended Posts