Avoid sprite warping

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Avoid sprite warping

Post by vnsbr » Sat Aug 22, 2020 6:19 am

Is there any way to automatically avoid sprite warping like in the screenshot?

thanks!
Attachments
platform-0.png
platform-0.png (1.44 KiB) Viewed 519 times

User avatar
tokumaru
Posts: 11858
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Avoid sprite warping

Post by tokumaru » Sat Aug 22, 2020 6:28 am

No. When you draw meta-sprites you're supposed to filter out any sprites that fall out of the area of the screen. One way to do this is to calculate sprite positions using 16-bit coordinates, and only output to the OAM sprites with $00 as the high byte of both coordinates.

vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Re: Avoid sprite warping

Post by vnsbr » Sat Aug 22, 2020 6:51 am

Oh I see =/ I am using Neslib, I will take a look how to do that :)

User avatar
tokumaru
Posts: 11858
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Avoid sprite warping

Post by tokumaru » Sat Aug 22, 2020 8:10 am

But you still have to generate the 4 bytes of each OAM entry manually, don't you? I believe that if you calculate the sprite positions as ints, you can test the high byte (e.g. spritex & 0xff00) and if that's zero you copy the low byte to OAM (spritex & 0xff), otherwise just drop the sprite.

User avatar
dougeff
Posts: 2735
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Avoid sprite warping

Post by dougeff » Sat Aug 22, 2020 8:12 am

You could use this code, oam_meta_spr_clip()

found here...

https://github.com/clbr/neslib/blob/master/display.sinc

It requires you to keep x position as a 16 bit integer, where a high byte of zero means on screen, ff (-1) means off screen to the left, >=1 means off screen to the right.
nesdoug.com -- blog/tutorial on programming for the NES

vnsbr
Posts: 22
Joined: Sun Feb 17, 2019 5:18 pm

Re: Avoid sprite warping

Post by vnsbr » Sat Aug 22, 2020 8:23 am

tokumaru wrote:
Sat Aug 22, 2020 8:10 am
But you still have to generate the 4 bytes of each OAM entry manually, don't you? I believe that if you calculate the sprite positions as ints, you can test the high byte (e.g. spritex & 0xff00) and if that's zero you copy the low byte to OAM (spritex & 0xff), otherwise just drop the sprite.
Yes! I use some prebuilt functions though but should be possible to edit if necessary:)
dougeff wrote:
Sat Aug 22, 2020 8:12 am
You could use this code, oam_meta_spr_clip()

found here...

https://github.com/clbr/neslib/blob/master/display.sinc

It requires you to keep x position as a 16 bit integer, where a high byte of zero means on screen, ff (-1) means off screen to the left, >=1 means off screen to the right.
Nice! As I posted this I found this function(silly me). I still dont quite understand it though. I already use 16 bit for movement since i can have smaller increments more easily. Ill take a deeper look

Thanks everyone!

User avatar
dougeff
Posts: 2735
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Avoid sprite warping

Post by dougeff » Sat Aug 22, 2020 9:58 am

If you mean, 8.8 fixed point (8 pixel, 8 sub-pixel)... as long as you don't need to have the sprite half off the left or right, you could probably send the X value as X>>8. This would pass a zero as the upper byte and the pixel X value as the low byte.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply