ZRT Posted February 14, 2014 Share Posted February 14, 2014 Hey guys, it's me again. I already posted what I'm doing in a different thread, but this time the problem is something else. I have this, which works fine with a slightly different code (without using states and object literals), but here it gives me: Uncaught ReferenceError: resetTop is not defined I saw some examples and haven't seen the functions being defined someplace else. If I change this.ob.events.onOutOfBounds.add(resetTop); to this.ob.events.onOutOfBounds.add(this.resetTop); it cannot call the reset method. Any ideas? Thanks. EDIT: I'm using Phaser 1.1.3Game.Play.prototype = { create: function() { // create player this.player = game.add.sprite(50, 100, 'player'); this.player.body.gravity.y = 7; this.player.outOfBoundsKill = false; // create obstacles this.obTop = game.add.group(); this.ob = this.obTop.create(this.game.world.width + Math.random() * 500, 0, 'obstacle'); this.ob.events.onOutOfBounds.add(resetTop); this.ob.body.velocity.x = -500; }, update: function() { if (this.game.input.activePointer.isDown) { this.player.body.velocity.y = -200; } }, resetTop: function() { this.ob.reset(this.game.world.width + Math.random() * 500, 0, 'obstacle'); this.ob.body.velocity.x = -400; },}; Link to comment Share on other sites More sharing options...
XekeDeath Posted February 14, 2014 Share Posted February 14, 2014 Have you tried adding a callback context parameter?this.ob.events.onOutOfBounds.add(this.resetTop, this); Link to comment Share on other sites More sharing options...
ZRT Posted February 14, 2014 Author Share Posted February 14, 2014 Thank you, XekeDeath, that actually solved it! I need to read more on this subject, obviously. Link to comment Share on other sites More sharing options...
Recommended Posts