I've embedded jmp909's suggestion into SpriteGrabber. You can download it again from Code Section.
WHAT IS NEW: Having a single-framed sprite, you can call sprite:getShape() to get what physics:addBody() is waiting as a "shape", to override the sprites dimensions.
REQUIREMENT: The sprite has to be single-framed for the getShape() function to be created. Otherwise, it has no real meaning to get the "shape" of a multi-framed animation series (in which the individual frames can be of different sizes).
great, this worked for me...
im my Actor class
1
2
| sprite = mySheet:grabSprite(img,true)
sprite.parsedShape = sprite:getShape() |
Hi,
I am using TexturePacker along with SpriteGrabber, what the guide didn't tell me was that this line:
local hero=mainSprites:grabSprite("hero",true,{ breath={1,8,1000,0}, jump={9,8,700,1}})
assumes the texturepacker spritesheet is in order, which is not always the case, you might have to reorder the data sprite sheet
@newbie101
I actually had in mind to write this to the guide but then I saw that if you leave TexturePacker / Zwoptex with the default settings both of them have the data alphabetically ordered and there is no real reason to order them otherwise. Am I wrong to this? What setting caused the different order in TP for you?
I did basic settings, I think the order is random, I tried generating other sprites and sometimes the order would be correct so I talked to the creator of TexturePacker, and he said the new texturepacker 2.1.0 will have an option to order the spritedata based on the file name, e.q: "Basic" + SortBy "Name" + "Order Ascending" so I guess 2.0 is not actually ordered? or it is naturally ordered (the order of file being processed)
I currently have TexturePacker version 2.00 rc3 installed and it works fine without any settings for ordering (same for Zwoptex). I am going to install the new version and report back the results.
Hi,
I updated TexturePacker which should now work perfectly with SpriteGrabber. Please report back any problems you find.
You can now create textures up to 2048x2048 in basic layout mode for free. It also supports creation of non power of 2 textures in PNG format. So if you have an animation with 10 23x43 sprites it'll set them up in 230x43.
You can order the sprites by name, size and others.
There are several other features but I think these are the major ones for corona.
Cheers
Andreas
Some SpriteGrabber news...
There is a SpriteGrabber v1.2 currently released in code section, which supports "on the fly blurriness elimination" (aka: always get crisp sprites, even if you have odd image dimension for width/height), after an idea of Amigoni. I still haven't documented this and 2 other features already implemented in v1.2, so I apologize for this...
I am also thinking of releasing a v1.3 update that implements a super duper (yeah!) core feature, but I would like some feedback about whether you find it a good or ...messy idea.
The new feature, which actually I already have implemented and I am currently beta-testing it in my own game, is called "Adaptive Layout". In its essence it incarnates the "Desired Scenario" as I have described it here (with extra improvements, optional HD versions, any number of versions and full automation), which allows Universal-ready builds for games with spritesheets.
In a nutshell, Adaptive Layout is an alternative to Ansca's "Dynamic Content Scaling", and requires/supports "relative positioning" of sprites, which IMHO is the only real solution to get trully Universal-ready builds.
Adaptive Layout:
1) Detects the device resolution the game is running on.
2) Dynamically loads a provided spritesheet version (normal, HD, etc) which best fits the device, even if you have provided only 1-2 versions but there are dozens of possible device resolutions that don't exactly fit your provided assets. It then makes corrective scaling to get sprites appearing the same on eye to any device resolution.
In other words, you make a High Definition version for your spritesheets, autoscale them down with a tool like TexturePacker to get a "normal" version and with them you are ready to go for any current/future iDevices and the dozens of Android devices, without caring about the involved resolutions.
3) It requires "relative positioning" of sprites, which may seem an extra step but to my opinion is a best practice if you trully want to be to be Universal-ready, not only for 2-3 devices but for any current and future ones, regardless their width/height ratio (which makes Ansca's "Dynamic Content Scaling" prune to blank stripes that break real "universability" on many devices, like iPad and Galaxy).
4) It supports quick and easy relative positioning: instead of writing mysprite.x=240 (yuck!) you write mysprite.x=px(50) ...meaning x=50% of the device width resolution. It doesn't get easier/healthier !
I am also thinking of releasing this feature as an optional one, that when deactivated will provide automatic support for Scenario 3 (which is explained here and in the next 3-4 posts) that is based on Ansca's Dynamic Content Scaling. Again it will be provided as a fully automated solution with the appropriate handling to be ready to work for spritesheets.
***
Now, help me on this: are you ready to invest on relative positioning (on sprites creation) to get perfect universability once and forever, or do you find "Adaptive Layout" as something messy and outside of SpriteGrabber scope? I am trying to understand whether Adaptive Layout would make SriteGrabber an awesome module or it would totally mess things up regarding the already hard to understand "Proper Scaling" thing in our beloved Corona SDK.
Feedback is much appreciated...
Regards
Does this introduce additional requirements from my side (TexturePacker)? Or is all you need already available for that?
@Andreas
Adaptive Layout already works nicely with TexturePacker, which is a lifesaver with its "Auto SD" feature!
Thanks for the high quality support you provide to the Corona community.
Let me put my 2 cents in,
I think it's a good feature, but you are solving a problem that corona should be solving.
Corona might in the future have an automated solution for publishing to more devices with less configuration for each, I am not sure how your solution would work into that. However, if you get every corona user to use your library, which is easy if it's noob friendly, I can see you having the upper hand.
My suggestion: Release 2 versions? Basic and Advanced, there are developers who specifically target certain devices. There are also developers who want to cover as many devices as possible, having 2 options will enable them to pick and choose. Should corona solve what you are solving in Advanced, people can still use SpriteGrabber basic as it is currently being used.
Also, I might be wrong in this but isn't positioning in corona already relative? I use object.x = constants in my current game, I use the simulator's view as=> ipad, iphone, etc the position still works fine, am I missing something? Is px(coordinate) a function from SpriteGrabber?
EDIT: added my suggestion.
@newbie101
Your feedback is always welcome.
I tend to believe that people here don't even use spritesheets, because of the involved additional steps for preparing the spritesheets. So, it may be somewhat romantic to promote a "best practice" for universal scaling that not only *requires* everything to be in spritesheets, but also dictates every coordinate to be given as a percentage. Maybe it's the healthiest thing in the world, but in the end Corona is more or less a middleware for people that prefer convenience (easiness) over flexibility (including myself to an extent).
Now, regarding your question, positioning is *absolute* in Corona (by default). To see how this lacks universability try the following:
Place a sprite/image/shape at coordinates (480,320), which stands for bottom right on landscape, while working with the iPhone Simulator. You now have two options for getting your sprite showing on the iPad simulator...
You either setup your config.lua to include (width=480, height=320, scaling="letterbox") for activating Ansca's "Dynamic Content Scaling" and you get a properly sized sprite BUT displayed NEAR bottom right, because iPad has a different ratio to that of iPhone
OR
You delete config.lua (deactivating Dynamic Content Scaling) and then you correct the coordinate *by hand* to (1024,768) and you get your sprite at the proper position (bottom right of the screen) on iPad BUT you also get it half sized because of the double+ resolution that iPad has over iPhone (while your image stays the same).
Now can you see where "Relative Positioning" (percentages instead of absolute coordinates) can help? You don't want to make a different build (correct coordinates) for each set of devices that have a different ratio (width/height). You only want 1 Universal build !
The solution I propose ("Adaptive Layout"), uses relative positioning to correctly place things on screen and alongside it detects the device and selectively loads the most appropriate version of your provided spritesheets to maintain same sprite sizes among ANY devices. It also corrects the absence of suited versions by scaling sprites up/down, so that you always get a sprite with a size of the same screen proportion.
I know, I am stupid, but I don't get it.
I did everything I'm supposed to do.
I have only ONE animation in my sprite. A coin is spinning.
How do I get it onto the screen and let it spin?
There is a description for sprite sheets with multiple animations, which I can't use at the moment.
I get my coin to the screen, but it is not spinning, so I do something wrong, but I don't know, how to write the code for a SINGLE animation.
Can somebody make my stupidity away, please?
Hi Hunnenkoenig,
Have you read the examples in SpriteGrabber module page?
You can also see a very quick example in the first post of this thread.
If you still have issues plz post your code here so we could help you.
I have no code, because I messed around already so much, I don't know anymore, what worked and what not.
The simplest I can find anywhere is this (from the OP),but this is an animation with two sequences. I have no two sequences.
enemy=sprites.getSprite("enemy", true, {stand={1,6,1000,0}, attack={7,6,1000,1}})
I think, I understand the sample codes if I have more sequences and more animations on one sheet, but I can't figure out, how to do this for only one animation on one sheet.
I have a coin.lua
There are 11 png files registered in it: coin1.png - coin11.png
I have a sprite sheet named coin.
So, what is the code to get this onto my screen and animate, please?
Because the above code doesn't work, because there are attack and stand in it and I don't know, what to remove, because no matter how I alter this, I get all kind of error messages.
All the samples on the code exchange page are useless for me too, because all of them do things, I don't want to do.
For me it seems, in corona everything has to be as complicated as possible.
Nobody can write examples with the simplest things. Everything is bloated with super duper extra stuff, so a newb can get lost in the first second for sure. Frustrating :-P
EDIT:
I messed around a bit today again and I still don't get it.
Here is the code, which gets the coin onto the screen, but doesn't animate.
1
2
3
4
| local coinSprites=grabber.grabSheet("coin")
local coin=coinSprites:grabSprite("coin", true, {1,11,100,0}) |
If you have difficulties to understand how to code in Corona, be sure that you will find the other choices much more complicated. For example, take a look to what you have to master just for bringing in life a simple animation in Cocos2d (which is considered as the "easy" Objective-C way).
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d
In your code, replace getSheet and getSprite with grabSheet and grabSprite. (hm.. I see you already found it).
To place sprites on screen use :
spritename:show(150,200)
Physics have nothing to do with SpriteGrabber. Just be sure to have all your sprite frames in fixed (same) dimensions to eliminate artifacts and other known problems. To have fixed dimensions, don't check the "trim" option in TexturePacker/Zwoptex.
Thanks!
I could manage it already :-)
That cocos2d stuff is crazy :-P
I'm new here and my first attempt using sprites went perfectly using your helper code! Thanks a million!
The support within the Corona community is simply amazing.
@noahm26
Yes, Corona community is constantly growing and has many members that love to share useful things. I also use code snippets from other guys and their work have saved me much time. Among them is Color-to-RGB, FPS module, Director, EasingX...
Sharing is a win-win situation :)
A last thing, I need a little help with:
How do I rearrange the animations on layers?
It seems, my coin animation is on top of the screen above my player, but I want the coin being behind my player.
Even if I place the coin code before my player code in the lua file, the coin will be drawn over my player.
EDIT:
Got it, thanks!
I inserted my animation to the localGroup, what I didn't do before....silly me...
@Hunnenkoenig
What really matters is the precedence you follow when inserting your objects to a group.
The objects are firstly auto-inserted in a default "screen" group on creation, so if you don't use a custom group there is also some importance in the precedence of objects creation.
You may want to read a mini tutorial I once wrote about properly using Groups in Corona:
http://developer.anscamobile.com/forum/2010/10/03/mini-code-tutorial-groups
Again, if you still have issues publish your code here for the rest to take a look.
PS: You may also want to check the new API methods: object:toFront() , object:toBack()
http://developer.anscamobile.com/reference/index/objecttofront
views:2573 update:2011/10/17 8:58:49