Jump to content
lucid

SpriterPlusPlus - a C++ Spriter implementation

Recommended Posts

Hi,

i downloaded the sourcecode from github and I wanted to try the example, but got a compilation error. The problem is, that the method newImageFile in examplefilefactory.h does not override the method in filefactory.h properly. Obviously the code of the "core-engine" has been changed, but the example hasn't been updated. I tried to fix it myself, but it didn't work out, because I've never used this code before. I just wanted to get used to it and how it is working.

Can someone fix the example? Would be very nice :)

Greetings

superolelli

Share this post


Link to post
Share on other sites
6 hours ago, superolelli said:

Hi,

i downloaded the sourcecode from github and I wanted to try the example, but got a compilation error. The problem is, that the method newImageFile in examplefilefactory.h does not override the method in filefactory.h properly. Obviously the code of the "core-engine" has been changed, but the example hasn't been updated. I tried to fix it myself, but it didn't work out, because I've never used this code before. I just wanted to get used to it and how it is working.

Can someone fix the example? Would be very nice :)

Greetings

superolelli

I'm updating the examples right now. I've already done a pull request with the fix and an scon loader.

I'll also add atlas data to the example.

Share this post


Link to post
Share on other sites

Added a pull request to update the example.

I've also added a project with an atlas for each folder as an example that it's working.

It's also giving a lot better fps. With only one atlas it'll probably be even better.

Share this post


Link to post
Share on other sites

Hello, I'm making a game with 3D environments and 2.5D characters, the animations are amazingly smooth, however I had a bit of a problem while integrating SpriterPlusPlus. As far as I understand, the library expects to be used in a 2D game, so it treats 1 unit as 1 pixel. This is confirmed by the fact that Spriter and the examples have lengths around 200 units IIRC, which makes sense in a 2D game. However, my game is 3D, where 1 unit equals 1 meter (which is more intuitive to deal with). I tried scaling down the GreyGuy example to around 2 units in size, however Spriter was bugging out at me, I guess it wasn't meant to be edited at such small scales.

Anyway, after saving the SCML file and reading it in my game engine, SpriterPlusPlus behaved in peculariar ways. I don't know if the fault is in my code (can't find) or there're some assumptions in SpriterPlusPlus or Spriter which I did not respect. Basically, if I export the file at 200 units, and tell SpriterPlusPlus to scale it down by ~0.02 (setScale(..) is the API? I did the integration quite some time ago now) to convert from the 2D units to 3D units, I get quite messed up rendering. A character's pieces are a bit detached from each other, and they become increasingly detached the more I scale down by using setScale(..). If I set the scale to 1.0f, then everything renders super nicely (awesome library, I love you), but it's quite buggy if I use setScale(..).

