Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: leafy on February 13, 2011, 11:28:46 pm

Title: Full-Byte Tilemapping
Post 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
Title: Re: Full-Byte Tilemapping
Post by: Darl181 on February 13, 2011, 11:49:10 pm
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.
Title: Re: Full-Byte Tilemapping
Post by: leafy on February 13, 2011, 11:54:45 pm
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.
Title: Re: Full-Byte Tilemapping
Post by: Darl181 on February 14, 2011, 12:03:35 am
I'm assuming it's 5*5 tiles, and that symbol is L1.
Or whatever list you're using.
Title: Re: Full-Byte Tilemapping
Post by: shmibs on February 14, 2011, 12:54:09 am
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)
Title: Re: Full-Byte Tilemapping
Post by: Builderboy on February 14, 2011, 01:00:19 am
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.
Title: Re: Full-Byte Tilemapping
Post by: shmibs on February 14, 2011, 01:07:34 am
herp-a-derp :P
post edited because i made the same mistake he did(although in a different spot).
thanks, builder
Title: Re: Full-Byte Tilemapping
Post by: Builderboy on February 14, 2011, 01:10:27 am
X*18+Y

I was talking about this part ;)
Title: Re: Full-Byte Tilemapping
Post by: Runer112 on February 14, 2011, 01:35:30 am
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.

Code: [Select]
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.
Title: Re: Full-Byte Tilemapping
Post by: Builderboy on February 14, 2011, 01:36:52 am
If you assume a non scrolling tilemap couldn't you just use a single variable for tilemap offset and increment it?  No multiplication needed.
Title: Re: Full-Byte Tilemapping
Post by: Runer112 on February 14, 2011, 01:40:27 am
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.