Jump to content
loodakrawa

SpriterDotNet - An implementation for all C# frameworks

Recommended Posts

Hi Loodakrawa,

Been playing around with this for the last couple of hours and it seems like a really useful plugin, so thank you!

I'm wondering if there's any support for loading the animations directly into Unity Animations, and in turn, an Animator? I'm looking to take advantage of the Animation Events within them and blend trees.

Any insight is greatly appreciated,

Thanks

Share this post


Link to post
Share on other sites
1 hour ago, Matt901 said:

Hi Loodakrawa,

Been playing around with this for the last couple of hours and it seems like a really useful plugin, so thank you!

I'm wondering if there's any support for loading the animations directly into Unity Animations, and in turn, an Animator? I'm looking to take advantage of the Animation Events within them and blend trees.

Any insight is greatly appreciated,

Thanks

Hi,

I'm glad you find it useful.

Due to the nature of SpriterDotNet it's not really possible to convert everything directly into Unity Animations but the plan is to make it more integrated with Unity. For the time being, you might want to take a look at Dengar's plugin. As for animation events, Spriter supports them natively so that might give you a decent replacement for Unity animation events. And blend trees are one of the planned features.

Cheers

Share this post


Link to post
Share on other sites

Hey Loodakrawa,

When I spawn in enemies that use character maps, the basic enemy appears for a moment before the character map gets assigned. Do you know of a way to set this character map before the visuals are displayed? 

I am setting the character map in the Awake() method for these game objects yet they still appear for a frame before popping to the desired character map.

Thanks,

James

 

Update: I realized after my post that the sprites are not actually swapped for a character map until SpriterAnimator.Step() is called to animate the entity. I simply added "spriterAnimator.Step(0);" after my "spriterAnimator.PushCharMap()" call and it appears to be working great. 

Share this post


Link to post
Share on other sites
On 16/05/2016 at 5:39 AM, Thrasher said:

Hey Loodakrawa,

When I spawn in enemies that use character maps, the basic enemy appears for a moment before the character map gets assigned. Do you know of a way to set this character map before the visuals are displayed? 

I am setting the character map in the Awake() method for these game objects yet they still appear for a frame before popping to the desired character map.

Thanks,

James

 

Update: I realized after my post that the sprites are not actually swapped for a character map until SpriterAnimator.Step() is called to animate the entity. I simply added "spriterAnimator.Step(0);" after my "spriterAnimator.PushCharMap()" call and it appears to be working great. 

Yes - it's just a timing issue. Calling Step(0) is a good solution to make it independent of the order of the init methods - I'm also doing that often in my own projects.

Share this post


Link to post
Share on other sites

Does SpriterDotNet works with multiples Spriter Projects imported to Unity?

I create two different spriter projects and made one entity in each one.

Both prefabs were created normally. I also added both to the scene and both animations works.

The problem is with the Animator property of the SpriterDoNetBehavior.

 

Scenario:

1. I imported the GreyGuy example to unity. Created a Script for the player to change its animation to hit_0 when an object (like a bullet) would collide with him.

Works perfectly.

2. I created a Spriter project and made a Bat entity. I would use it as the bullet for the test 1. I imported the project to unity and added the Bat to the scene. When the bat collided with the GreyGuy, an Exception appear saying that the animation name I used to play in the GreyGuy's animator was not found.

After some tests I realized that both GreyGuy and Bat prefabs were sharing the Bat's Animator.

 

Does I need to do something for it to work?

I uploaded the full unity project to onedrive: https://1drv.ms/u/s!AmhLdtS8gKjrlrpG9w4jIbN7H_D0bg

 

Thiago

Thanks

Share this post


Link to post
Share on other sites
3 hours ago, Thiago Romam said:

Does SpriterDotNet works with multiples Spriter Projects imported to Unity?

I create two different spriter projects and made one entity in each one.

Both prefabs were created normally. I also added both to the scene and both animations works.

The problem is with the Animator property of the SpriterDoNetBehavior.

 

Scenario:

1. I imported the GreyGuy example to unity. Created a Script for the player to change its animation to hit_0 when an object (like a bullet) would collide with him.

