Tiles

A

Amoses

Guest
So, i am making a tower defense game and i want to make it so whenever my mouse hovers over any tile that isnt the dirt path, a different tile replaces it. could anybody help me? i have 0 experience with tiles
 

Rob

Member
tilemap_set_at_pixel will change a tile to another tile.

If you google that function and read the relevant manual parts it's pretty straightforward.

It's also worth noting that the indexes for tiles start at 0 (the top left most tile in a tileset) and their index increases by 1 from left to right.

If you need something visual here's a video of how to change tiles wit the mouse:

U
 
A

Amoses

Guest
tilemap_set_at_pixel will change a tile to another tile.

If you google that function and read the relevant manual parts it's pretty straightforward.

It's also worth noting that the indexes for tiles start at 0 (the top left most tile in a tileset) and their index increases by 1 from left to right.

If you need something visual here's a video of how to change tiles wit the mouse:

U
thank you! also, do you know if there is a way to magnetize a object to tiles?
 
S

Smallmak

Guest
tilemap_set_at_pixel will change a tile to another tile.

If you google that function and read the relevant manual parts it's pretty straightforward.

It's also worth noting that the indexes for tiles start at 0 (the top left most tile in a tileset) and their index increases by 1 from left to right.

If you need something visual here's a video of how to change tiles wit the mouse:

U
just checked out your youtube channel. great stuff, you sir just got a new subscriber.

Edit: I just realized this post didn't pertain to the topic, sorry. in order to make it pertinent friendly cosmonaut also has a good video on tiles.
 
  • Like
Reactions: Rob
A

Amoses

Guest
What do you mean by magnetize?
like, whenever a object gets close enough to a certain tile, that tile changes to a different tile sorta like [distance_to_tile, which i know isnt a thing but maybe there is a different syntax that makes that work?]
 

Rob

Member
P
like, whenever a object gets close enough to a certain tile, that tile changes to a different tile sorta like [distance_to_tile, which i know isnt a thing but maybe there is a different syntax that makes that work?]
Youll need to check for a radius around that object and then change those tiles that are within the radius.
 
A

Amoses

Guest
P

Youll need to check for a radius around that object and then change those tiles that are within the radius.
so like if collision_circle(x, y, 20, obj_Cursor, false, true)
tilemap_set_at_pixel??
 

Rob

Member
so like if collision_circle(x, y, 20, obj_Cursor, false, true)
tilemap_set_at_pixel??
if obj_cursor is what you want to have the radius around then no.
Also collision_circle returns an instance id or no one, something that's useless for tiles.

You want to use obj_cursors x/y as the center spot but then use 2 for loops to check from (x-100 to x+100) and (y-100) to (y+100)

Assuming your tile size is 32:

Code:
//whenever the cursor moves run this code

for (var yy = y - 160; yy <= 160; yy += 32){

   for (var xx = x - 160; xx <= 160; xx += 32){
      tilemap_set_at_pixel(tile_map_element_id, tile data, xx, yy)
   }
}
 
A

Amoses

Guest
if obj_cursor is what you want to have the radius around then no.
Also collision_circle returns an instance id or no one, something that's useless for tiles.

You want to use obj_cursors x/y as the center spot but then use 2 for loops to check from (x-100 to x+100) and (y-100) to (y+100)

Assuming your tile size is 32:

Code:
//whenever the cursor moves run this code

for (var yy = y - 160; yy <= 160; yy += 32){

   for (var xx = x - 160; xx <= 160; xx += 32){
      tilemap_set_at_pixel(tile_map_element_id, tile data, xx, yy)
   }
}
do i put that in a certain object? and what is the tile data for?
 

Rob

Member
do i put that in a certain object? and what is the tile data for?
Well the code is referencing the x/y of the instance that it's in so I would put it inside the step event of whatever object you want to affect the tiles.

I don't think it will affect performance much but just putting it in the step event means the code will run 30-60 times a second, or however high your game speed is. You can reduce the amount of checks by using a timer.

As for tile_data you'll get a lot more info from the manual entry for tilemap_set_at_pixel than you ever will from my drivelling.

The more familiar you get with reading manual entries for functions the better you'll be and things will get a LOT easier!
 
A

Amoses

Guest
Well the code is referencing the x/y of the instance that it's in so I would put it inside the step event of whatever object you want to affect the tiles.

I don't think it will affect performance much but just putting it in the step event means the code will run 30-60 times a second, or however high your game speed is. You can reduce the amount of checks by using a timer.

As for tile_data you'll get a lot more info from the manual entry for tilemap_set_at_pixel than you ever will from my drivelling.

The more familiar you get with reading manual entries for functions the better you'll be and things will get a LOT easier!
thats why im trying so hard to learn alot, cause im tired of not knowing what certain things mean, anyhow i can look at most code and know exactly what it does, just wouldnt know how to put that code together without seeing it
 
Top