Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Yeong on December 16, 2011, 11:27:19 am

Title: [Mini Tutorial] How to flip around 8x8 sprite data
Post by: Yeong on December 16, 2011, 11:27:19 am
Let's hope that this will be useful to somebody

Let's say you have this sprite data for example: [1818101C10282828]

Horizontal Flipping:

1. separate the data by 2 digits: [ 18 18 10 1C 10 28 28 28 ]
2. switch the order of 2 digits   : [ 81 81 01 C1 01 82 82 82 ]
3. Now change each digit to its complement(Is this what these are called?)
    Here's the list if you don't know it.    
    0↔0  1↔8   2↔4  3↔C  5↔A  6↔6  7↔E  9↔9  B↔D  F↔F
So if we change it, it should be: [ 18 18 08 38 08 14 14 14 ]

So the result is: [1818083808141414]!

Vertical Flipping:

This thing is easier than the horizontal flipping.

1. separate the data by 2 digits: [ 18 18 10 1C 10 28 28 28 ]
2. switch the places around (First set with last set, 2nd set with 7th set, etc)
    So it should look like: [ 28 28 28 10 1C 20 18 18 ]

So the result is: [282828101C201818]!
Title: Re: [Mini Tutorial] How to flip around 8x8 sprite data
Post by: Runer112 on December 16, 2011, 11:54:07 am
It's probably worth mentioning that, for flipping sprites during program execution, you don't have to implement those algorithms yourself. Just use the built-in flipH() and flipV() commands. :)
Title: Re: [Mini Tutorial] How to flip around 8x8 sprite data
Post by: Yeong on December 16, 2011, 12:25:19 pm
but didn't those two had a some kind of restriction?
Title: Re: [Mini Tutorial] How to flip around 8x8 sprite data
Post by: Quigibo on December 16, 2011, 02:51:22 pm
The only restriction is that you can't flip it twice without a copy, but the main advantage of pre-flipping the sprite before compiling is the speed gain because flipping a sprite takes some time.  It also makes sprite animation easier since you can reference sprites by a simple offset instead of extra conditionals for which direction to flip.

Of course the disadvantage is that you will have 2-4 times as many sprites that needed flipping than before, but when you only have a few sprites that need flipping (like a main character for instance) its probably smaller than including the flip routine in code.

There is also a hybrid compromise approach when you have a ton of sprites that need flipping, but you still want the fast speed without the extra size.  Just use the flip command to flip all the sprites in the beginning and copy them to a free ram location when the program loads.  Then, you can use that location with the speed of the preflip method, but with the program size of the runtime flip (minus the decompression routine).