Page 1 of 1

NES Screen coordinates for Sprites

Posted: Wed Apr 06, 2011 3:41 pm
by Grumskiz
Hello,
I've been looking around on this board for quite a while now, but I didn't really write anything yet.
Well, to get started:
I'm working on a small game similar to Arkanoid or Breakout that will include some puzzle elements.
It is actually in a VERY early stage of development and there is not much to show yet...

But for my question there is probably no real need for that anyways.

I was looking for a table with some information about the screen positions of sprites.
I know that $FE and $FF are off-screen and how to get sprites in the middle, but sometimes I want to do more complicated positions and I end up trying to guess where to put them and then moving them in little steps and looking at the results in an emulator until they're in the right position.
Well, it's a huge waste of time...
Maybe it's just me and I don't see yet how the positions are actually arranged and why $FE and $FF are off-screen.
So, I was looking for a table or graph for the screen positions, maybe with some explanations on it, but I couldn't find anything on the wiki or here on the board and Google wasn't that helpful either.(Maybe, I didn't have the right search words...I'm really not sure how one would describe such a graph in English. I'm German btw. It says Canada on my profile, because right now I'm living here as an international student)

To get back to my problem and (finally) to my question:
Is there such a graph somewhere out there and if there is, where can I find it?

Thanks,
Grums

Re: NES Screen coordinates for Sprites

Posted: Wed Apr 06, 2011 4:11 pm
by cpow
Grumskiz wrote: But for my question there is probably no real need for that anyways.
People on this board love seeing early-stage stuff, regardless.

Regarding the sprite position...

For horizontal, there's 256 pixels, and the sprite-width is 8 pixels, so to put a sprite at dead-center I would think:

(256*(1/2))-(8/2) or 124 decimal would do the trick. The 8/2 factor is just to get to the middle of the sprite, the other factor is to get to the middle of the screen. To get to half-way-to-center-from-left:

(256*(1/4))-(8/2) or 60.

To get to half-way-to-right-from-center:

(256*(3/4))-(8/2) or 188.

Hopefully you sense a pattern.

Vertically it's similar except there's only 240 pixels to work with. F0-FF is "offscreen", not just FE and FF as you state. However, vertically there's another factor that is the sprite height, which is either 8 or 16 pixels.

To get to half-way down for an 8x8 sprite:

(240*(1/2))-(8/2) or 116.

To get to half-way down for an 8x16 sprite:

(240*(1/2))-(16/2) or 112.

Hopefully here too you sense a pattern.

To get to 5/7ths of the way across by 2/3rds of the way down for 8x8 sprite:

across: (256*(5/7))-(8/2) or "roughly" 179.
down: (240*(2/3))-(8/2) or 156.

That's just what I'd do...but experimentation with an emulator, while tedious, is probably going to have to happen anyway.

Re: NES Screen coordinates for Sprites

Posted: Wed Apr 06, 2011 4:30 pm
by Grumskiz
cpow wrote: People on this board love seeing early-stage stuff, regardless.
I'm sure, they do :3
There really just isn't much to see yet...
cpow wrote: For horizontal, there's 256 pixels, and the sprite-width is 8 pixels,(...)
Vertically it's similar except there's only 240 pixels to work with. F0-FF is "offscreen", not just FE and FF as you state.
That makes sense to me, compared to the screen size that the NES produces.
cpow wrote: (256*(1/2))-(8/2) or 124 decimal would do the trick. The 8/2 factor is just to get to the middle of the sprite, the other factor is to get to the middle of the screen. To get to half-way-to-center-from-left:

(256*(1/4))-(8/2) or 60.

To get to half-way-to-right-from-center:

(256*(3/4))-(8/2) or 188.

Hopefully you sense a pattern.
Yes, I do see the pattern now! Thanks a lot for this formula.
I just got confused by using Hex for programming all the time, while I always thought of the screen size in decimal numbers.(256x240 instead of $FF x $F0)
Now it is all clearer to me.
cpow wrote: However, vertically there's another factor that is the sprite height, which is either 8 or 16 pixels.
The latter would be the case if I used 8x16 Sprites, right?
Again now it's a lot clearer to me here.

Thanks for the fast answer and the good explanation!

Posted: Wed Apr 06, 2011 5:58 pm
by Dwedit
If you don't like hex, then don't use it.

