HimeWorks

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. Hmm, actually onmouseup is probably good enough for a single-player game. I only need the pieces to be clickable when it's time to choose a piece to move, so I don't actually need hit areas on all the time. Maybe a global game phase tracker like the "game.dragging" you mentioned 1. choosing a piece (not dragging) 2. choosing where to move the piece (dragging) Though I imagine this global variable only works because it's a one-player game. If I wanted to players to click on pieces and drag them around at the same time (like in real-life when there's no strict rules on playing with your pieces while the opponent is making their move), might need a different solution.
  2. I've been reading about collision detection and I think the concept can be applied here. My mouse cursor in this case is the collider, and can be treated as a point collider. When onmouseup event is emitted, the piece that I'm dragging will trigger its onmouseup handler. Since I know the position where the mouse was released, I can perform a "hit test" at that position on the screen to get a sprite there. If I see a tile sprite, now I have both objects and I'm able to perform the interaction between them. Possible issues are, does the hit test return all sprites at that position? If I have a tile with an existing piece on top, would it return the piece, or the tile, or both?
  3. I'm making a chess game to practice pixi. Here's how it's set up: 1. I have a Sprite_Tile for each of the 64 squares on the board 2. I have a Sprite_Piece which represents one of the chess pieces (king, rook, queen, etc) So basic use case is player clicks on a piece to "pick it up", and then they can drag it around. I used the example onmousedown, onmousemove, and onmouseup events for the pieces, and it works, I can drag and drop pieces around. To give the player a visual reference for where their piece is going to be dropped, I added an onmouseover event to the tiles, so that when they move the cursor over it, it'll change color or something. I saw there was a topic a week ago about setting the hitarea of the picked up sprite to 0 0 0 0, and that worked well. Here's a picture of how it looks: Now I'm stuck on how to get the square I dropped it on. When the player releases the mouse, the piece will be dropped wherever their cursor is, but I'm having a hard time figuring out how to efficiently grab the sprite that I dropped it over. Since I already have onmouseover event over the tiles, I could always just store that reference globally or something, but that's probably terrible idea lol. What's a nice way to handle this?