Works perfectly.

2. I created a Spriter project and made a Bat entity. I would use it as the bullet for the test 1. I imported the project to unity and added the Bat to the scene. When the bat collided with the GreyGuy, an Exception appear saying that the animation name I used to play in the GreyGuy's animator was not found.

After some tests I realized that both GreyGuy and Bat prefabs were sharing the Bat's Animator.

 

Does I need to do something for it to work?

I uploaded the full unity project to onedrive: https://1drv.ms/u/s!AmhLdtS8gKjrlrpG9w4jIbN7H_D0bg

 

Thiago

Thanks

It definitely should work with multiple spriter entities. I won't be near my machine with Unity installation for a couple of days to check the project. But, from your description it seems you're trying to play "hit_0" which exists on GreyGuy but not on the bat. Did you perhaps add the PlayerController to the Bat game object?

Share this post


Link to post
Share on other sites
3 hours ago, Thiago Romam said:

...

Just realised what the problem is. You're getting the SdnBehaviour with FindObjectOfType which (as per documentation) "Returns the first active loaded object of Type type." That means it probably finds the one on the Bat and that's why it blows up.
https://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html

What you want is: https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

Share this post


Link to post
Share on other sites
15 hours ago, loodakrawa said:

Just realised what the problem is. You're getting the SdnBehaviour with FindObjectOfType which (as per documentation) "Returns the first active loaded object of Type type." That means it probably finds the one on the Bat and that's why it blows up.
https://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html

What you want is: https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

I didn't saw that. Usually I use GetComponent method for getting scripts in object, but I copied it this way from the SpriterDotNet.Examples.

It works now

Thanks for your help.

Share this post


Link to post
Share on other sites

How do I define trigger collision for Unity?

I set the "Is Trigger" flag for a BoxCollider2D after I imported an object. When I changed the Spriter Project, the entity is reimported and the "Is Trigger" flag loses it's value.

Is there a different way to validate collisions when using SpriterDotNet?

Share this post


Link to post
Share on other sites
On 16/07/2016 at 8:31 AM, Thiago Romam said:

How do I define trigger collision for Unity?

I set the "Is Trigger" flag for a BoxCollider2D after I imported an object. When I changed the Spriter Project, the entity is reimported and the "Is Trigger" flag loses it's value.

Is there a different way to validate collisions when using SpriterDotNet?

Hey, you can customise the import process (like setting the Is Trigger flag on colliders) via the EntityImported event. Take a look at the example.

Share this post


Link to post
Share on other sites

Hello,

I have just updated your lib to the latest (because I wanted the shared assets) from an older one (4+ months) and nearly everything is working perfect.  I have noticed that the attack animations on the goblin and girl hero are jerking and don't seem as smooth as they did with the previous version of your lib.  Have you experienced this ?

Any help is very much appreciated.

Thanks, DSE.

Share this post


Link to post
Share on other sites
5 hours ago, DSE said:

Hello,

I have just updated your lib to the latest (because I wanted the shared assets) from an older one (4+ months) and nearly everything is working perfect.  I have noticed that the attack animations on the goblin and girl hero are jerking and don't seem as smooth as they did with the previous version of your lib.  Have you experienced this ?

Any help is very much appreciated.

Thanks, DSE.

Hi,

Definitely haven't experienced it - newer versions should be faster, not slower :-D
Does it happen with any other animations? Also, are you using Unity or something else?

Share this post


Link to post
Share on other sites

Hello, thanks for the reply !

sorry ignore me.  I have checked the problem animations in Spriter and its the same.  Can I ask, was your older library tweening to smooth out animations which you have now disabled / removed in the latest version ?

Thanks again.

Share this post


Link to post
Share on other sites
5 hours ago, DSE said:

Hello, thanks for the reply !

sorry ignore me.  I have checked the problem animations in Spriter and its the same.  Can I ask, was your older library tweening to smooth out animations which you have now disabled / removed in the latest version ?

Thanks again.

Now that I think of it - I added caching of frame data. Relevant documentation: https://github.com/loodakrawa/SpriterDotNet#providers
 

