2
\$\begingroup\$

I'm migrating a 2D game I've been making using only SpriteKit to an ECS architecture using GameplayKit, and I'm still a bit clueless on how to achieve this. I think I got the gist of ECS, but yet, I've got no clue on how to make my game map.

For reference my map is basically a 2D grid and on each coordinate there's a possibility to exist resources, or a player unit, enemy unit, etc. It's basically a build your base, collect resources, upgrade your stuff, survive waves of enemies kind of game.

In my non-ECS implementation I basically have a Map class that's keeping references to SKSpriteNodes, and I basically just have some procedural generation going on to generate my initial resources.

How do I define my map? Should it be an GKEntity? I've got no clue on how exactly to represent it. Any tips that will give me a push will be very welcomed!

\$\endgroup\$
2

1 Answer 1

1
\$\begingroup\$

I see many GameplayKit examples that are more EC than ECS, which can add to confusion as they put a lot of code in entities. GameplayKit supports both approaches.

In an ECS, an entity is an aggregation of components. Components are data objects. Systems is where your logic goes. In the case of your Map, it can be an entity where you add components that make sense for the systems which need to act on it.

For example the Map would have a Renderable component because it is rendered by the Render system. A Position component for storing its x and y locations (and the Render system knows where to render it). The Map might have a Grid component that has data like tileSize, numRows, numCols, etc. That data could be used by a TerrainGenerator system to create the image of the map.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .