Regarding the issue that the scene cannot be paused after the callback, please help me. Thank you #6534
-
Here is my code.When the execution scenario "pauses", regardless of whether parameters are added, an error will be returned: "Cannot sleep non running Scene Example".I also used 'sleep()', which is the same. I don't know why! But I use 'this. scene. start ('Example') ', which can perfectly jump through scenes.Later, I tried to call a timer (triggering the scene 'pause'), which could be executed correctly.I find it difficult to understand why, it feels like it's a problem with the direction of 'this'!layer.setTileIndexCallback(6, (player, tile)=>{ }) Please help me! Thank you very much. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is not really specific to Phaser but a common javascript mistake: you should learn about scope in js https://www.w3schools.com/js/js_scope.asp -> You need to define the scope of the 'inner' function - the callback in this case . Take a look at the docs https://newdocs.phaser.io/docs/3.55.2/focus/Phaser.Tilemaps.Tilemap-setTileIndexCallback All you have to do is to tell the function what the callback should refer to - in this case: this
|
Beta Was this translation helpful? Give feedback.
This is not really specific to Phaser but a common javascript mistake: you should learn about scope in js https://www.w3schools.com/js/js_scope.asp -> You need to define the scope of the 'inner' function - the callback in this case .
Take a look at the docs https://newdocs.phaser.io/docs/3.55.2/focus/Phaser.Tilemaps.Tilemap-setTileIndexCallback
It tells you how to use it:
setTileIndexCallback(indexes, callback, callbackContext, [layer])
All you have to do is to tell the function what the callback should refer to - in this case: this