Posts: 35
Threads: 13
Joined: Dec 2005
I have recently found a pixel by pixel scrolling tutorial in QBasic.
pixel by pixel scrolling in Qbasic, by Aaron Severn
It's been around for a while I bet, so I tried it out.
It works very well, except that the original tutorial works with 10 * 10 pixel sprites.
can anyone tell me which numbers I have to change to make it scroll 16 * 12 tiles?
He didn't remark that portion very well.
Posts: 320
Threads: 24
Joined: Feb 2005
Well, you could always rewrite it using your own code. Pixel*pixel scrolling is really easy, actually, I don't see what the big deal is...
Okay, here's how you do it (the tutorial gives you this, too, just in a longer form, and I think he mentions clipping, too):
1) You have two variables (offset variables)that track how much the map has been scrolled (x and y-values).
2) When you draw the tiles as usual, simply do the following:
a) Compute where you would draw the tile normally (you can use an existing tile engine for this, just something that can draw tilemaps)
b) Add the offsets to the final x and y coordinates of the tile BEFORE you draw the tile.
See how simple it is? Now, go off and write yourself a nice, flexible tile engine. You'll learn more that way than copying and pasting and modifying somebody else's code. Then, in the future, you'll always be able to inplement a smooth-scrolling, pixel*pixel tile engine no matter what platform you're on.
This technique also works for isometric tile engines, by the way, and so if you ever decide to implement an isometric game, you will be able to do it easily just by modifying the way you draw the tiles.
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Posts: 35
Threads: 13
Joined: Dec 2005
ok, I've built my own pixel by pixel scrolling engine.
it works alright, but I was wondering one thing.
is there any way to get a faster command than "MOD"?
(returning the remander of a division)
I realized how slow it is, probably because it uses floating point opperations.
Posts: 1,080
Threads: 87
Joined: Feb 2002
If it's stuff MOD 2 you could replace it with stuff AND 1
/post]
Posts: 108
Threads: 0
Joined: Jan 2006
Quote:If it's stuff MOD 2 you could replace it with stuff AND 1
Let me clarify that.
X MOD Y will evaluate to the same result as X AND Y if Y+1 is an integer power of 2.
and X \ Y evaluates to X shr Z, where Y = 2^Z
(y HAS to be a power of 2)
to math geeks out there:
how would you factor Z from this: Y = 2^Z :-?
Posts: 6,419
Threads: 74
Joined: Mar 2002
Quote:ok, I've built my own pixel by pixel scrolling engine.
it works alright, but I was wondering one thing.
is there any way to get a faster command than "MOD"?
(returning the remander of a division)
I realized how slow it is, probably because it uses floating point opperations.
Use tile dimmensions that are a power of two. That way you won't have to multiply/divide/modulize ever.
If you do 16*16 tiles, QB will change /16 and *16 by "SHR 4" and "SHL 4" which are binary shifts (right and left, respectively) - so much faster. The module can be calculated as mentioned: A AND 15 is the same as A MOD 16. This only works with powers of two (i.e. A MOD 2 = A AND 1, A MOD 4 = A AND 3, etcétera).
Posts: 488
Threads: 19
Joined: Sep 2005
Quote:and X \ Y evaluates to X shr Z, where Y = 2^Z
(y HAS to be a power of 2)
to math geeks out there:
how would you factor Z from this: Y = 2^Z :-?
Rational Exponents
Exponential Equation:
a^x = a^y
So Y = 2^Z
You would turn Y into a base of 2 then solve x = y
Let's say Y = 8 then:
2^3 = 2^Z <- 2^3 = 8 as a base of 2
x = y
3 = Z
Therefore Z = 3
Let's say Y = 16 then:
2^4 = 2^Z <- 2^4 = 8 as a base of 2
x = y
4 = Z
Therefore Z = 4
...
That's Exponential Equations in a nutshell, if you need more help just ask
Posts: 6,419
Threads: 74
Joined: Mar 2002
Just use Logs