It's as if the library casts floats to int's somewhere (or floors), which is not noticeable with 2D units (pixel scale) but becomes noticeable if your skeleton is around 1 unit in size (floor'ing/casting to int makes the pieces mislocated by 1 meter instead of 1 pixel).

Anyway, I solved the problem by simply telling SpriterPlusPlus to render at 100% scale (200 units or so), and then I scale it down in OpenGL myself. So I'd like to have a confirmtation, if SpriterPlusPlus assumes the skeletons to be in the >100-200 unit range and therefore does not care about "subpixel" rendering (below 1), or there's a silly bug on my side. Everything works well now, but it's something which has been bugging me for a while.

Share this post


Link to post
Share on other sites

@KGeist I tried saving the example project (the one included in the SpriterPlusPlus example), and resaved it in Spriter to 10x the original size.  Then changed main.cpp to scale each instance to 0.02,0.02 instead of random, and it worked as expected:

02sized.JPG

 

Are those the correct steps to reproduce the error you're talking about?

Share this post


Link to post
Share on other sites
27 minutes ago, lucid said:

@KGeist I tried saving the example project (the one included in the SpriterPlusPlus example), and resaved it in Spriter to 10x the original size.  Then changed main.cpp to scale each instance to 0.02,0.02 instead of random, and it worked as expected:

02sized.JPG

 

Are those the correct steps to reproduce the error you're talking about?

Sounds OK. It must be a bug somewhere in my code, then (quite expected). I tested my wrapper with a square (rotating/scaling around random pivots) and it seemed OK, but it failed with the data passed by SpriterPlusPlus. Perhaps I misunderstood some API (especially considering pivots, such as, is scale applied according to the pivot or the actual center etc. - it's not obvious from the examples because they use interfaces of a third-party lib I'm not familiar with, perhaps it's where the errors stems from).

Anyway, thanks for the confirmation that it's not your code which is to blame, perhaps a wrong order of matrix multiplications somewhere. Will have a look at my code again... (although it already works OK as it is)

On an unrelated note, one minor complaint is that the interface is quite cumbersome; can't we have an option to iterate over all the pieces in one loop in Z-order (a list of infos describing the position + the angle around center + scale around center + texture path; can't we omit the pivot thing altogether too?), instead of scattering it around in subclasses (like ImageFile). Or maybe I overlooked?

Edited by KGeist

Share this post


Link to post
Share on other sites

If you want an example using Allegro 5(allegro-5.0.10-msvc-11.0), I got bored and wrote one copying your structure you wrote for the SFML(though I've never touched SFML).

May have not done it perfectly. But it works and compiles and looks practically similar. I didn't test Atlas and bounding box drawing.

I haven't used Github alot but do you want me to fork your project and add a directory called allegro-example for you?

Also good work on it all. Works nicely.

 

Share this post


Link to post
Share on other sites

hey guys,

I found the sub entities have problems that

when a spriter object load a scml file which has sub entites,it can not works in clickteam fusion.

Frame can not run.

(I mean this function

I have tried the four ways in Sample file. QQ图片20170111174354.png

Dont know whether this problem will be solved.

sorry for my bad english and love your awesome works.:-D

Share this post


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

hey guys,

I found the sub entities have problems that

when a spriter object load a scml file which has sub entites,it can not works in clickteam fusion.

Frame can not run.

(I mean this function

I have tried the four ways in Sample file. QQ图片20170111174354.png

Dont know whether this problem will be solved.

sorry for my bad english and love your awesome works.:-D

I think you should be reporting this to conceptgame who created the Spriter plugin for Fusion. This thread is for the C++ implementation.

http://community.clickteam.com/threads/91759-Beta-Spriter-Object-Extension

 

Share this post


Link to post
Share on other sites

Related to the issue of callofAS, is it now possible to change current entity on the fly with void EntityInstance::setCurrentEntity(int newEntityId)?

Or is the only way to delete and recreate from top API?

For example, instead of this:

SpriterEngine::EntityInstance * inst = scmlModel->getNewEntityInstance(0);

delete inst;

inst = scmlModel->getNewEntityInstance(1);

just this:

SpriterEngine::EntityInstance * inst = scmlModel->getNewEntityInstance(0);

inst->setCurrentEntity(1);

Share this post


Link to post
Share on other sites

@conceptgame Yes. You can add an additional entity to an EntityInstance in two ways.
First, you can use 

entityInstance->appendEntity(&scmlModel, "entityName");

entityInstance->setCurrentEntity("entityName"); // or use the index as you did in your example.




You can also do it in one step:

entityInstance->setCurrentEntity("entityName","initialAnimationName",&scmlModel);



The second method will append the entity before setting it to the current.  Note that neither method checks whether or not you already have this entity appended.  

Share this post


Link to post
Share on other sites
On 3/1/2017 at 5:48 PM, maxfish said:

Hi,

In case somebody is still interested in an SDL2 implementation, here is my attempt at it: https://github.com/maxfish/SpriterPlusPlus_SDL2

The most important thing still missing is a working support for sprite atlas, the rest works fine.

I hope it might help someone.

Awesome. Thanks for contributing to the communities arsenal of Spriter implementations. :)

Share this post


Link to post
Share on other sites

Hi,

Can I get access to transformations of all sprites after EntityInstance->setTimeElapsed() was called?

The problem is I have my own hierarchy of sprites, and I don't want to draw them from ImageFile::renderSprite(). I tried to capture transformation there and use it later. This fails in case when two sprites use one image. Because there is no sprite identification (?), only image, I can't tell which specific sprite is rendered and second transformation is overwritten by first.

How can I solve this?

Share this post


Link to post
Share on other sites

Hi,

is it possible to play two animations at the same time?
Imagine a character, which can e.g. walk and shoot. Now I want, that this character can walk and shoot at the same time.
If the walking animation doesn't effect bones used by the shooting animation that should be possible, shouldn't it?

Is there a way to achieve this?

Share this post


Link to post
Share on other sites

(solved) After some investigation, I used EntityInstance::getZOrder() to get ObjectInterfaceVector

Anyway, have you tested loading scenes with Settings::reverseAngleOnLoad == false? In such case every spin must be inverted, otherwise sprites spin like crazy ;) This should be done in SpriterDocumentLoader.

 

Share this post


Link to post
Share on other sites
On 3/13/2017 at 3:07 PM, mildanach said:

(solved) After some investigation, I used EntityInstance::getZOrder() to get ObjectInterfaceVector

Anyway, have you tested loading scenes with Settings::reverseAngleOnLoad == false? In such case every spin must be inverted, otherwise sprites spin like crazy ;) This should be done in SpriterDocumentLoader.

 

Glad you got it worked out.  And yes, the reverseAngleOnLoad is for engines that use clockwise angles instead of counter-clockwise.

On 3/11/2017 at 7:48 AM, superolelli said:

Hi,

is it possible to play two animations at the same time?
Imagine a character, which can e.g. walk and shoot. Now I want, that this character can walk and shoot at the same time.
If the walking animation doesn't effect bones used by the shooting animation that should be possible, shouldn't it?

Is there a way to achieve this?

The only way to do it now is using sub-entities.

Share this post


Link to post
Share on other sites

Hi,
I think I've got the same problem that Breush had earlier.
I tried to retrieve the position of a point but I always get 0.

I did it this way:

SpriterEngine::UniversalObjectInterface *pt = body->getObjectInstance("arm_point");
pt->getPosition().x;

Do you know, what the problem could be?

And here's another thing:
I made an animation consisting of two subentities. Now I want to render them seperately. I tried it this way, but my program crashed.

 

dwarf->setCurrentAnimation("walk");
dwarf->setTimeElapsed(timeElapsed);

SpriterEngine::UniversalObjectInterface *body = dwarf->getObjectInstance("body");
body->render();
delete(body);

SpriterEngine::UniversalObjectInterface *arm = dwarf->getObjectInstance("arm");
arm->render();
delete(arm);

"dwarf" is the entityInstance. Any idea, how i can get this working?

Greetings

superolelli

Share this post


Link to post
Share on other sites

Hi, I spotted a problem with non-looped animations. I've got three anims in a project (each 500ms), and when they're played, some of them tend to stuck at the very beginning. Everything works fine if loop is on.

I'll try to investigate, but maybe someone has seen this earlier?

Share this post


Link to post
Share on other sites

OK, I realised that blending may cause this problem, so I gave up on that. But again, animations were played properly only once, showing only last frame for consecutive replays. I thought this is related to time, so there's workaround:

instance->setCurrentTime(0);
instance->setCurrentAnimation(name);

But still, there is remaining problem with blending such animations.

Share this post


Link to post
Share on other sites

I want to use Spriter with Oxygine2d. I inspire my self on the SFML example (wich compiles and runs well on my system). So far I am quite sure the images referenced by the SCML file are loaded well. But I get an error message when I call the function. inst->setTimeElapsed((int)t).  An exception is thrown in the function.
real TimeInfo::getTimeRatio(real currentTime)
    {
        return easingCurve->adjustedTimeRatio(inverseLinear(time, nextTime, currentTime));
    }
Unhandled exception thrown: read access violation.
this->easingCurve was 0xDDDDDDDD

Does someone recognise this problem?

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...