• Content count

  • Joined

  • Last visited

About LandonSchropp

  • Rank

Contact Methods

  • Twitter
  1. I would like to change the point a sprite rotates around to the center of the sprite. I realize I can do this by calling sprite.anchor.set(0.5), but that also effectively changes the position of the sprite. Is there a way to change the rotation point of the sprite without affecting its position? I found the pivot property, but it also seems to have the same problem.
  2. Thanks for the reply! I like all of the ideas, and the collision detection was really interesting! In this case, I think I'd like to keep it simple and do the math, but I'll definitely be keeping a couple of those techniques in my toolbox. I was able to get things working by taking advantage of getBounds. Here's what I did: function onBoardClick(sprite, pointer) { let { x, y, width, height } = sprite.getBounds(); let row = Math.floor((pointer.y - y) * 3 / height); let column = Math.floor((pointer.x - x) * 3 / width); } Thanks again for the help!
  3. I'm building a simple tic-tac-toe game in Phaser. I've added a sprite for the board, and I'd like to detect where inside the board the user has clicked so I can add a. Here's what I have so far: let game = new Phaser.Game(380, 720, Phaser.AUTO, '', { preload, create }); function preload() { game.load.image('board', `/images/board.png`); } function create() { // Add the board let board = game.add.sprite(0, 0, 'board'); board.anchor.setTo(0.5, 0.5); board.position =, 0.5); // Scale the board so it properly fits in the canvas let scale = / board.width * 0.9; board.scale.setTo(scale, scale); // Listen to clicks on the sprite board.inputEnabled = true;, this); } I'd really love to be able to do something like this: function onBoardClick(sprite, pointer) { // Get the coordinates of the click relative to the bounds inside the board let point = sprite.relativeClickCoordinates; let { x, y } = point.divide(sprite.width, sprite.height).multiply(3, 3); let row = Math.floor(x); let column = Math.floor(y); } Ideally, this would spit out values for row and column between 0 and 2. Obviously relativeClickCoordinates doesn't exist, but I haven't been able to find an equivalent property or function while digging through the Phaser docs. Ideally, the relative coordinates of the click would take into account: The anchor point of the sprite The scale of the sprite The position of the sprite relative to the mouse Is there a simple way to accomplish this? Is there a better way? Thanks in advance!