nesdev.com
http://forums.nesdev.com/

Understanding sprite tile flipping
http://forums.nesdev.com/viewtopic.php?f=3&t=14719
Page 1 of 1

Author:  DarylTechNES [ Sun Aug 21, 2016 8:36 am ]
Post subject:  Understanding sprite tile flipping

I'm having issues figuring out how to handle tile flipping (byte 2 of sprite OAM memory).

Consider if the bit is set to flip a sprite horizontally and its an 8x8 tile at 0,0 that looks like this (for simplicity):

Code:
a 0 0 0 0 0 0 b
e 0 0 0 0 0 0 f
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 d


Would a horizontal flip result in this? My rationale is that it flips in the middle, on a "horizon" as the pivot point.

Code:
c 0 0 0 0 0 0 d
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
e 0 0 0 0 0 0 f
a 0 0 0 0 0 0 b


For a vertical flip, same idea:

(Original)
Code:
a 0 0 0 0 0 0 b
e 0 0 0 0 0 0 f
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 d



(Vertical flip bit set)
Code:
b 0 0 0 0 0 0 a
f 0 0 0 0 0 0 e
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
d 0 0 0 0 0 0 c


Does any of this look right? Its rendering terribly in my emulator so I'm guessing I'm not interpreting this correctly.

Author:  Dwedit [ Sun Aug 21, 2016 8:54 am ]
Post subject:  Re: Understanding sprite tile flipping

You have 'horizontal flipping' and 'vertical flipping' switched in your post.

Author:  Zepper [ Sun Aug 21, 2016 9:18 am ]
Post subject:  Re: Understanding sprite tile flipping

Code:
unsigned int vsize = (ppu_2000 & 0x20)? 0x0F: 0x07;

         /* attributes */
         attrib = sprites[2];
         /* horizontal position +flip
          */
         if(attrib & 0x40)
            xcomp ^= 7;

         /* vertical position +flip
          */
         drawline = (current_scanline - 22 - sprites[0]) & 0x0F;
         if(attrib & 0x80)
            drawline ^= vsize;

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/