The default implementation uses the SnapshotFrameDataProvider which means that instead of calculating the transforms for every frame, this pre-calculates the transforms for the animation with the given interval and uses the closest value when needed. The default interval is 20ms and it should result in a smooth animation but try lowering the value or using the implementation that calculates everything every frame.

Let me know if you have any more questions and your results - any feedback helps improve the library.

Cheers

Share this post


Link to post
Share on other sites
5 hours ago, DSE said:

Hello, thanks for the reply !

sorry ignore me.  I have checked the problem animations in Spriter and its the same.  Can I ask, was your older library tweening to smooth out animations which you have now disabled / removed in the latest version ?

Thanks again.

And now I read this properly - no, my lib never used any additional smoothing. The goal is to have everything look as it looks in Spriter. That being said, everything in Spriter is being interpolated so technically everything should be smooth all the time.

Share this post


Link to post
Share on other sites

Hi everyone,  Keep in mind, some animations are set up to use "instant" keyframes (no tweening interpolation whatsoever), so those can never be silky smooth no matter what code is playing them back. Are you comparing the animation while playing back in Spriter with how they look once in Unity and they are less smooth?

-Mike at BrashMonkey

Share this post


Link to post
Share on other sites

Hi! Thanks for this amazing project, it is really usefull!

I'm using it on Unity 5.5.0b6 and when I add GreyGuy to my project, the player asset doesn't have the references of the sprites and unity set my images as Textuye Type=Default instead of Sprite 2D.

I don't know what i'm doing wrong.

EDIT: I fixed it by selecting the sprites manually on the player.asset. Is there a way to select them manually?

asset.PNGdefault_texture_type.PNG

 

Share this post


Link to post
Share on other sites
On 06/10/2016 at 8:18 PM, Narref said:

Hi! Thanks for this amazing project, it is really usefull!

I'm using it on Unity 5.5.0b6 and when I add GreyGuy to my project, the player asset doesn't have the references of the sprites and unity set my images as Textuye Type=Default instead of Sprite 2D.

I don't know what i'm doing wrong.

EDIT: I fixed it by selecting the sprites manually on the player.asset. Is there a way to select them manually?

 

You probably created the project as 3D instead of 2D so Unity imports images as something other that Sprite. So either create this as a 2D project or change the default import type for images (I don't know if this is actually possible).

Share this post


Link to post
Share on other sites
5 hours ago, loodakrawa said:

You probably created the project as 3D instead of 2D so Unity imports images as something other that Sprite. So either create this as a 2D project or change the default import type for images (I don't know if this is actually possible).

Awesome! I tested it on an old project and I didn't know it was created as 3D.

Thanks for your answer, its working perfect now!!

Share this post


Link to post
Share on other sites

Hello everyone! :)

I'm a real beginner with Spriter (and with animation in general), I discovered it some days ago, but I would like to use it for a MonoGame project on Android and I have some newbie question.

- Is it possible with Spriter to combine multiple animations? Let's say that we have a character with a "walk" animation and an "eyes blink" animation, is it possible to play both simultaneously? As a matter of fact, I would like to play the "eyes blink" animation independently, no matter what is the animation that is currently playing.

- Is it possible to get the world position of a part of an animation? Let's say that we have a character waving arms, is it possible to get the position of the end of the left arm for example?

- Is it possible to attach bouding boxes to every parts of the sprite so that the transformations (translation, rotation and scale) applied to the sprite are also applied to the bounding boxes?

I'm sorry if the questions are really dumb, but I need to know if these 3 points can be achieved with Spriter and the MonoGame extension.

Thanks in advance :)

 

Share this post


Link to post
Share on other sites
13 hours ago, Noxalus said:

Hello everyone! :)

I'm a real beginner with Spriter (and with animation in general), I discovered it some days ago, but I would like to use it for a MonoGame project on Android and I have some newbie question.

- Is it possible with Spriter to combine multiple animations? Let's say that we have a character with a "walk" animation and an "eyes blink" animation, is it possible to play both simultaneously? As a matter of fact, I would like to play the "eyes blink" animation independently, no matter what is the animation that is currently playing.