Posted: Wed Apr 06, 2011 6:16 pm
by cartlemmy
Dwedit wrote:If you don't like hex, then don't use it.
Yep, I have a bad habit of intermingling hex, dec, and binary. Well, sometimes it makes sense... But sometimes there is no reason for it.

Posted: Wed Apr 06, 2011 6:52 pm
by Grumskiz
Dwedit wrote:If you don't like hex, then don't use it.
Oh no, you got me wrong there ^^'
It was just about the screen resolution.
I'm used to have screen resolutions in a form somewhat like this: 1280x720
Notice the decimal numbers and the "x" instead of an "*".
That's the form I've seen since...well...as far as I can remember ^^'
I just never thought of converting that to Hex, because I'm used to see screen resolutions given in that form for forever, but as soon as I did convert it, it all made a lot more sense to me.

I'm used to using Hex for a while now. I learned it back when I made (crappy) SMW ROM hacks. I don't have a problem with it ;3

Posted: Wed Apr 06, 2011 7:16 pm
by MottZilla
I think the proper way, or one of them, to put sprites off-screen is to set the Y value to $F0. Alternatively you could just write $F0 to all of Sprite RAM. Atleast I seem to recall alot of games doing this. I guess that $F0 and up would all hide it. You don't want to put them horizontally off screen and not also vertically since the sprites would still count torward the 8 sprite scanline limit.

Posted: Wed Apr 06, 2011 11:04 pm
by Kasumi
Grumskiz wrote: I just never thought of converting that to Hex, because I'm used to see screen resolutions given in that form for forever, but as soon as I did convert it, it all made a lot more sense to me.
His point is, you don't NEED to convert that to hex, not that you should stop NES programming, if that's the impression you got.

lda #255 is valid in most 6502 assemblers.

lda #$FF
and
lda #255 are equivalent.
lda #%11111111 for binary. They all become exactly the same thing. $7E is not a different number than 126.
I use binary for the bitwise operators, hex for most other things, and the straight number for speed values. You can use whichever one is easiest for you at any given time.
lda #241 is vertically off screen, because the screen resolution is only 240. No conversion necessary.

I realize you now know why those hex values are off screen, but hopefully this post taught you something else.

Posted: Thu Apr 07, 2011 4:25 am
by Grumskiz
Kasumi wrote:
Grumskiz wrote: I just never thought of converting that to Hex, because I'm used to see screen resolutions given in that form for forever, but as soon as I did convert it, it all made a lot more sense to me.
His point is, you don't NEED to convert that to hex, not that you should stop NES programming, if that's the impression you got.

lda #255 is valid in most 6502 assemblers.

lda #$FF
and
lda #255 are equivalent.
lda #%11111111 for binary. They all become exactly the same thing. $7E is not a different number than 126.
I use binary for the bitwise operators, hex for most other things, and the straight number for speed values. You can use whichever one is easiest for you at any given time.
lda #241 is vertically off screen, because the screen resolution is only 240. No conversion necessary.

I realize you now know why those hex values are off screen, but hopefully this post taught you something else.
I'm aware of that and I know I can use decimal numbers for 6502 Assembly, because, as you said, they can all represent the same numbers.
I think it's just a little misunderstanding going on.
I already use hex, binary and decimal numbers together in a way that is similar to yours! I also find Binary a lot clearer for bitwise operators than anything else. For most other things I use Hex, sometimes also decimal numbers that I usually convert to Hex at some point. I find it easier to see a connection between the program I write and the ROM that I run in FCEUX while I'm looking at the HEX Editor(to see the RAM Addresses while the game is running), if I use Hex. That way, for me, I it's easier to recognize and find things.

I think I wasn't really clear before...
I just didn't know that sprites are off screen on vertical positions bigger than 240 or $F0.
I thought it's only $FE and $FF, because that's what I read in the Nerdy Nights tutorials, I think.
I just never saw the connection between these two numbers and the screen resolution of which I thought it was absolutly independent from the Sprite positions. I saw it as something that is only based on the size of the nametables.

Posted: Thu Apr 07, 2011 5:42 am
by thefox
Grumskiz wrote:I just didn't know that sprites are off screen on vertical positions bigger than 240 or $F0.
I thought it's only $FE and $FF, because that's what I read in the Nerdy Nights tutorials, I think.
Some nitpicking: 239 ($EF) is also off screen, because the sprites are shifted down one scanline (that is, a sprite with y coord 0 will appear starting from the 2nd scanline).