It is currently Sat Aug 24, 2019 10:08 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Calculate sprite coordinates on the nametablePosted: Tue Sep 06, 2016 7:07 am

Joined: Tue May 28, 2013 5:49 am
Posts: 1180
Location: Hokkaido, Japan
Let's say I want to draw a 8x8 sprite so that it exactly covers a 8x8 BG tile. Is there an easy way to calculate the X- and Y-coordinates of the sprite if I know the nametable address? The scroll register is 0.

Top

 Post subject: Re: Calculate sprite coordinates on the nametablePosted: Tue Sep 06, 2016 7:34 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21561
Location: NE Indiana, USA (NTSC)
X coordinate: (((address << 3) & 0xF8) - camera_x) % 256
Y coordinate: (((address >> 2) & 0xF8) - (camera_y + 1)) % 240

A simplification is possible if your scroll position is (0, 0), as you mentioned:
X coordinate: (address << 3) & 0xF8
Y coordinate: ((address >> 2) & 0xF8) - 1

Translation of these expressions from C to 6502 assembly code is an exercise for the reader.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Post subject: Re: Calculate sprite coordinates on the nametablePosted: Tue Sep 06, 2016 8:21 am

Joined: Tue May 28, 2013 5:49 am
Posts: 1180
Location: Hokkaido, Japan
Thanks a lot! These formulas works like a charm!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2019 NESdev Competition       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki