-
-
Notifications
You must be signed in to change notification settings - Fork 559
Game Architecture and Workflow (FXGL 11)
We keep the JavaFX convention to append App
after the class containing main()
.
So if your game name is "MyGame" then the class that has main()
should be called MyGameApp
.
Most games will have different types of entities, e.g. player, bullet, enemy, etc. The type is likely to be an enum, so it might look like this:
public enum EntityType {
PLAYER, BULLET, ENEMY
}
Instead of EntityType
you can also put MyGameNameType
depending on what suits you better.
For example, for a Space Invaders clone I used SpaceInvadersType
name for the enum.
It is recommended that you have a single class responsible for creating entities per collective types in your game. For example, you might create a class for creating enemies only, then a class to create powerups only, and maybe another class for creating specifically background and decor entities. Such a class for creating entities is called an entity factory.
public class MyBlockFactory implements EntityFactory {
@Spawns("block")
public Entity newBlock(SpawnData data) {
return FXGL.entityBuilder(data)
.viewFromNode(new Rectangle(70, 70))
.build();
}
}
You can add a factory to the game world as follows: getGameWorld().addEntityFactory(new MyBlockFactory());
.
Then you can spawn an entity, using getGameWorld().spawn("block");
, which in turn calls your factory method annotated with @Spawns("block")
.
Building Levels - in short, use .txt for very simple levels, use Tiled editor for anything else.