- Is it possible to get the world position of a part of an animation? Let's say that we have a character waving arms, is it possible to get the position of the end of the left arm for example?

- Is it possible to attach bouding boxes to every parts of the sprite so that the transformations (translation, rotation and scale) applied to the sprite are also applied to the bounding boxes?

I'm sorry if the questions are really dumb, but I need to know if these 3 points can be achieved with Spriter and the MonoGame extension.

Thanks in advance :)

 

Hi!

I'm also using it with MonoGame and Android so that means this mode is always actively updated :-D

- It is possible to combine multiple animations (2 atm). Just read the docs (relevant section)

- You can achieve the desired behaviour by using "Action Points". Also, take a look at the MonoGame example project - it is just drawing the points but it can serve as a good example.

- I don't see why not. All the transforms do get applied to bounding boxes. Also take a look at the example project - same thing.

Cheers

 

Share this post


Link to post
Share on other sites

Hi, I've been developing a small video game in MonoGame and I'm working on using the MonoGame plugin but I'm caught up on a few parts. Steps 2 and 3 are super easy but when I reach step 4 I get confused. Step 4 states: "Instantiate a DefaultProviderFactory". As this is a generic class I am not quite sure which types should be used for my Spriter animations and what to put for TSound if I have no sound with my sprite. Also, I get even more confused when I reach steps 5. Step 5 states: "Load the required TSprites and TSounds based on the FolderId/FileId from the Spriter instance and register them with the DefaultProviderFactory". I am really lost on what FolderId and FileId are and how to properly use them. I would really appreciate it if someone could point me in the right direction or maybe even teach me a little bit about this plugin.Thank you.

Share this post


Link to post
Share on other sites
5 hours ago, dcaudill724 said:

Hi, I've been developing a small video game in MonoGame and I'm working on using the MonoGame plugin but I'm caught up on a few parts. Steps 2 and 3 are super easy but when I reach step 4 I get confused. Step 4 states: "Instantiate a DefaultProviderFactory". As this is a generic class I am not quite sure which types should be used for my Spriter animations and what to put for TSound if I have no sound with my sprite. Also, I get even more confused when I reach steps 5. Step 5 states: "Load the required TSprites and TSounds based on the FolderId/FileId from the Spriter instance and register them with the DefaultProviderFactory". I am really lost on what FolderId and FileId are and how to properly use them. I would really appreciate it if someone could point me in the right direction or maybe even teach me a little bit about this plugin.Thank you.

Hi,

I'm glad to hear there's more love for MonoGame out there :-D

I'll update the MonoGame specific documentation soon since I added quite a few helpers and the documentation you're referring is the generic one (since the lib can be used with any framework).

The easiest way to make it work for MonoGame is:

  1. Build the SpriterDotNet.MonoGame.Importer project
  2. Add a reference to the built .dll in MonoGame's content file for your game - something like this
  3. Instantiate a DefaultProviderFactory<Sprite, SoundEffect>
  4. Instantiate a SpriterContentLoader
  5. invoke the fill method of the SpriterContentLoader passing the factory from step 3

You can see all this in action in the example project, or in this class to be more specific.

Alternatively, if you want the bare bones version (not using any caching, texture sharing, etc):

  1. Read the .scml data into a string
  2. Get a Spriter instance with SpriterReader.Default.Read
  3. Instantiate a MonoGameAnimator passing the Entity you want animated (from the Spriter in step 2) + null for factory
  4. Iterate over all SpriterFolder/SpriterFile in Spriter and load them as Texture2D/SoundEffect MonoGame types
    * wrap all Texture2D in a Sprite instance (like so)
  5. Register all data from step 4. with SpriteProvider/SoundProvider properties on the animator from step 3
  6. Call Update and Draw on the animator

There you go, hopefully that can get you started. All of this might sound a bit overly complicated but it comes with a bunch of optimisations out of the box and allows you to customise almost every detail. You can find more about that here.

Let me know if you managed to make it work or if any steps were not clear (so I can add this to the docs).

Cheers

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...