Weird overlapping issue on dynamically generated Tile grid

Just started using Construct 2? Post your questions here

Post » Tue May 27, 2014 7:57 pm

Hi everyone. This is my first post on this forum and I'm not sure about the protocol, so feel free to point out if I'm doing something wrong (I have already searched the forums and couldn't find a similar issue to mine).

I'm currently working on a turn-based board game with tiles. I've been mostly following the "Small Tactics" tutorial by @Kyatric, (I can't post the URL apparently). The main difference is that while he manually places the Cell sprite objects and snaps them to the grid, I generate them dynamically like this:
Image

I then proceed to create the Player Sprites (which are the same size as the tiles) and place them on the corners by selecting the respective tiles (Xpos = 0, Ypos = 0; Xpos = grid_size - 1, Ypos = grid_size - 1) and changing their position to Tile.X and Tile.Y. So far so good.

The problem arises when I try to (in another event) select the tile the Player Sprite is currently on by using the condition "Player is overlapping Tile". When I'm referring to the Player on the logic [0, 0] it's ok, but when it's the other Player, the tile selected is not the one at [grid_size - 1, grid_size -1], but the one at [grid_size - 2, grid_size - 2]. How can this be if all tiles are exactly the same size and spaced apart by that same amount, and the player sprites are the same size as the tiles and placed at the center of them?

I have circumvented the issue by simply adding a logical position instance variable to the player sprites, not having to rely on overlapping to figure out where the player is (which is a better practice anyway because I may want to use player sprites which are bigger than the tiles if I decide to use more of a top-side view rather than top-down) but I am still curious for a solution to this particular issue.


I hope the problem was well specified

Cheers
B
6
S
2
Posts: 79
Reputation: 608

Post » Wed May 28, 2014 4:45 am

Overlapping in that case considers you are overlapping the current tile as well as all its neighbours.
Simply reduce the size of your player's sprite by a few pixels it will only return the very tile you're overlapping.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,313
Reputation: 71,094

Post » Wed May 28, 2014 7:56 am

Thank you, that fixed the problem :D

Although I figured out that I only have to reduce the player sprite hitbox, not the entire sprite

Thanks a lot
B
6
S
2
Posts: 79
Reputation: 608


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests