vchelaru / FlatRedBall

Cross-platform 2D game engine focused on ultimate productivity built in .NET
http://flatredball.com
MIT License
408 stars 65 forks source link

Discussion - possible animation codegen for platformers #506

Closed vchelaru closed 2 years ago

vchelaru commented 2 years ago

Problem

Currently FRB wizard can create a simple platformer with no code - you just select the platformer type and the wizard will create a game with levels, platforming physics, platforming controls, collision relationships. The user can paint a level in the editor and try it out.

However, the character is a white rectangle. It is missing art. If the user wants to add art to the level, it can be done in Tiled with no code, but adding animation to the player requires code, and it's unfortunately somewhat complex.

The new platform wizard is missing the "wow" factor of having an animated character, and if it had support for automatically animating a platformer character, then users would be that much further along on their project from the beginning.

Solution Discussion

To solve this, the platformer plugin could codegen some animation playing code. The simplest conceptually is to generate animation code depending on which movement type is used. Each movement type could have an animation name that it assigns, and whenever the values are set, the animation changes. Games like Super Mario Bros play animations at different speeds depending on the player's velocity, so some variables are needed to control speed.

Unfortunately, this does not provide enough flexibility to be used in a lot of games, and if the user had to rip that out and start fresh this would be frustrating for all but the most basic of games.

Here are things that games might need in a platformer animation system:

Each set of movement values needs to:

There may be other things that are needed. For instance, the animation may need to support attacks but only when the player performs an attack (like Mario shooting a fireball), or may depend on other input (like Donkey Kong playing a swim animation whenever the player pushes the swim/jump button in water)

Therefore, a good balance is needed between providing useful defaults which will work in many cases, but which are very easy to override.

Animation Layers

This system should definitely use the AnimationLayer system, as that allows additional logic to inject itself inbetween the different layers, or on top of the layers. A layered system allows for adding new logic on top. If the new top layers return animation values, then those will be used. Otherwise, the generated animation layers will be applied.

Will the following separation between what's generated vs custom work?

Generated:

This will create an animation layer which can then be added to an AnimationController.

Supported Through Code Generation

The following would be supported automatically, with no need for custom code (including facing left and right):

The following would require custom code:

vchelaru commented 2 years ago

Fixed

3e34351e1fcd3e529ad74069e8989be17debd669