Which Components Should I Use

I’ve been through most of the sample code and have been able to create my own game… Im very excited to get started but not sure which approach and components would be best for the concept Im thinking of.

The Game is a traffic sim. Each level is a map with different maps/routes for vehicles to travel to and from. Along the route there would be waypoints/traffic signs which the vehicles need to respond to. This vehicles would also need some randomness/intellgence…i.e. dont hit the car in front of it, decide to go left/right straight all while following a route to their destination.

At first the route and followers examples seemed promising, but I quickly ran into problems implementing logic and switching paths along the route. I am mostly looking for suggestions as to which phaser components would be ideal for this game. Any existing projects or code would also be most welcome. Finally, Im not deadset on using version 3 but I do tend to utilize the most up to date release when possible! Thanks for reading and I looking forward to jumping in!

It’s a bit of a difficult question to answer, and I have only really just started using Phaser and I am not a Javascript programmer by trade, however I have been having success making my game’s GameObjects as sub-classes of Phaser.GameObjects.Container, something like:

(typescript)

export class MyObject extends Phaser.GameObjects.Container {
    private mainSprite: Phaser.GameObjects.Sprite;

    public constructor(scene: Phaser.Scene, x: number, y: number) {
        super(scene, x, y);

        scene.add.existing(this);
        this.setDepth(10);

        this.mainSprite = scene.add.sprite(-122, -3, "sprites", "mummy_fish_00.png");
    }
}

The reason being that Components allow you to compose your game object of many sub-components like sprites and physics objects and allow you to define their functionality in a nice object-oriented manner.

If you want more detail, please let me know.

1 Like