igwgames / nes-starter-kit

A Beginner's Guide and toolkit for NES game creation.
MIT License
221 stars 24 forks source link

Adding Animations into the game. #25

Open haseeb-heaven opened 3 years ago

haseeb-heaven commented 3 years ago

Hi, Can you add tutorial on how to add animations of different sprites where sprites would be. 1.Standard (8x8) size. 2.Extended (8x16) size.

And maintaining sprites flickering limitations also while doing these for multiple sprites in single room. and could you them general so they can be adapted by our external code.

Thanks

potatolain commented 3 years ago

For standard sprites this is actually already available, if it helps. There are some details here: https://cppchriscpp.github.io/nes-starter-kit//guide/section_2/adding_enemies.html#adding-a-new-animation-type

However, I don't really explain what the art needs to look like for the built-in animation types. Can you clarify what you are looking for? I'd be happy to spend some time on this, I just need to make sure I'm doing the right thing.


For extended 8x16 sprites, I have really only tried this very recently, so it is not something I had considered for the guide yet.

This seems like I could add it to the advanced chapters. It's a bit challenging to use as a developer though, so I avoid them unless I really need them. The main challenges are with designing graphics, since you have to lay them out in a specific way that's not clear to look at. Sprite ids also change, so looking an editor like NES Screen Tool can be more confusing.

(Note to self: There was some mention of this in #24 too. I did this in commit cf084d97 in a private project - it's very hacky though, and needs a lot of cleanup.)


For sprite flicker, the library already handles that for you, so I don't really want to devote too much of the guide to it.

To help you out, here's where to look: https://github.com/cppchriscpp/nes-starter-kit/blob/master/source/sprites/map_sprites.c#L48

In short, I switch between ordering the sprites from 0, 1, 2, 3, 4... to ...4, 3, 2, 1, 0 every other frame. The NES will show the first 8 sprites it sees in numeric order, so this works for showing up to 16 sprites on a scanline with flicker.


I hope that all helps - I'm not completely sure I understood your question though, so if there is more, please ask.

haseeb-heaven commented 3 years ago

I am using oam_meta_spr() method to draw sprites in my game with 3 enemies and 2 more collectable items the problem is there are way too many sprites in single room , so i needed to fix it for both 8x8 and 8x16 sprites.

since your guide uses oam_spr() method with sprites Id's it would be easy to handle them but its hard to handle Animations for metasprites since it draws more sprites per frame the Animation is not as expected.

potatolain commented 3 years ago

That makes sense. Unfortunately I have no experience at all using the oam_meta_spr methods though, so right now I'm not super well equipped to write that chapter.

I am probably not going to write this chapter right away, but let's keep this open and see if there is more interest in it. (Or perhaps if someone feels strongly enough to create a PR)