map editor 2
BlitzMax Forums/BlitzMax Beginners Area/map editor 2
| ||
Take a look at these two function.Function place() If MouseDown(KEY_MOUSELEFT) For Local i:Int = 0 To mapx-1 For Local j:Int = 0 To mapy-1 map[i,j] = curtile Next Next EndIf End Function Function update() For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 DrawImage tiles,x*50,y*50,map[mapx-1,mapy-1] Next Next End Function What am I doing wrong? here is all the code |
| ||
Two things I can see: You don't need any loops for your place function. You need to work out how to convert the current mouse co-ordinates to an array index, then simply make that array index equal to the current tile. You would also need to deselect the previously current tile, so it may be easier to implement this using global variables instead. Secondly, replace DrawImage tiles,x*50,y*50,map[mapx-1,mapy-1] with DrawImage tiles,x*50,y*50,map[x,y] You need to use the variables for your indices, not your constant upper bounds. Ryan |
| ||
Hey Ryan. I was hoping you would be about coz you seem to help me the most. I'll try what you said. Thanks :) |
| ||
Amon, I've edited my post - look again. |
| ||
Quick question How would I do the following? You need to work out how to convert the current mouse co-ordinates to an array index |
| ||
If you are drawing your tile palette at 0,0 for instance you can simply divide the mouse coordinates by the width and height respectively to find the array index. |
| ||
You mean like thisFunction place() Local x:Int = MouseX()/50*50 Local y:Int = MouseY()/50*50 If MouseDown(KEY_MOUSELEFT) DrawImage tiles,x,y,curtile map[x-1,y-1] = curtile EndIf End Function A code example would be nice. Please :) |
| ||
This is what you want:Function place() If MouseDown(KEY_MOUSELEFT) map[ MouseX() / 50, MouseY() / 50 ] = curtile Endif End Function |
| ||
Thanks Ryan. That works perfactly and is simple also. I dont understand why I cant figure out these things. |
| ||
@Amon don't take offense.....but this usually happens because people usually make things complicated......remember, divide and conquer...... to be short, think simple ;) for example.....a long time ago, in a college far away......i was taking "data structures and algorithms ii" and we were supposed to create an "infinite precision math library".....we were given a couple functions pre-made, and we had to create several other functions and operators.....so i was working on the equality operator.... made it in one line.....basically if a number is not greater than AND not less than the other, they are equal........ get my point? less is more. i guess it's just practice..... btw, Ryan Moody, nice work there ;) |
| ||
Thanks Loonie! |