Spriter Importer for Monkey

Community Forums/Monkey Talk/Spriter Importer for Monkey

therevills(Posted 2013) [#1]
A week or so I decided to update my Spriter importer, seems to work pretty well:

http://www.therevillsgames.com/monkey/SpriterA4/MonkeyGame.html

And should be easy enough to move to BlitzMax too ;)




SLotman(Posted 2013) [#2]
I had to change "MonkeySpriter" draw code to get it to work, but it worked really well here!

	Method Draw:Void(offsetX:Float, offsetY:Float, tween:Bool = False)
		Local anim:SpriterAnimation = entities.Get(0).animations.Get(animationName)
		If anim=Null Then Return
(...)


Just added the null check and it's running solid :)
(I had to comment out everything "hero" related, since on their page they only have the monster example to download)

I can't thank you enough for this, I now have to write tons of code to see if this can be used in a game I'll make :D

Edit: Is it possible to mirror/scale the whole animation in code? Or even to 'hide' parts of the animation? (Like setting an arm alpha to zero or something?)


therevills(Posted 2013) [#3]
If anim=Null Then Return

Thanks for that! I did mean to change on how that part works, but I totally forgot to do it when my head was in between tweening and keyframes...

Is it possible to mirror/scale the whole animation in code?

Should be... I'm using the local scale commands within the DrawImage, so using the global matrix it should work. See code below...

Or even to 'hide' parts of the animation? (Like setting an arm alpha to zero or something?)

You can change object's alpha in Spriter itself and the code should read that.

Updated code, to scale animation.... need to fix flipping animation, currently doesn't support flipping Y.



therevills(Posted 2013) [#4]
Another update, flipping Y and X works now:
http://www.therevillsgames.com/monkey/SpriterA4/MonkeyGame.html




Shagwana(Posted 2013) [#5]
At very slow speeds the feet of the little knight don't look right when walking. Sort of jumps and snaps to location. Is that right?


therevills(Posted 2013) [#6]
The Knight`s file was based off the first version of Spriter and was converted by someone, I've slightly fixed it up myself but yeah it still looks a little off... But it does in Sprinter itself.


SLotman(Posted 2013) [#7]
I just did some changes in the code - don't know if anyone will find it useful, but it's really good for me:



- Added another null check on MonkeySpriter.update - I was trying to play an animation that didn't exist and the program was crashing!

- Added a copy() method to MonkeySpriter - so I can clone any loaded animation - don't know how it will affect alpha or even hiding parts of the animation - but for all the rest it seems to work pretty well

- moved x/y/scale inside MonkeySpriter, so each animation can have it's own position/scale, even if cloned.

- Added autofit into the code ^_^


SLotman(Posted 2013) [#8]
Hmmm... I just got worried about something: Spriter doesn't support multiple "parts" on a single image?

Isn't this going to create a huge overhead (because of several texture swapping) if you have lots of chars on screen?


therevills(Posted 2013) [#9]
I just did some changes in the code

Cool! Sounds good!

Spriter doesn't support multiple "parts" on a single image?

Not yet:
http://www.brashmonkey.com/spriter%20features.htm
Texture atlas (spritesheet) support via texturepacker integration. <coming soon>

But it doesnt stop us for doing it before them, we can use TexturePacker to generate the atlas and use the TextureProvider class to lookup the texture instead of the single images ;)

I'm still thinking if having separate TextureProviders is a good idea or not...


SLotman(Posted 2013) [#10]
I've managed a hacky way to hide objects ^_^

First, I added a new class:

Class FileFolder
  Field file:Int
  Field folder:Int  
End Class


Then, I added on SpriterMonkey:



And changed the Draw method:


Then I can just call monster.hideObject(0,0) to hide the monster shadow in the sample file :)


therevills(Posted 2013) [#11]
That seems like a bit of work remembering that 0,0 in the shadow... what about expanding the TextureProvider and altering GetTexture, so if the texture is hidden GetTexture returns null. Of course, change Draw to not access the null texture ;)

I've added the importing of bones, but at the moment I haven't got a clue how to code them into the animations.

Heres the updated code:



SLotman(Posted 2013) [#12]
About the file/folder thing: I know - but the 0,0 part I can see right in the beginning of the scml file, so it won't bother me that much :)

As for bones... I'm not using them myself, no need to create any unnecessary overheads :)

But I just found out a problem with the code - one animation I made is being played incorrectly: body parts moving erratically, with some parts flying away very far from where they should be.

Get the problematic animation to see it: it runs fine on Spriter, but on the test program, it's completely crazy. (I guess it has anything to do with changing the anchor rotation points in Spriter - It was the first animation where I actually did that)


therevills(Posted 2013) [#13]
Thanks for the test file, you can see its the tweening which is messing up as when you turn off tweening it displays the keyframes correctly.


therevills(Posted 2013) [#14]
Yep, you are correct its the pivot points changes in the timeline which is messing it up...

I'll have to have a think how to fix that... as when you set the pivot in Spriter it actually changes the X,Y position of the object.


therevills(Posted 2013) [#15]
Okay this is getting tricky...

Say on key frame 1 the pivot for the head is at 20, 74 and on key frame 2 its at 24, 150, but the actual image doesn't move. The tween is between 74 and 150 forcing the head to move upwards.

I could minus the pivots off the co-ords, but only if I don't use "SetHandle":

       |Frame 1 | Frame 2
-------+--------+---------
  x    | 20     | 24
  y    | 74     | 150
pivotX | 0.617  | 0.503
pivotY | 0.157  | 0.778

Image Height = 121 pixels

Just looking at Y:
Frame 1:
pivotYPoint = 0.157 * 121 = 18.997

newY = 74 - 18.997 = 55

Frame 2:
pivotYPoint = 0.778 * 121 = 94.138

newY = 150 - 94.138 = 56


But of course now all the angles wont be rotated at the correct point.... :(


SLotman(Posted 2013) [#16]
Yikes! Maybe looking into other "plugins" may help a little?

Anyway - this isn't something "essential" for me - I can live with it (I've made several anims already just to stress test the system, and none changing the pivot position)

Edit: for me, the most concerning issue is the "texture packing" thing - I just made a test with almost 100 chars on screen, and the FPS dropped severely :(


therevills(Posted 2013) [#17]
Fixed it! Thank gawd!!!




Edit: for me, the most concerning issue is the "texture packing" thing - I just made a test with almost 100 chars on screen, and the FPS dropped severely :(

What target were you testing on? Also 100 characters is quite a lot...
Do you own TexturePacker? I'll have a look on how to use it with this code (Diddy already can load in TP files).


therevills(Posted 2013) [#18]
Decided on uploading the code to Google Code:

https://code.google.com/p/monkey-spriter-importer/


therevills(Posted 2013) [#19]
Added Sparrow Atlas support and updated the example to benchmark it...

I get 60FPS in HTML5 (IE10) using an Atlas and not using an Atlas, with 103 characters on screen...


therevills(Posted 2013) [#20]
WIP Bones Added...


therevills(Posted 2013) [#21]
Managed to "fake" bones flipping:

http://www.therevillsgames.com/monkey/SpriterA4/MonkeyGame.html