LynxJam2023 - day 10


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

Flip

This one is the easier one :

  • add HFLIP and/or VFLIP to sprctl0
  • adjust hpos and vpos accordingly : +width if you HFLIP, +height if you VFLIP


Tilt

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

  • select the right CC65's sprite struct : SCB_REHVxxT
  • use the right sprctl1 : REVHxxT
  • set the value without forgetting it's a 8bit.8bit fixed point value (like scaling)

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 ;)

Stretch

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,

  • select the right CC65's sprite struct : SCB_REHVxxS
  • use the right sprctl1 : REVHxxS
  • set the value without forgetting it's a 8bit.8bit fixed point value (like scaling)


Stretch + negative Tilt

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)

Get Hero Dust

Download NowName your own price

Comments

Log in with itch.io to leave a comment.

Awesome devlog!

Thanks you for the devlog, and nice to see I did not chosed also a Dungeon Master like (this was one my ideas)
Just a small remark

  • adjust hpos and vpos accordingly : +width if you HFLIP, +height if you VFLIP

You can define the action point of the sprite and this impact the FLIP (and also TILT & STRETCH)

For example, if you have a 17x17 sprite and define action point in the middle at (9,9), flipping horizontally or vertically will not require to adjust coordinates.

But as you use TILT & STRETCH also, it may imply some side effects...