Posted December 07, 2023 by KanedaFr
#lynx
I didn't like the way to use one bitmap data for every wall of my game while, with using stretch, tilt and flipping, I could use only a 1/4 of what I use today.
I know this day would come : the jam limits the game to be one block so resource is limited.
But I also know it won't be easy...and I was right
This one is the easier one :
This one is not that hard too.
If you followed Alex's tutorial, you know what it does : add X pixels every line.
But it took me some times to understand how to substract X pixels per line
I use the macro (x) << 8 to set a pixel tilting.
For small sprites, you'll probably want to use subpixel tilting, so you need to set the 8.8 full value
What if you want to negative tilting ? well, (-3)<<8 does the trick ;)
This one was a nightmare for me....
I spent half of my time fighting with it because, since tilting and stretching are somewhat connected for me, I tough stretching was pixels based too!
I missed a details on Alex's tutorial .... but with the help of 42Bastian, Vince and the official doc, I suddenly understood my (big) mistake.
The modification consists of adding the 16 bit stretch value ('STRETCH') to the 16 bit size value ('HSIZE') at the end of the processing of a scan line.
This one killed me!
HSIZE is not the width of the sprite but the scale of the sprite.
So stretch adds with hscale value to define a new horizontal scale every line.
Every line, sprite scale is HPOS + line*STRETCH
If you're sprite is 50 pixels and you set a stretch value of 1<<8, you don't ask 1 pixel per line...but 50 !!
Like tilting,
When I finally understood how it works, this let me with one last problem : how to stretch AND tilt to make something like a trapeze ?
Answer : You'll need to use stretching and negative tilting.
But since stretch is scale and tilt is pixel, you can't do : stretch = 2*tilt
I first define how much pixels I want for tilting then compute the stretch value needed this way
X = tilting pixels * -2 stretch.H = X / sprite.width if X % sprite.width == 0 stretch.L = 0 else stretch.L = sprite.width / (X - (stretch.H * sprite.width))
Note : you can't make it dynamic by code since you don't know what is sprite.width on code side (buried in sprite.data)