Author Topic: [Mini Tutorial] How to flip around 8x8 sprite data  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
[Mini Tutorial] How to flip around 8x8 sprite data
« 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]!
« Last Edit: December 16, 2011, 11:28:05 am by TBO_Yeong »
Sig wipe!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: [Mini Tutorial] How to flip around 8x8 sprite data
« Reply #1 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. :)

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: [Mini Tutorial] How to flip around 8x8 sprite data
« Reply #2 on: December 16, 2011, 12:25:19 pm »
but didn't those two had a some kind of restriction?
Sig wipe!

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Mini Tutorial] How to flip around 8x8 sprite data
« Reply #3 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).
« Last Edit: December 16, 2011, 02:55:05 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!