Author Topic: HELP - Tilemap fill black outside the map  (Read 4722 times)

0 Members and 3 Guests are viewing this topic.

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
HELP - Tilemap fill black outside the map
« on: April 11, 2015, 11:11:46 am »
Problem: Area outside the tilemap is filled with the TI's memory.
Objective: Fill the area outside my tilemap with black.
Image:

Thanks in advance.

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: HELP - Tilemap fill black outside the map
« Reply #1 on: April 11, 2015, 11:20:21 am »
What is the data structure for your tilemap? Can we see how it looks in the program?

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #2 on: April 11, 2015, 11:27:31 am »
Code: [Select]
.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

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: HELP - Tilemap fill black outside the map
« Reply #3 on: April 11, 2015, 11:30:34 am »
Is your tilemap a set area in memory? Like do you actually have tile data stored somewhere in memory?

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: HELP - Tilemap fill black outside the map
« Reply #4 on: April 11, 2015, 11:49:32 am »
Do you always know the tilemaps size?

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #5 on: April 11, 2015, 11:55:18 am »
There are two solutions to this problem:

  • 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.
« Last Edit: April 11, 2015, 12:04:10 pm by Runer112 »

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #6 on: April 11, 2015, 03:52:35 pm »
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:

  • 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.
Thanks, i will begin testing.

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #7 on: April 11, 2015, 03:58:57 pm »
Okay, this issue is solved. Thanks, runner's second solution worked perfectly. Although i understand the concept, I dont understand how and why it works. Could you explain it please?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #8 on: April 11, 2015, 04:34:36 pm »
Sure, I can break down the code a bit. Since only the tile lookup logic changed, I'm just going to focus on that. Also, I realized I could make the logic a bit nicer, so I'm going to explain this slightly different version:

Code: [Select]
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<32If 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→CCalculate the pointer offset of this tile index (saved for later in C)
+Pic0Add 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+Pic1Add the pointer offset to the tileset secondary data pointer to obtain a pointer to the tile's secondary sprite
« Last Edit: April 11, 2015, 04:43:45 pm by Runer112 »

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
Re: HELP - Tilemap fill black outside the map
« Reply #9 on: April 12, 2015, 03:07:06 am »
Sweet, case closed thanks for your help.