I am trying to trace the StarWarrior code (the Artemis tutorial). I cannot figure out how these sprites are being drawn. This is the code where the player's ship is initialized:

/// <summary>The initialize player ship.</summary>
private void InitializePlayerShip()
    Entity entity = this.entityWorld.CreateEntity();
    entity.Group = "SHIPS";

    entity.AddComponent(new SpatialFormComponent("PlayerShip"));
    entity.AddComponent(new HealthComponent(30));

    entity.GetComponent<TransformComponent>().X = this.GraphicsDevice.Viewport.Width * 0.5f;
    entity.GetComponent<TransformComponent>().Y = this.GraphicsDevice.Viewport.Height - 50;
    entity.Tag = "PLAYER";

Which line of code actually leads to the ship being drawn? The drawing takes place in PlayerShip.cs. Here is a commented version of the code with what I think is happening:

/// <summary>The initialize player ship.</summary>
private void InitializePlayerShip()
    Entity entity = this.entityWorld.CreateEntity(); //declare and initialize entity
    entity.Group = "SHIPS"; //Unused label

    entity.AddComponentFromPool<TransformComponent>(); //Add the component to store X and Y
    entity.AddComponent(new SpatialFormComponent("PlayerShip")); //Add a component which is just a String (perhaps this has something to do with PlayerShip.cs?)
    entity.AddComponent(new HealthComponent(30)); //Add a health component with 30 hp

    entity.GetComponent<TransformComponent>().X = this.GraphicsDevice.Viewport.Width * 0.5f; //Initialize the TransformComponent's X
    entity.GetComponent<TransformComponent>().Y = this.GraphicsDevice.Viewport.Height - 50; //Initialize the TransformComponent's Y
    entity.Tag = "PLAYER"; //Unused label

So how is the actual sprite being drawn? Because, I am not seeing it. :(

If it is being drawn by entityWorld.Draw() in the Draw() method, then which line(s) of code put it in the world to be drawn? Or what is actually happening in entityWorld.Draw()?

I believe the RenderSystem is the one that is doing the drawing, but I don't get how it is being called.

I am sorry for the uninformed question, but I have made no progress after about 12 hours, and I desperately need some guidance!


Each system in Artemis has a function called process, the process function in the RenderSystem looks like this:

protected void process(Entity e) {
    Spatial spatial = spatials.get(e.getId());
    Transform transform = transformMapper.get(e);

    if (transform.getX() >= 0 && transform.getY() >= 0 && transform.getX() < container.getWidth() && transform.getY() < container.getHeight() && spatial != null) {

This is getting the Spatial component from each entity. The Spatial component defines the sprite to be rendered.

That sprite is then being drawn to screen with the render call you see above. Which looks like this:

public void render(Graphics g) {
    ship.setLocation(transform.getX(), transform.getY());
  • \$\begingroup\$ thanks @Byte56! I am going to study your answer for a few hours, then i will have some follow up questions im sure :) \$\endgroup\$ – Evorlor Mar 14 '14 at 21:11
  • \$\begingroup\$ Sure. I suggest you download the source for the StarWarrior project, and run it in the debugger. Step through it line by line, it's far easier to trace when the debugger does it for you. Also, make sure you read through the tutorial on their page. It gives a nice overview, and should be read before trying out the demos. \$\endgroup\$ – MichaelHouse Mar 14 '14 at 21:15
  • \$\begingroup\$ i wish, but it wont let me put StarWarrior into visual studio. not sure why, but i spent about 3 hours trying before calling it quits. i did read the tutorial. depsite my uninformed questions, i have done a lot of research on this already. but it just is not clicking in my head. (perhaps cuz i cannot actually run StarWarrior) \$\endgroup\$ – Evorlor Mar 14 '14 at 21:16
  • \$\begingroup\$ Visual studio doesn't do Java. You're using the wrong tool for the job. \$\endgroup\$ – MichaelHouse Mar 14 '14 at 21:18
  • \$\begingroup\$ i know this. i am using C#. I am also using a C# version of StarWarrior. (they ported artemis to c#). however, the c# version of starwarrior is made for linux and mac, not windows :-/ hence my trouble opening it in VS \$\endgroup\$ – Evorlor Mar 14 '14 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.