tobymcfly Posted May 31, 2018 Share Posted May 31, 2018 Hey. So im trying to make a game where you can pickup this box with a chicken. This is the code i use to create the box, but it says error: "" What's going on? I've a version where i dont have any states for the game, and it's working fine. But when i try to implement my code inside the game with states code, it comes up with this error. The rest of the code is working fine for (var i = 0; i < 1; i++) { //box var b = boxGroup.create(0, 0, 'box'); b.name = 'box' + i; b.exists = false; b.visible = false; b.checkWorldBounds = true; b.events.onOutOfBounds.add(function(){resetBox, this}; var idle = b.animations.add('idle'); b.animations.play('idle', 10, true); b.body.drag = new Phaser.Point(100, 100); b.body.drag.y = -400; b.anchor.setTo(0.5, 0.5); b.scale.setTo(0.6, 0.6); b.body.setSize(231.6, 226.8, 50); b.body.collideWorldBounds = true; } Link to comment Share on other sites More sharing options...
rich Posted May 31, 2018 Share Posted May 31, 2018 Signal callbacks need to be a reference to a function, which is only run when the event fires. You should likely change your code to be: `onOutOfBounds.add(resetBox, this)` (assuming resetBox is in the local scope) tobymcfly 1 Link to comment Share on other sites More sharing options...
hektor74 Posted June 3, 2018 Share Posted June 3, 2018 Or I think you can use fat arrow function like: b.events.onOutOfBounds.add(():void=>{ //resetBox function content }, this}; Link to comment Share on other sites More sharing options...
Recommended Posts