.TITLE
[SPRITES]
[HEX MAP]
5->X
3->Y
Repeat getKey(15)
sub(MOVE)
sub(SCREEN)
End
Lbl MOVE
If getKey(4):Y--
ElseIf getKey(3):X++
ElseIf getKey(1):Y++
ElseIf getKey(2):X--:End
Return
Lbl SCREEN
ClrDraw
ClrDraw^^r
For(B,0,7)
For(A,0,11)
Pt-On(A*8,B*8,{32*(B+Y)+A+X+GDB0}*8+Pic0)
Pt-On(A*8,B*8,{32*(B+Y)+A+X+GDB0}*8+Pic1)^^r
End
End
Text(0,0,(32*(B+Q)+A+P+GDB0))
Pt-Off(40,24,Pic2+8)
Pt-Off(40,24,Pic2)^^r
DispGraph
DispGraph^^r
Return
Pt-On(A*8,B*8,((B+Y→D<32?A+X→C<32)?{D*32+C+GDB0}*8,BLACK_TILE_INDEX)+Pic0→C)
Pt-On(A*8,B*8,C-Pic0+Pic1)ʳ
Is your tilemap a set area in memory? Like do you actually have tile data stored somewhere in memory?Yes, GDB0
Do you always know the tilemaps size?Yes, 32x32
There are two solutions to this problem:Thanks, i will begin testing.
- Add enough black tiles around the edges of your tilemap so that the camera can never move far enough to go past them. This only costs as much extra time as it takes to perform the larger Y-coordinate multiplication to look up a tile, but does cost a fair amount of extra map space, so might not be ideal.
- Check if a tile to render's coordinates are outside of the map, and if so, produce a black tile instead. This only costs a small amount of time and requires no extra map data, so is probably the desired solution. Your map tile drawing code should then look something like the following (untested!), which should look up the tile index normally if both coordinates are between 0 and 31 or return the black tile index if not:
Code: [Select]Pt-On(A*8,B*8,((B+Y→D<32?A+X→C<32)?{D*32+C+GDB0}*8,BLACK_TILE_INDEX)+Pic0→C)
Pt-On(A*8,B*8,C-Pic0+Pic1)ʳ
Unrelated to your question, but there's also a good potential for optimization (and a bit of a bug) with how you display each frame and prepare the next. The optimization is that DispGraphʳ : ClrDraw : ClrDrawʳ can all be done in one command with DispGraphClrDrawʳ. And the bug is that the DispGraph without the ʳ shouldn't be there, as you have two display commands fighting between monochrome and grayscale graphics.
Pt-On(A*8,B*8,((B+Y→D<32?A+X→C<32)?{D*32+C+GDB0},BLACK_TILE_INDEX)*8→C+Pic0)
Pt-On(A*8,B*8,C+Pic1)ʳ
((B+Y→D<32 | If the Y-coordinate (saved for later in D) is between 0 and 31 (this is an unsigned comparison, so negative coordinates are interpreted as really large positive coordinates and are not less than 32) |
? | And (a ternary operator with only one following clause is like a short-circuit AND operator) |
A+X→C<32) | If the X-coordinate (saved for later in C) is between 0 and 31 |
? | Then: |
{D*32+C+GDB0} | Look up the tile index at (C, D) in the map GDB0 |
, | Else: |
BLACK_TILE_INDEX) | Use the black tile index |
*8→C | Calculate the pointer offset of this tile index (saved for later in C) |
+Pic0 | Add the pointer offset to the tileset primary data pointer to obtain a pointer to the tile's primary sprite |
... In the next sprite command... | |
C+Pic1 | Add the pointer offset to the tileset secondary data pointer to obtain a pointer to the tile's secondary sprite |