# Omnimaga

## Calculator Community => Major Community Projects => The Axe Parser Project => Topic started by: coops on August 25, 2016, 05:57:01 pm

Post by: coops on August 25, 2016, 05:57:01 pm
Hey,

So, I'm wanting to program a game where I draw a tilemap for the background and have masked sprites for the character and objects/enemies, etc. It'd be a side-scrolling game

I read here that the quickest way to get a tilemap to shift is by using the Horizontal or Vertical commands. You then redraw the side the direction the map shifted. Like, if the map moves down, you redraw that side, etc. This avoids drawing the whole map over again.

If the screen has masked sprites on it, will they shift along with everything else when I use the Horizontal/Vertical commands? How could I avoid it?

It probably has to do with the front and back buffers, but I dont know too much about them, so an explanation on buffers could be helpful! :D
Post by: Sorunome on August 25, 2016, 06:02:43 pm
Hey,

So, I'm wanting to program a game where I draw a tilemap for the background and have masked sprites for the character and objects/enemies, etc. It'd be a side-scrolling game

I read here that the quickest way to get a tilemap to shift is by using the Horizontal or Vertical commands. You then redraw the side the direction the map shifted. Like, if the map moves down, you redraw that side, etc. This avoids drawing the whole map over again.
Sounds right
Quote
If the screen has masked sprites on it, will they shift along with everything else when I use the Horizontal/Vertical commands? How could I avoid it?
Yes, the masked sprite would also shift along
Quote
It probably has to do with the front and back buffers, but I dont know too much about them, so an explanation on buffers could be helpful! :D
There are multiple ways in solving this problem, as you already suggested back and front buffers, i'll explain that one.
The following is assuming you don't use grayscale, only black/white.

So, basically you draw your tilemap to the back buffer (you know, with the ^r command), and then also shift the back-buffer (whith Horizontal+^r etc.)

Then, when drawing the screen, you copy the back buffer to the front buffer: Copy(L3)

And then with DispGraph the screen gets updated.

I hope that made sense somehow :3
Post by: coops on August 25, 2016, 06:14:04 pm
I think so...It typicallly makes more sense in practice, lol.

I'm making the DrawMap command right now, and I'm drawing everything to the back buffer like you said. but, nothing's showing up. Is there a command to display the back buffer?

Also, should I use Pt-On( or Pt-Off? Xor or Overwrite logic?
Post by: Sorunome on August 25, 2016, 06:15:35 pm
Well, it's not showing up as you have to copy it to the front buffer first, with Copy(L3)

In case you want to, for whatever reason, display the back buffer directly to the screen (where you actually don't want to have the masked sprite on), you do DispGraph(L3)
Post by: coops on August 25, 2016, 06:32:58 pm
ahh, thanks! that makes a lot more sense!
Post by: coops on August 26, 2016, 07:17:23 pm
Alright. So I took Sorunome's advice. I draw the map onto the back buffer and wrote a routine to shift it with the horizontal and vertical commands. I then use Copy(L3) to send it to the front. It works great, however, I'm kindof stumped at this minor problem.

The routine uses the Horizontal/Vertical command first, then redraws the appropriate area. In the attachments, you can see that every 16 pixels the redraw method isn't working, and I'm left with a line of pixels that isn't drawn correctly. This only happens on the Horizontal+ and Vertical+ commands.

You can see it most notably in the horizontal screenshot, but it's the same problem with the vertical one as well.

Post by: Sorunome on August 26, 2016, 07:26:41 pm
it's very hard to tell without any code, do you have some to share?
Post by: coops on August 26, 2016, 07:38:32 pm
Gotcha! Here's what I got, it's totally not optimized! lol. I have a 16x16 tilemap. Each tile is 16x16 pixels. {GDB0} refers to the map's overall x and y corrdinates

Code: [Select]
`//Shifts Map background 1 pixelLbl Shift//Tell which Tile is on the top left of the screen!If {GDB0}/2/2/2/2→A=0:15-A→A:End!If {1+GDB0}/2/2/2/2→B=0:15-B→B:EndIf r₁=1Vertical-ʳ16*B→CFor(J,A,A+7)C+J+64→NDraw(16*J+{GDB0},C+64+{1+GDB0},{N+GDB0MAP}*32+Pic0TileEndElseIf r₁=2Horizontal+ʳFor(I,B,B+5)16*I+A→NDraw(16*A+{GDB0},16*I+{1+GDB0},{N+GDB0MAP}*32+Pic0Tile  EndElseIf r₁=3Horizontal-ʳ For(I,B,B+5)16*I+A+6→NDraw(16*A+96+{GDB0},16*I+{1+GDB0},{N+GDB0MAP}*32+Pic0Tile  EndElseIf r₁=4Vertical+ʳ16*B→CFor(J,A,A+7)C+J→NDraw(16*J+{GDB0},C+{1+GDB0},{N+GDB0MAP}*32+Pic0TileEndEndCopy(L₃) Return--------------------------Here's the action key that calls shift. The map cannot scroll past the boundaries.Lbl ActionKey{GDB0}→X{1+GDB0}→YIf getKey(1)If Y≠64{1+GDB0}--Shift(1)EndEndIf getKey(2)If X≠0{GDB0}++Shift(2)EndEndIf getKey(3)If X≠96{GDB0}--Shift(3)EndEndIf getKey(4)If Y≠0{1+GDB0}++Shift(4)EndEndReturn`Hope that explains enough!

Post by: Sorunome on August 26, 2016, 07:59:34 pm
How does your method "Draw" look like? (More importantly: what kind of arguments does it take / what do they do)

From the look of the screenshot it looks like when it is shifting out a whole tile it isn't working as expected, so my guess right now is that something with
Code: [Select]
`!If {GDB0}/2/2/2/2→A=0:15-A→A:End!If {1+GDB0}/2/2/2/2→B=0:15-B→B:End`is wrong. Without really knowing what the code does, why 15-A and 15-B and not 16? (since your tiles are 16x16)

Again, I don't really understand your code yet, i might be just plain up wrong, lol
Post by: coops on August 26, 2016, 08:09:03 pm
Code: [Select]
`!If {GDB0}/2/2/2/2→A=0:15-A→A:End!If {1+GDB0}/2/2/2/2→B=0:15-B→B:End`
This returns the reference number to the tile in the upper right hand of the screen. A is the number of tiles to the right, B is the number of tiles down. It's pretty accurate. What's weird is this is working when usingt he Vertical- and Horizontal- commands, the shift method works fine...

Draw is very simple: takes an x, y and pointer. I chose to use overwrite logic

Code: [Select]
`Lbl Draw  Pt-Off(r₁,r₂,r₃)ʳ  Pt-Off(r₁+8,r₂,r₃+8)ʳ  Pt-Off(r₁+8,r₂+8,r₃+16)ʳ  Pt-Off(r₁,r₂+8,r₃+24)ʳReturn`
ActionKey doesn't recieve any parameters.

Shift takes 1 parameter: 1 - 4, associated with the four directional keys.

Here's the main loop:

Code: [Select]
`Lbl MainRepeat getKey(15)//ClrDrawActionKey()//redraw the map by pressing enterIf getKey(9)DrawMap({GDB0},{1+GDB0})EndDispGraphEndReturn`
Post by: Sorunome on August 26, 2016, 08:24:46 pm
Hang on, you said {GDB0} and {GDB0+1} hold the x- and y-coordinates of the map, right?

I don't see that changed at all in your Shift routine, keep in mind that you need to grab the tiles to re-draw from the new coordinates, not from the old ones