Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: leafy on February 13, 2011, 11:28:46 pm
-
How come this code doesn't work for a 18 by 12 tilemap?
Lbl MAP
ClrDraw
For(Y,0,11
For(X,0,17
{Y*18+X+L}->A
Pt-On(X*5,Y*5,A*16+Pic1)
End
End
StorePic
Return
-
Try putting in a dispgraph? (if the problem is it isn't showing anything)
It looks fine to me...
Hex pics are 8 bytes. So, unless they're two-frame animated or something, it would be A*8+Pic1.
-
No, I already have a dispgraph. And the *16 is because i'm using SirCmpwn's sprite editor, which uses greyscale tiles (two *8) which I usually up ending up removing at the end.
But it's not working, oddly enough. I'll check my level data and get back to you.
-
I'm assuming it's 5*5 tiles, and that symbol is L1.
Or whatever list you're using.
-
your X and Y are switched in the {} section.
here's how i would write this bit of code
:ClrDraw
:19While -1->X
:13While -1->Y
:Pt-On(X*5,Y*5,{X-1*18+Y-1+L1}*16+Pic1
:XEnd
:YEnd
:StorePic
:Return
EDIT: this time the code should actually work (although you should look below for runer's faster method)
-
Shmibs, I think you are mixed up? I guess it depends on how his tilemap data is read. From the top left going to the right and down, or from top left going down and then right.
-
herp-a-derp :P
post edited because i made the same mistake he did(although in a different spot).
thanks, builder
-
X*18+Y
I was talking about this part ;)
-
By the way, loops like these:
:18While -1->X
:12While -1->Y
Will break as soon as the variable becomes 0, so a row and column of sprites would be missing.
Also, you using Pt-Off() to draw a 5*5 tilemap could (in this case will) overwrite already drawn tiles as it draws other tiles, so it's best (and faster anyways) to use Pt-On().
Here's the code I would use. It's size-optimized, but is still also quite speed-optimized, too.
Lbl MAP
ClrDraw
12*18+L₁→Z
12*256
Repeat 0
-256→Y
18
Repeat 0
-1→X
Pt-On(*5,{°Y+1}ʳ*5,{Z-1→Z}*16+Pic1)
End!If X
End!If Y
StorePic
Return
EDIT: 432 cycles saved with some pretty sweet high/low byte abuse of Y.
-
If you assume a non scrolling tilemap couldn't you just use a single variable for tilemap offset and increment it? No multiplication needed.
-
I was thinking about that, but for some reason I thought it was a scrolling tilemapper and that that wouldn't work. But you're right, that's smaller and faster, so I've adjusted my code for that.