It is currently Sat May 26, 2018 10:35 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: NES animations
PostPosted: Mon Feb 12, 2018 8:17 am 
Offline

Joined: Mon Feb 12, 2018 8:07 am
Posts: 1
I’m new to nes game development and was wondering how do you animate a sprite while for example you press a key to move the sprite. Thanks


Top
 Profile  
 
 Post subject: Re: NES animations
PostPosted: Mon Feb 12, 2018 9:18 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20072
Location: NE Indiana, USA (NTSC)
This topic isn't about putting a (more or less usable) program onto a cartridge. Moving from Reproduction to Newbie Help Center.


Top
 Profile  
 
 Post subject: Re: NES animations
PostPosted: Mon Feb 12, 2018 10:05 am 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1145
This question isn't too specific to NES. Like most platforms you would:
Read the state of the buttons once a frame. (On NES, you write a 1, then a 0 to $4016, then read $4016 eight times and store the result, once for each button)

Check the state of right on the d-pad (pressed or non pressed) by reading the location you stored each button above. For every frame it is pressed, add a value to RAM that keeps track of how long the sprite's frame was displayed for.

When that value is greater than say... 5 frames (this value affects how fast the animation plays), add a value to RAM that keeps track of which frame to display, and store zero to the RAM that keeps track of how long the sprite's frame was displayed for. (This frame will then be displayed until the timer reaches 5 again, so every frame will be displayed for the same number of frames.)

When the value for which frame to display is greater than the length of the animation, store zero to that RAM. (To make the animation loop.)

When drawing the sprite, read the value for which frame should be displayed and use it load data for that frame.

Draw that frame to the screen. On NES, this is:

Store the data for the right frame to OAM memory (where sprite data is copied from). Let's say you chose $0200-$02FF for your OAM memory.

Store the high byte where OAM memory is (#$02 using the example above) to $4014 during vblank to display all sprites.

Done!

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
 Post subject: Re: NES animations
PostPosted: Mon Feb 12, 2018 11:31 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10484
Location: Rio de Janeiro - Brazil
On the NES, we often use metasprites for drawing characters and objects. A metasprite is a collection of hardware sprites, arranged together to form a larger image.

To animate characters and objects, you have to change the metasprites over time. The most straightforward way to do this is to have a table in the ROM, listing a sequence of metasprites and for how many frames each one must be displayed.

Each object/character needs to have a pointer to a metasprite definition, and a counter to control when to advance to the next metasprite in the sequence. To start an animation, set the pointer to the initial metasprite and load its frame count. Then, every frame, draw the current metasprite and decrement the counter. Once the counter reaches zero, advance the pointer to the next metasprite and load that one's frame count. Repeat this indefinitely.

A lot of different things can trigger an a new animation, such as controller input (e.g. player presses button to jump), timers (e.g. death animation when the time is up), collisions (e.g. damage animation when hit by projectile), and so on.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group