Sprite Based on Surroundings

0 favourites
  • 15 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • 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.

  • 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...

  • 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.

  • 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.

  • You my friend are a genious. Thanks so much!

  • 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?

  • 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.
  • Wow that's a detailed reply! Thanks so much. I think I can figure it out. Thanks for you help I really appreciate it.

  • (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?

  • Would you like to share the capx maybe?

  • Here you are.

    dropbox.com/s/jzs0r2dt81hrvlg/MyGamev2.capx

  • And here it is

    The events were all right. Only problem was your tilemap : it was set to tiles of 32x32 but your image was 240*60. I stretched it to 256*64 and all was all right.

  • Guizmus Is there a way to change the size of the selection of tilemap say i have 16x16 tiles that i want to use? when i put a tilemap ive made that the tiles are 16x16 when i try to select one it selects like 2 because it is grabing 32x32.

  • Guizmus If i was using an array how could i check the surrounding cells? My question is very similar to this one that has been asked but im not using the bitwise method, im using the array generation method.

    I wanted to know if its possible to check the surrounding cells around a certain sprite? I needed to know this because i want my dirt sprite to change if it is exsposed to air transforming it into a grass covered dirt sprite.

    I just need help trying to figure out how to check the surrounding cells.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've quickly edited Rojohound's terrain gen capx to show how you can turn top sprites to grass.

    [attachment=0:2gf8vq9q][/attachment:2gf8vq9q]

    After generating the terrain press spacebar.

    To check surrounding tiles you'll need to loop through the array. I checked for the current cell value being "1" which is a solid then to check surrounding tiles I used CurX (this stays as it is because we're not interested in left&right surroundings) and then CurY-1 which will check "1" cell above the current cell is "0" which is air.

    If you planning on doing more like this you WILL be using bitwise numbers eventually since that has nothing to do with the fact that your terrain gen is array based it is a method of setting tiles/sprites based on surroundings.

    There is another example of mine

    HERE

    and a link to my blog post about using bitwise numbers for tiling levels.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)