-
-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a more "standard" spritesheet format #8
Comments
+1 |
hehe :) |
Cocos2D implements the zwoptex format, which both TexturePacker and (obviously) zwoptex implement. It seems to have become somewhat of a standard. I'm not really a fan of using XML for that sort of thing, but plists are natively supported on iOS, so I guess that's why they chose it. JSON would have been more compact and easier to parse. Rotation is part of the standard, however; so you would be blocked on this until you implement rotation in your sprite classes. |
I was also hoping to use Texture Packer, has anyone worked on this? Or found a good way to use better sprite sheets? |
Well yeah, I'm using it, although it might be improved a lot. In TP you can tweak the settings, so each of your sprites will be the same size as the others, and with different padding space (so it's the same size as the others, right?), and update the colRect for each entity. In the game I'm developing I use this approach, although I really want to use some better format, so I can strip those empty pixels from my spritesheet. |
Hi guys, now that ticket #15 is done (will make it easier to add additional format) and that I just finished JSON parsing (which means it's easy to add for this as well) my next step is to look at adding Texturepacker support. I however have a few questions as I don't really know how to start this. basically, the idea of Texturepacker is obviously to pack all sprite in a single image and build out of it a texture atlas, kind of dictionnary that contains position and setting for all single image. In melonJS is working today, the most simple renderable element is the spriteObject, and then AnimationSheet that takes in input a sprite sheet with fixed cell size. with Texture Packer how would this work, knowing that all image can have different size ? I'm trying to see how it could then be used (programmatically) when adding a renderable element to an entity that would be using TexturePacker, but I cannot see it.... I was initially thinking that a texturePacker "object" could define a function that would returns a specific sprite(s), but then if it;s about creating an additional image in memory all benefit of texture packer is lost ! |
My understanding is that these texture atlases contain information about positioning each frame, relative to an object's "center point" maybe. Without at least that, supporting different sizes for each animation frame would be a complete headache to manage. Likewise, the atlas should contain information about frame ordering and durations. |
Yep actually from what I saw so far (in other implementation) this can be seen as 2 different objects :
|
…other small improvements still pretty draft anyway :)
This is also linked to ticket #15, but since I'm having these questions when implementing this, here they are, How is a sprite supposed to be displayed corresponding to an entity ?
If anyone passing by here, some light/idea would be appreciated :) |
@obiot, my recommendation here is anchoring to the center (0.5, 0.5). This is also inline with physics engines (box2d/chipmunk) which describe object positions relative to their center, and polygons are defined by vectors around the center, rotation around the center, etc. I'm looking at the ticket-8 branch now, but I don't see any information about sprite anchor points. :( https://github.com/obiot/melonJS/blob/d73a489f3a9b90abe06f58d3abb5262ff6ca0136/examples/platformer/data/gfx/texture.json I guess this info has to be added outside of texturepacker? Or maybe it's a matter of the source images you used to create that atlas? As I understand it (reading forum posts) the TexturePacker "trim" feature will remove the transparent pixels, and store some information about the original image size in the meta data. That's probably what these |
@parasyte thank you for the feedback as always :) But do we say here that both the entity (than inherit from rect) and the sprite anchor points should be aligned ? Else, ticket #8 is still pretty draft, but for the trim function yes, that’s the idea. |
@obiot I think it would be very useful to transition all anchor points to default to object center, including position vector. It will be really odd for upgrading the lib in existing games. But it will make a log of things much easier for us when we have multiple renderables, and when we decide to integrate a physics engine. :) |
@parasyte Would you mind explaining me with some example ? like compared to what I did in ticket#8 (entity Else I completely agree about any breaking changes, and if we want melonJS to go to the next level some are anyway required ! |
@obiot Currently, position vectors are "anchored" to |
…tioning * default position is now around the entity center * platformer example update to bottom aligned (0.5, 1.0) the sprite to the entity
I ended up having very little free time during this weekend, but I finally implemented the changes we discussed for the renderable positioning : Here is what I did :
And that should be all I think ? I think that if this thing works well, I will commit back a first version of ticket #8 in the master branch (while keep working on ticket #8 to add SpriteAnimation), I know that this is not yet finished, but at least we have a first version with a sprite object that can be extracted from textureapacker and most of all the new object positioning (the sooner we expose it, the sooner people will use it). What do you think ? would you see any other “must” change stuff if we do so ? |
I was just thinking that it's nice to see that when things are well thought they all come together quite nicely :) |
@obiot OoooOOOoooo! :D TBH, I don't know of any other engines/frameworks that use unit vectors for anchor point, but it really simplifies the math involved when used with the Vector2D class. I like it. (Chipmunk uses unitless vectors for the center point; the numbers don't necessarily correlate to any specific length. Typically though, it's easiest to treat the vectors in Chipmunk as pixel lengths. At least, in my experience.) However, Chipmunk is a bit different still: It uses I haven't looked at the code for this yet, but it sounds cool! |
note that it's still time to align it to what chipmunk is doing, so far almost nobody used this in melonJS , so it's just a matter of deciding what is the "best", knowing that ultimately being closer from what is chipmunk is doing will for sure ease our life when integrating it (either as plugin or not) though to be honest, while i can understand that the y axis can be reversed, having (0,0) as center point looks however strange to me ) |
I think that's pretty common when defining polygons. When I was learning OpenGL, the same convention was used. For example, about 1/3 down the page: http://openglbook.com/the-book/chapter-2-vertices-and-shapes/ there's a diagram of a triangle defined in 3-dimensional space which uses (0,0,0) as the center point. (Also note the reversed Y-axis in OpenGL, too! This actually matches the Cartesian coordinate system, and geometry in general.) |
@parasyte note that if we keep |
Animation is there ! it still need further testing and tweaks (as right now when using rotation option or non trimmed sprites, final position can be a bit off), but else it works just as I wanted :) if you want to try, make sure you disable rotation, and enable trim ! |
@parasyte thank you for the last code review, I effectively forgot the one when creating sprites ;) I did not do much today (I was the whole day to some exhibition for my company), but I will merge this baby tomorrow in the main branch. it's late now here, i'm tired, and I'm lazy then to update the wiki and write a post in the forum with the changes, and seek for our usual beta-testers :) |
…other small improvements still pretty draft anyway :)
…tioning * default position is now around the entity center * platformer example update to bottom aligned (0.5, 1.0) the sprite to the entity
this is still broken though, as once rotation is enabled in TexturePacker, sprite position is off .
I'm closing this one, as the point was to add a more generic/flexible texture format, which we did, and so far so good (i don't believe it being100% bug free, but at least it's mature enough tho consider this one done). if more format are to be added they can be managed through specific ticket/request. |
question : any better way to return the region information ? (maybe through a me.Renderable object ?)
@see http://renderhjs.net/shoebox/ Requires to install a custom exporter (download & dbl-click) @see https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx
Zwoptex, TexturePacker or any other stuff with an easy and popular format !
The text was updated successfully, but these errors were encountered: