Sprite Based on Surroundings

Get help using Construct 2

Post » Mon Feb 24, 2014 2:05 am

Can someone explain how to do a digging game in Construct 2? And how can I tell it to choose a particular sprite based on whether or not there is open air or more sprites of the same type. I have seen some generic explanations, but I can't figure out how to do it in Construct 2.
B
4
Posts: 11
Reputation: 251

Post » Mon Feb 24, 2014 4:26 am

viewtopic.php?t=63214&start=0

Check out the link above - you may get some help from there...

As for the air part, it depends on how you do it. Are you using tilemap, or sprites, or something else for the ground? There are to many variables to answer this without looking at a capx, i think...

Except for this: You would probably place a sprite over the "air"/"non-air" spot, and do an overlap evaluation: if sprite "is overlapping another object":ground, do this or that (or inverse it for NOT overlapping)... However, again, we need to know more about what you are trying to do...
B
193
S
6
G
7
Posts: 213
Reputation: 10,203

Post » Mon Feb 24, 2014 12:44 pm

I am trying to make a huge field of blocks, which have a grass edge when the tops are exposed to the air. Then when the person clicks a block that destroys it and the ones around e destroyed block change accordingly to the correct images. Kinda like Growtopia if you have ever played that game.
B
4
Posts: 11
Reputation: 251

Post » Mon Feb 24, 2014 1:04 pm

Ok, so here is an example of exactly what you want, using the bitwise method. I couldn't explain it very clearly (you calculate a weight for each tile, depending on the surroundings, and deduce what tile to use), but the capx is explained and clear.

I take no credit for this as I found it in the comments of this tutorial.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Mon Feb 24, 2014 1:52 pm

You my friend are a genious. Thanks so much!
B
4
Posts: 11
Reputation: 251

Post » Mon Feb 24, 2014 3:38 pm

Ok, I am not quite understanding the number thing. My tilemap is much smaller and I can't get things to show up correctly.

http://www.pasteall.org/pic/67338

Also is there a way to pre-populate the tilemap so that there are already blocks when I start?

Would I just add a Solid behaviour to walk on the blocks right?
B
4
Posts: 11
Reputation: 251

Post » Mon Feb 24, 2014 4:02 pm

This isn't simple at all, sorry, and if you want to use it, you will have to adapt it to your case.
I'll try my best :
The weight is called "bitwise" in the capx. There is a different bitwise for every surrounding configuration. It is manipulated in decimal form here, but is thought in binary form. For explaining it, I'll write it down like this : 101[2] = 5[10] (where the [X] is the base used for the number. So here 101[2] means 101 in binary, and 5[10] means 5 in decimal)
- If the tile above is empty (air), then add 1[2] to bitwise.
- If the tile on the right is empty, then add 10[2] to bitwise
- If the tile on the bottom is empty, then add 100[2] to bitwise
- If the tile on the left is empty, then add 1000[2] to bitwise
That means that, if you want to set the tile to bitwise :
- the tile number 0 in your tilemap (the first one top left) should correspond to 0[10] = 0[2] = no empty space around. This should be the tile where there isn't any grass on it
- the tile number 1 in your tilemap should correspond to 1[10] = 1[2] = only air above the sprite, so a sprite with grass on top
- the tile number 2[10] = 10[2] = only air on the right => grass on right
- the tile number 3[10] = 11[2] = air on top and right => grass on top and right, angle at top right edge
- the tile number 4[10] = 100[2] = air only on the bottom
And so on... This means that, to use this method, you will need to have a friendly tilemap, or you will have to reorganize where each tile is on the tilemap image.

- You can pre-populate a tilemap using the "tilemap bar" in construct 2's editor. Check in your tab "View" to see if the tilemap bar is checked.

- If you only have solids in this tilemap then yes, you can add the behavior. Remember that every tile in the tilemap will be solid. If you only want some things to be solid, I recommend using multiple maps on top of each other, and have one handle the solid behavior and collisions.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Tue Feb 25, 2014 4:27 am

Wow that's a detailed reply! Thanks so much. I think I can figure it out. Thanks for you help I really appreciate it.
B
4
Posts: 11
Reputation: 251

Post » Tue Feb 25, 2014 3:00 pm

(The forum wont let me post links, so just copy and paste. Sorry about that.)

This is what I have for my tilemap, its just a test:

pasteall.org/pic/67404

This is what I get when I place blocks:

pasteall.org/pic/67405

I have double and triple checked the event sheet and everything lines up with the demo you shared. This is making no sense. I have the same sized tilemap and everything seems good. What could be going wrong?
B
4
Posts: 11
Reputation: 251

Post » Tue Feb 25, 2014 3:02 pm

Would you like to share the capx maybe?
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 42 guests