So, we already have the

In the previous tutorial, you learned how to load an existing Spriter animation into your Glue project. But, we did that into a screen. In this tutorial, we will be loading it into an Entity. This works almost exactly the same way as with Screens.

In Glue, choose an existing Entity or add an Entity by right clicking on "Entities" and selecting "Add Entity"

Choose a name, and then click ok

Right click on Files, and choose add file, new file, navigating to the player.scml file from the prior tutorial.

If you are lost, refer to the previous tutorial for how to add an existing file, and do that in this Entity instead.

If you did it right, you should end up with something like this:

Here is where the really cool stuff comes in!

In order to use a spriter animation in an entity, you have to add an object. Glue Assumes if you're adding a file directly to a screen, you want to see it, so it automatically adds it to the managers. This is not so with an Entity, because it's not clear what your intent is for this file. When you add an object from a file, though, Glue assumes that you want it to be tangible, so it clones the object and adds to managers.

That said, here is what you need to do.

Right click on objects, and click Add Object

Select the From File radio button, and select the file in the list:

Click ok.

Now you have an object instance that's tied back to the file, but you have to tell Glue what part of the file to use.

Open the dropdown for SourceName, and choose Player (SpriterObject):

Notice how it gives you two options? Most of the time, you will probably be choosing a SpriterObject instead of the SpriterObjectCollection, because it refers to a single Spriter Entity as defined in the Spriter project. If you had multiple Spriter Entities in the Spriter project, they would all show up here in the dropdown, and you could add the project file once while adding objects for the different entities.

Add the following line to your Entity's CustomInitialize function:

ObjectInstance.StartAnimation("idle");

PRO TIP: if you're following along and using this tutorial as a guide, be sure to use the object instance variable name here as opposed to the object that was created when the file was added. Glue only generates code to add the object instance to managers when adding a Spriter file to an entity, whereas in a screen, the file's associated object itself is just added to managers immediately.

Now add your entity to a screen (Right click and drag the Glue Entity to a Screen)

Your project should now look something like this:

Go ahead and run the game now, and you should see the idle animation again. Now you're ready to add game logic, which in this case is just going to be making him walk.

All that's left is to make him walk now!

Open up your Entity's cs file and paste the following in to the CustomActivity function:

if (!InputManager.Keyboard.KeyDown(Keys.Right) && !InputManager.Keyboard.KeyDown(Keys.Left))
{
    Velocity.X = 0f;
}
if (InputManager.Keyboard.KeyPushed(Keys.Right))
{
	Velocity.X = 200f;
    ObjectInstance.FlipHorizontal = false;
}
if (InputManager.Keyboard.KeyPushed(Keys.Left))
{
	Velocity.X = -200f;
    ObjectInstance.FlipHorizontal = true;
}

if (Velocity.X == 0f && ObjectInstance.CurrentAnimation.Name != "idle")
{
    ObjectInstance.StartAnimation("idle");
}
else if (Velocity.X < 0f && ObjectInstance.CurrentAnimation.Name != "walk")
{
    ObjectInstance.StartAnimation("walk");
                
}
else if (Velocity.X > 0f && ObjectInstance.CurrentAnimation.Name != "walk")
{
    ObjectInstance.StartAnimation("walk");
}

Run the game, and you should now be able to press the right and left arrows and watch him walk. When you let up on both arrows, the idle animation plays.

Click here to download a binary of the tutorial.