[Solved]Place object relative to a tile [roguelite]

1 favourites
  • 14 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • hey guys, i'm making a roguelite platformer and i have this problem to place objects and populate the map

    i'v manage to make the procedural generation of the basic platforms, but my problem is how to place objects inside the map

    using a tilemap with 16x16 tiles, how can i spawn a object at a random place but relative to the grid (16x16)?

  • When generating your random position, generate random numbers between 0 and the height or width of your level in tiles, then multiply that value by the width/height of your tiles. For example:

    Create object A at floor(random(Width in tiles)) * TileWidth, floor(random(Height in tiles)) * TileHeight

    Assuming your object's hotspot is in a corner of your image(the size being a multiple of your tile size), then your object will be placed properly aligned to the grid.

  • After spawning the object , set its position to a rounded value of a multiple of 16

    you can also destroy it if it accidentally appears on top of a ground tile.

    or in your spawning code, only create it in the first place if the value its going to "attempt" to spawn it on isnt a ground tile (unless you are trying to do some sort of digging mechanic.

  • Out of curiosity, are you creating tiles across the whole map, then randomly spawning those blue boxes and deleting the tiles that they overlap?

    then running the bitwise update to calculate which tile look goes next to each one?

    clever way of doing it.

  • One other way to approach it that i just thought of, is that if you only want items to spawn above your ground tile, then while spawning your items, use a "pick by evaluate" to only pick tiles with the bitwise value that equals your standard "ground" tile, then subtract the tile height (eg: 16). Thus they will only appear above the ground, and centered in the correct location.

    pseudo code

    pick all tiles = tile.bitwise = "ground"

    randomly pick how often a item should be created eg: 10% of the time

    for each tile -> spawn item at tile.x, tile.y-tile.height

  • linkman2004

    justifun

    it works like a gem, thank you very much!

    and yes, it spawn a lot of squares(about 30) at random locations with random angles that erase overlaping tiles and then when the tickcount hit 20~25 the bitwise function update the map

    since i'm not very good with math i have to use this kind of "duct tape code"

    the good thing is that is simple and i understand what is going on

  • justifun

    i tried your method but i think the way i handle the code cant support this approach

    its uses a local variable to upade the tiles

    but i need a way to check the tilemap and place a iten above the especific tile type, geez... i have a work around but if you guys have any clue to solve this, then it would be nice to try it

  • well... i think i solved but still needs a lot of work

  • Why are you getting all of those lines between your tiles?

  • You can have it check the value of a tile, you make a loop that goes through each tile once after creating them, and if its equal to the value you want, then you can make it do something.... i think i have an example capx. lemme find it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can have it check the value of a tile, you make a loop that goes through each tile once after creating them, and if its equal to the value you want, then you can make it do something.... i think i have an example capx. lemme find it

  • check this out

    https://dl.dropboxusercontent.com/u/403350/example.capx

    See how i looped through the tilemap and if the tile was a "sign" tile, it placed a red solid square overtop.

  • justifun

    those lines are there because i mess up the image, the tiles was 32x32 but i needed a 16x16 so i just resize then for a small size, no big deal since i'll change it later

    if you have a capx with a example it would be great, thanks

  • justifun

    geez, nice and simple, thank you very much man

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