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

Get help using Construct 2

Post » Tue Oct 21, 2014 10:08 pm

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

Image

Image
Last edited by valdarko on Fri Apr 17, 2015 7:17 am, edited 3 times in total.
B
48
S
5
G
6
Posts: 210
Reputation: 6,297

Post » Tue Oct 21, 2014 10:34 pm

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.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Tue Oct 21, 2014 10:36 pm

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.
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Tue Oct 21, 2014 10:38 pm

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.
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Tue Oct 21, 2014 10:39 pm

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
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Tue Oct 21, 2014 11:21 pm

@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
B
48
S
5
G
6
Posts: 210
Reputation: 6,297

Post » Wed Oct 22, 2014 7:24 pm

@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
B
48
S
5
G
6
Posts: 210
Reputation: 6,297

Post » Wed Oct 22, 2014 11:10 pm

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

Image
B
48
S
5
G
6
Posts: 210
Reputation: 6,297

Post » Wed Oct 22, 2014 11:39 pm

Why are you getting all of those lines between your tiles?
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Wed Oct 22, 2014 11:40 pm

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
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests