I've updated, and nothing have changed on my side : it is always scaled and blurred. Have you tried an example with what I did http://www.aymericlamboley.fr/test/StarlingMC.zip before ?
It seems that frameWidth="0" & frameHeight="0".
I've updated, and nothing have changed on my side : it is always scaled and blurred. Have you tried an example with what I did http://www.aymericlamboley.fr/test/StarlingMC.zip before ?
It seems that frameWidth="0" & frameHeight="0".
Aymeric, from what I can see in your example, you don't have the latest version of DynamicAtlas.as
I've checked and it's up to date on gitHub. If you browse the file you should see that there is a new function called getRealBounds, and a new parameter in the fromMovieClipContainer method, called checkBounds. The download as zip also brings the latest update.
Oh didn't see this last paremeters to set to true! Now I have some strange result.
I updated my code but not the zip. Now the zip is updated with the last version.
Have you compared your code and MC with the one in the sample? Is the sample running OK?
I can take a look at your files if you want.
The example is running fine. I have made the checkBounds parameter directly to true in the extension.
It would be really cool if you can take a look on my files! It is a bit a battlefield... but nothing complex, really simple example (check StarlingState). If you just change the checkBounds parameter the character is not at the same starting point for example. Thank you !
Thanks Aymeric. I had a small bug in the bounds detection.
Version 1.0 is out. Download it from gitHub and hopefully you'll not experience anomalous scaling ever again. (crossing fingers)
Hey emibap,
Thanks for this really useful class! I was wondering, have you thought about implementing something that forces the atlas to have width/height set to power of 2?
Note taken from 'Whack!' notes:
"The last big note to keep in mind for textures is that the GPU only accepts images where both the width and height are each a power of 2 (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, and 2048)"
Don't worry, tomph, Starling will automatically draw non-POT-textures into a POT-texture before uploading them, so there's no performance penalty of having non-POT-textures. (Except on creation time, that is, but not on rendering.)
I was about to say the same thing. Thanks Daniel! You´re everywhere
@thomp, thanks for using the class
Thanks Daniel! You´re everywhere
Yeah, this is a strong point for Starling's community
Not to mention one of the moderators is Genome2D's author.
On topic, would you happen to know how your dynamic atlas generator compares to ND2D Dynamic Atlas, feature and performance wise? ( http://docs.rsnewmedia.co.uk/display/nd2ddynatlas/Home )
Thanks!
Wow! I wasn´t aware of the existence of the ND2D Dynamic Atlas...
I´ve just taken a quick look at it.
In terms of performance I haven't done much yet, so I think that the ND2D version would be better since the docs says that performance has been improved.
In terms of features, it would be tricky to compare, but let's see:
ND2D DynAtlas:
--------------
* Support for scaling movie clips if they don't fit on a single sprite sheet.
* Convert multiple movie clips into a single sprite sheet.
* Play animations by label or linkage name if no label exists.
* Play by Class name if no Linkage or Labels exist, remember to use the full package and Class name if you are embedding.
* Handles offsets for you even when using different sized frames.
* SWF loader utility to load multiple SWF files and easily access the movie clips by name.
* Bin packing
Starling DynAtlas:
* Dynamic creation of a Texture Atlas from a MovieClip (flash.display.MovieClip) container that could act as a sprite sheet, or from a Vector of Classes
* Filters made to the objects are captured
* Color transforms (tint, alpha) are optionally captured
* Scales the objects (and also the filters) to a specified value
* Automatically detects the objects bounds so you don't necessarily have to set the registration points to TOP LEFT
* Registers Bitmap Fonts based on system or embedded fonts from strings or from good old Flash TextFields
So, basically if you do not need filters, color transforms or Bitmap Fonts then the ND2D version would be a better implementation. I don't exactly know what Bin Packing is though
Cheers!
Bin packing is probably type of binary tree packing algorithm. Anyway guys you should always do this during asset preparation using software like http://www.texturepacker.com and not pack your atlases at runtime. I don't see why someone would generate atlases at runtime unless there is some kind of graphic itself that is generated at runtime.
BTW Genome2D can also create texture altases from movieclips or fonts, you can also implement your own packing algorithm and just call Genome2D with a bitmap, vector of regions and vector of pivots and it will create the altas for you.
Still I am wondering why you guys want to create the atlases at runtime? Its like compiling the shaders at runtime, seems like everyone is doing it even if its a performance impact without reason.
@sHTiF, I don't think everyone is doing it. I think it's good for quick prototyping or very useful when dealing with different screen sizes. Still, most of the developers end up using bitmaps.
@emibap you are right I didn't think about prototyping, especially existing projects where this is really helpful. I am just worried that people will get lazy and just do it instead of going the complete route during asset preparation
Can't say I'm not usually tempted by lazines
But yes, the best route wouldn't involve Dynamic Atlasses most of the times.
Thanks emibap for your thorough reply.
I'm keeping both generators as favs, luv them.
@sHTiF: I agree with you technically and I do have TexturePacker as a fav, but there are 2 main reasons to use dynamic atlas generators IMO. Firstly it can reduce file size and download times, and secondly you can't always know what a sprite will look like. It was the big advantage of MovieClips and Sprites over spritesheets: What if I have a 2D animated character that can equip items at runtime and run around with them?
Even dynamic atlases can't quite make up for it, or at least I had trouble last time I tried... I think I had issues with memory consumption, z-ordering of equipped items and various character orientations. I came up with partial solutions but I'm all ears if you already know how to deal with that or there's a lib or something. ^^
If items could stand in their own spritesheets and fit character animations, and we could flawlessly integrate them into main character animations at runtime, then TexturePacker would work. In the mean time I found that equipping a flash.display.Sprite or MovieClip and capturing them into a spritesheet at runtime was simpler to do ^^
Noradrenaline to achieve that you would need to implement your own animation system, something like armature models.
Yeah, that's pretty much where I stopped I think, if armature models (in 2D) mean having all Z-meaningful body parts separated but all running the same animations, ready to be integrated together on player demand.
This sounded too long to develop, so I just sticked to generating spritesheets from animated MovieClips. The lazy way you said? :p
@Noradrenaline About memory usage: you are quite wrong in that point. TexturePacker's sprite sheets are usually way smaller than a set of isolated sprites since better packing can be applied.
You an also reduce memory by reducing color depth if your sprites allow what.
I compose my characters from different sprite sheets and that works well. E.g. having the head separated from the body which is more or less static, then add arms and weapons, walking animation.
I think there was a misunderstanding, I meant that spritesheets consume a lot more memory than vector animations.
Usually it's not a problem but in my situation where there was a bunch of character orientations required for every single animation, along with a bunch of different characters, I had to keep an eye on RAM and file size (for download times). I decided to fix size issues with a dynamic atlas generator because shipping the graphics as vectors was so much smaller. I'm all ears if you know a way to use pre-generated texture atlases that aren't too big compared to vectors. Like... is Adobe Texture Format released yet? Or whatever. I'd rather not convert MovieClips at runtime if I could avoid to.
Your second paragraph is interesting, that's my understanding of what is an armature model in 2D. Would you happen to have a texture atlas sample waiting in your hard drive? One illustrating that animated "2D armature" thing to make sure I understand properly.
Thanks either way
PS: sHTiF might have meant animated 3D armature models. We create the model, animate it, then add a mesh to it and export separate body parts (animated) to sprite sheets. One sprite sheet per body part per mesh, later merged into one.
It's an interesting workflow, I don't know how to use 3DS Max or any other program to achieve that though :/ (If anyone has links I'd be happy to hear them of course)
Right - vector *is* smaller (well - in most cases at least
)
Currently I do the animation quite simple... I have the limbs and attach them relative to each other. Hand at arm, arm at body etc. They can move x,y and rotate. Attached limbs rotate with it's parent.
Then I have several final positions saved and interpolate the animation between them.
(I am currently doing this in cocos2d but things should work the same with flash)
You can see it in action here: http://www.turtletrigger.com/ at 0:30
What a tasty game xD
Tweening must provide an important gain in file size and RAM consumption over what I've been testing in the past. I'll see if I can find some articles so I don't have to work out all details from scratch. Thanksalot!
This is a great idea for Starling and something I've been doing on my own projects for a while. It maintains the core magic of flash (being a vector tweening engine) and combines it with the speed benefits of bitmap data.
One thing I'd suggest that would be a good addition is an optional hitzone marker (with a reserved name) that can be placed within the MCs to specify a square hit area. Not sure if there is any provision for something like that within Starling, but it's what I do on my own projects and works well for characters that are not visually contained strict circle or square shapes.
Currently it's one thing that is keeping me from jumping on Starling right now so I'd be interesting in learning how you achieve this currently (ie - how do you specify the hit zone of a starling sprite, is it only possible by plugging in co-ords manually or is there some kind of visual marker based system).
Keep up the awesome work, will be following!
To add some kind of hit zone, you currently have to override the "hitTest" method and check the coordinates. (Like the "RoundButton" class in the demo project does.) If you can create the hit zone with rectangles, you could create a sprite with quads (alpha=0), and forward the hit test to that sprite.
Hi Daniel, thanks for the info.
So it does sound like it's a case of manually plugging in co-ords for a hit zone on each of the character animation cycles (though generally I try to keep the same hit zone for all the characters cycles in most cases). Makes sense, I guess if you committed to using a "HitZone" subclass of Starling's Sprite or MovieClip classes you could tweak the dynamic atlas builder to generate this data off an internal marker clip also (which is what I do). I think it would be a good addition - pretty standard coding problem to face.
On that note it would also be good to be able specify a child (with a reserved name) to act as a frame so you can control the perimeter of the sprite capture and force particular sizes if you have the need. I've aslo found that sometimes capturing elements on stage freaks out Flash a bit and it can return an area that is actually a lot bigger than the visible pixel bounds.
Thanks a lot for that suggestion! You're right, this might be a valuable addition. I'll think about that!
Here is a great new tutorial using this extension.
CREATE DYNAMIC TEXTURE ATLASES FROM VECTOR AT RUN-TIME
--
http://www.rivellomultimediaconsulting.com/starling-framework-use-flash-display-movieclip-with-dynamictextureatlasgenerator/
I'm trying to use Dynamic Texture Atlas with the checkBounds parameter set to true. It does help to maintain scaling proportions, however it creates some playback problems: some frames seems to be skipped during playback (when it loops). The framerate of the app is not affected, but the movie clip playback is not smooth. If I keep the checkbounds parameter to false, the playback is perfect.
As a workaround, I created an almost invisible rect around my movie clip to keep the same rect during all the animation and it works... But this doesn't seem to be the best way to go in terms of optimisation.
Any ideas? Thanks.
Hi Jonathan,
Can you PM me a sample of the issue? Thanks!
Hi to everyone,
I used DynamicAtlas to maintain a single vector assets version and manage for every device resolution.
This is a great extension!
I try to save locally a bitmap "device specific version" of every asset, the first time it is used.
It works fine on the desktop emulation player, but if I try this features on a device, the second time I get the image from local disk but it doesn't show anything.
The function I create is:
...
public static function getImage(name:String):Image
{
var retImg:Image;
if (sTextures[name] == undefined)
{
//check if exists a local png file (saved in the past)
var fl:File = File.documentsDirectory.resolvePath(name + ".png");
if (fl.exists)
{
//load imge from disk
sTextures[name] = Texture.fromBitmapData(loadLocalPNG(name));
retImg = new Image(sTextures[name]);
}
else
{
if (_spriteSheet == null)
{
_spriteSheet = new SpriteSheet();
_textureAtlas = DynamicAtlas.fromMovieClipContainer(_spriteSheet, 1, 0, true, false);
}
sTextures[name] = _textureAtlas.getTextures(name)[0]; //N.B.: I use ONLY the first frame of the named movieclip
//save local PNG copy
retImg = new Image(sTextures[name]);
saveLocalPNG(name, copyAsBitmapData(retImg));
}
}
return retImg;
}
private static function loadLocalPNG(name:String):BitmapData
{
var ba:ByteArray = new ByteArray();
var file:File = File.documentsDirectory.resolvePath(name + ".png");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
while (fileStream.bytesAvailable > 0)
fileStream.readBytes(ba, fileStream.position, fileStream.bytesAvailable);
fileStream.close();
var png:PNGDecoder = new PNGDecoder();
return png.decode(ba);
}
...
The Image object returned by the function has the correct width and height size but the following code show the image only the first time the app is started:
...
var myUfo:Image = AssetsManager.getImage("Ufo");
addChild(myUfo);
...
If I open the Organizer, inside Xcode, and I select the app installed on the connected device, I can see the png files created (in the Documents folder): they are well generated.
What can I do to solve my issue?
Thanks
You must log in to post.