specific tile on tilemap - collision/overlapping

Get help using Construct 2

Post » Wed Aug 05, 2015 9:27 am

Hey,

I want to do something like this :

"playerSprite" is overlapping "tileMap : tile ID 0" > erase tile

But I don't understand how to specify tile since overlapping event works on entire tile map.
B
7
S
1
Posts: 64
Reputation: 585

Post » Wed Aug 05, 2015 9:34 am

This is an example from another thread, what you are looing for is condition (4), that's how you can check if something is overlapping a specific tile on a tilemap.

Image

Image

(Be advise that the tilemap at row 0 for both X and Y is empty so its not an error that it seems like it should be tile 3,7, its just me that didn't put any tiles in that row, so the white area around the tiles are actually row 0)

If you want the coordinate in X,Y you can just convert the TileX and TileY to that.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Aug 05, 2015 10:12 am

Thank you but what i'm looking for is a way to pick tiles by ID (as it can be seen on tile map bar).

Unfortunaly there is no simple condition, but I guess it's possible since tile IDs exist... No?
B
7
S
1
Posts: 64
Reputation: 585

Post » Wed Aug 05, 2015 10:34 am

The Tile ID is the tiles position in the tilemap. So you have to check for it like in my example.
1. Which tile you want to check
2. What type of tile is it

In my example above I check the tile underneath the bullet and check if that is a tile type of 4, which are the ID you are talking about.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Aug 05, 2015 3:16 pm

Thank you for help!

It's actually too complicated for picking tile by ID for a non programmer like me.

I guess one day there will be simple condition like :
add new condition > on collision with another object > tileMap (indicate tile ID in text field below)... and that's it!

Until this kind of improvement, I will use tile map only for decoration.
B
7
S
1
Posts: 64
Reputation: 585

Post » Wed Aug 05, 2015 6:24 pm

norab wrote:Thank you for help!

It's actually too complicated for picking tile by ID for a non programmer like me.

I guess one day there will be simple condition like :
add new condition > on collision with another object > tileMap (indicate tile ID in text field below)... and that's it!

Until this kind of improvement, I will use tile map only for decoration.

The tilemap is not really that hard to use once you understand the basics of how it is constructed.

Image

Image (1): Just using the basic tilemap in C2. You can look at a tilemap as being just a collection of images combined into 1 image. The reason to use a tilemap is because you can reuse a lot of graphic and reduce the performance hit from using a lot of sprites. So instead of adding lots of objects you simply add a tilemap and reuse the graphic over and over. There are some other benefits as well, but to keep it simple ill just focus on the basics.

Image (2): Shows a single tile in the tilemap, which current size is set to 32 x 32 px, this is equal to adding a sprite and setting its width and height to 32px. But since the tilemap split the image into tiles, you need to tell C2 what size these tiles are, so it knows how many tiles the tilemap should contain.

Image (3): Once the size of each tile have been set, C2 split the image into tiles and give each of them an ID, so its easy for you to see which graphic belongs to what tile. And it makes it possible for C2 to work with the tiles. This ID identify what image is related to a given tile. And can be compared to you making 2 sprites and calling one of them "Image_1" and the other "Image_2".

Image (4): Guess this might be what confuse you a bit. But the tilemap object can be compared to adding a lot of sprites next to each other. But instead of you having to add all of them, you just add the tilemap object and C2 will then split it up for you in the tile sizes that you set in Image (2). The tilemap object, that being the one in the C2 viewport will be split into areas that match the size of the tile width and height.

So a tilemap that is 320x320 px and have a tile width and height of 32 x 32 px will have 10 tiles in X and 10 tiles in Y. And each of these tiles will have an index so C2 know which tile is which. Looking at Image (4) you can see the tile coordinates, which always starts at 0,0 in the top left tile. This coordinate have nothing to do with the X,Y value in the normal coordinate system that C2 uses. So you can place the tilemap at X: 500 and Y: 500 in the viewport, but the top left tile in the tilemap will always be (0,0).

Image (5): Shows a tile placed on the tilemap, this tile have the tile position of (2,1) and looking at the overview in image (3) you can see that the ID of the tile is 0.

If this is makes sense to you, you can see that you can't work with a tile ID alone. Because it simply relates to what type of tile it is. You have to first tell C2 which tile coordinate you want to test.

And you do that by using the condition "Compare tile at":
Image

To test it:
Image

So you just have to remember that Tile ID and Tile coordinate cant work without each other. The Tile ID is the tile graphic in the tilemap, and the tile coordinate is on the tilemap it self.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Aug 06, 2015 9:15 am

Thank you very much for this explaination.

So, if I understand well, I have to specify coordination for all tiles wich have same ID?

If I have 30 tiles "ID:3", I must create 30 conditions for each tiles if I want add an action "on collision/ is overlapping"?

It's sounds crazy..... :shock:
Last edited by norab on Thu Aug 06, 2015 10:38 am, edited 1 time in total.
B
7
S
1
Posts: 64
Reputation: 585

Post » Thu Aug 06, 2015 10:25 am

norab wrote:Thank you very much for this explaination.

So, if I understand well, I have to specify coordination for all tiles wich have same ID?

If I have 30 tiles "ID:3", I must create 30 conditions for each tiles if I want add an action "on collision/ is overlapping"?

It's sounds crazy..... :shock:

No, the coordinates and IDs are automatically created by C2. For the coordinates as shown in image (4) these are the same no matter what tilemap you use. So top left corner will always be (0,0) regardless of your tiles being 32x32 px or 128x128px.

The tilemap object it self use its own coordinate system. Might be easier to understand if you try to make a tilemap and set the tile width and height to 1 px. Then it works the same way as the normal C2 coordinate system (X,Y) that you use whenever you make an object and move it around, all objects then have a X,Y coordinate that tells you where on the layout they are placed.
Its the same for the tilemap except it also have it owns coordinate system that it uses for placing tile correct in the tilemap.

So you don't specify a coordinate for each tile, you check a certain coordinate to see if it contain a certain tile.

If you have 30 tiles with a tile that have ID:3 you use a "For..loop" to go through each tile and check whether a tile have an ID:3 tile at that position.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Aug 06, 2015 11:05 am

When I talk about improvement, I mean that all you say would be handled by C2 in background process.

The actual way to specify tile by ID is really useful in many case but also tedious for non programmer users.

So, the "improvement" that I talking about is only ergonomics :

if the user add condition > on collision with another object > tileMap (indicate tile ID in text field below)
C2 should manage to write all the things that you explained to me in the code (comparison tile at, for...loop, etc).

I'm glad to learn what you explain to me, but I think that kind of improvement should be coherent with the principle of "no coding" developpement software.
B
7
S
1
Posts: 64
Reputation: 585

Post » Thu Aug 06, 2015 11:23 am

norab wrote:When I talk about improvement, I mean that all you say would be handled by C2 in background process.

The actual way to specify tile by ID is really useful in many case but also tedious for non programmer users.

So, the "improvement" that I talking about is only ergonomics :

if the user add condition > on collision with another object > tileMap (indicate tile ID in text field below)
C2 should manage to write all the things that you explained to me in the code (comparison tile at, for...loop, etc).

I'm glad to learn what you explain to me, but I think that kind of improvement should be coherent with the principle of "no coding" developpement software.

But what you want to do is like it is, you just want to use Tile ID first instead of coordinate. But regardless of which approach you use, you are going to have to check the tile coordinate anyway.

Your approach:
Object collide with tile on tilemap that have a certain ID
Find coordinate

C2 approach:
Check if object is colliding with a given coordinate
Check if its a certain ID

But its not really coding as I see it, its math using a very basic coordinate system.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests