[Nez framework] how to get multiple sprites to act as one object?

I want to create a tank (base + turret). Have the turret manipulate on its own but still be part of the tank. This is more like a layered sprite. I can use the Nez sprite component to add the sprites to get the look that I want, but the turret is not an entity so I can’t make it do anything.

Has anyone done this with Nez?

A few trial and errors and I got something working.

Set one entity as the base of the tank
Set one entity as the turret of the tank
Give them both a SimpleMover component to have in common. This component only has one value ‘speed’
Create a MoveSystem that moves all entities that have SimpleMover component

Base and turret will move together.

Give the turret TurretMover component
Create a TurretSystem that rotates the turret (since its the only entity with that component)

1 Like

Here is the initialization code . Could not get it to paste properly so here is an image of it :slight_smile:

1 Like

[solved] found another fantastic way to do this. a property called: enitity.Transform.parent

Set up the base sprite as the parent of the next sprite and next and so on. That way, everytime you move the base sprite all the children will move.

Also, if you can make the children as entities with special components (tag), then you can use specialized systems to act only on that part. This will make the turret turn while the base moves in a different direction.

Nez is fantastic for 2D games. I used Unity ECS for this, although it works, it requires a lot of setup and I wasn’t feeling like I wanted to put so much in a simple 2D game. So, I came back to Monogame and found Nez to do most of the work.

Thanks Prime 31 for a wonderful framework.