NES animations

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
AlexDempsey123
Posts: 1
Joined: Mon Feb 12, 2018 8:07 am

NES animations

Post by AlexDempsey123 » Mon Feb 12, 2018 8:17 am

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

tepples
Posts: 21746
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NES animations

Post by tepples » Mon Feb 12, 2018 9:18 am

This topic isn't about putting a (more or less usable) program onto a cartridge. Moving from Reproduction to Newbie Help Center.

User avatar
Kasumi
Posts: 1289
Joined: Wed Apr 02, 2008 2:09 pm

Re: NES animations

Post by Kasumi » Mon Feb 12, 2018 10:05 am

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!

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

Re: NES animations

Post by tokumaru » Mon Feb 12, 2018 11:31 am

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.

Post Reply