Tilemap editor help.
BlitzMax Forums/BlitzMax Beginners Area/Tilemap editor help.
| ||
Ok here is my source code so far after 20 mins.Graphics 640,480,0 Global tileset = LoadAnimImage("tileset.png",16,16,0,9) SetMaskColor 0,0,0 Global icon = LoadImage("icon.png") MidHandleImage icon Global MX:Int,MY:Int Global mapX:Int,mapY:Int Global gx:Int,gy:Int Global tx:Int,ty:Int tx = 50 Global map[40,20] Repeat Cls draw_tileset() update_map() control() Flip Until KeyHit(KEY_ESCAPE) = True Function update_map() For x:Int = 0 To 39 For y:Int = 0 To 19 If map[x,y] > 0 And map[x,y] < 9 gx = x*16 gy = y*16 DrawImage tileset,gx,gy,map[x,y] EndIf Next Next End Function Function control() MX = MouseX() MY = MouseY() For x = 0 To 39 For y = 0 To 19 If MX = map[x,y] And MY = map[x,y] DrawImage icon,MX,MY,0 EndIf Next Next End Function Function draw_tileset() tx = 100 For i:Int = 0 To 8 DrawImage tileset,tx,464,i tx = tx + 16 Next End Function What I want is for you guys to look at the control function. What I'm trying to do is draw an outline(icon image) over the currently selected area of the array or map. media here : http://www.kamikazekrow.com/storage/tiles.zip Basically I am trying to draw an outline around the current tile. |
| ||
all you need is something like: x=16*floor((MX-100)/16)+100 y=whatever draw icon at x,y *Untested* Looping through all the tiles checking each one is a waste of time. |
| ||
I still cant get it to work. I just dont seem to be able to understand the concept. Thx anyway Falken. :) Can anyone else help? |
| ||
If your tiles are 16x16 (which it looks like they are) divide the mouseX and mouseY by 16. Then multiply them both with 16 and draw the icon to that position. You might have to fiddle with the image handle or add maybe 8 to the x and y to make it look right but you should be getting something like what you want. So the code might be something like this: Function control() MX = MouseX() MY = MouseY() DrawImage( icon, (MX/16)*16, (MY/16)*16, 0 ) End Function |
| ||
Hey thx Big&. :) This is exactly what I wanted. :) |
| ||
An alternative, rather than using a /16 and *16 to get cooridnates that align to a grid, you could use `and`, ie..DrawImage icon,MX and $FFF0,MY and $FFF0,0 That's probably going to be more efficient. You just basically erase the lower 4 bits to 0 so that the coordinates don't have any `resolution` more accurate than to the nearest 16. |
| ||
That's the oldskool, quickest and easiest method, except in Max, you'd be wanting to replace 'And' with '&' for the binary operator. |
| ||
nice tip.. thanks from me ^^ oldschool rocks! |
| ||
Oh, good to keep in mind |
| ||
Lovely tip angel. I worked out the /16 * 16 when I was back on Amiga Blitz. Nice to know there's a much better way! |
| ||
And you can have it draw to a grid of other sizes so long as they are powers of 2, ie 2 4 8 16 32 64 128 256 etc. |