Skip to content

Regarding the issue that the scene cannot be paused after the callback, please help me. Thank you #6534

Answered by finefin
dasdssdasdas asked this question in Q&A
Discussion options

You must be logged in to vote

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

layer.setTileIndexCallback(6, (player, tile)=>{
  this.scene.pause()
}, this)  // define the scope of the callback function

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dasdssdasdas
Comment options

Answer selected by dasdssdasdas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants