# LandonSchropp

Members

4

• Rank
Newbie

## Contact Methods

LandonSchropp

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

1. ## Can I change the point of rotation on a sprite without affecting its position?

Thanks for the reply @end3r! Your solution looks like the best way to accomplish this, but it's a bit of a bummer that I can't change the rotation point independent of the sprite's location. Still, I appreciate the help.
2. ## Can I change the point of rotation on a sprite without affecting its position?

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.
3. ## Click location relative to sprite

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!
4. ## Click location relative to sprite

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 = game.world.bounds.size().multiply(0.5, 0.5); // Scale the board so it properly fits in the canvas let scale = game.world.bounds.width / board.width * 0.9; board.scale.setTo(scale, scale); // Listen to clicks on the sprite board.inputEnabled = true; board.events.onInputDown.add(onBoardClick, 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!