Skip to content

Instantly share code, notes, and snippets.

@JetLua
Last active May 6, 2018 17:35
Show Gist options
  • Save JetLua/531378aa69d9ecbaa6458a7584c77b88 to your computer and use it in GitHub Desktop.
Save JetLua/531378aa69d9ecbaa6458a7584c77b88 to your computer and use it in GitHub Desktop.
phaser 旋转画布后的点击事件映射
// game.rotation: 画布的旋转角度,可简化为landscape | portrait
Object.defineProperties(phaser.Input.Pointer.prototype, {
x: {
get() {
return config.landscape ? this.position.y / this.manager.bounds.width * this.manager.bounds.height : this.position.x
},
set(v) {
this.position.x = v
}
},
y: {
get() {
return config.landscape ? (devicePixelRatio - this.position.x / this.manager.bounds.height) * this.manager.bounds.width : this.position.y
},
set(v) {
this.position.y = v
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment