Open zawasp opened 9 years ago
@zawasp You can specify a rect for sprite sheet, please refer to polygon sprite test case 2.
auto filename = s_pathGrossini;
Rect head = Rect(30,25,25,25);
auto pinfo = AutoPolygon::generatePolygon(filename, head);
spp = Sprite::create(pinfo);
addChild(spp);
@fusijie I know, but there's no direct way of doing it, eg:
auto pinfo = AutoPolygon::generatePolygonFromSpriteFrameName(spriteName);
spp = Sprite::create(pinfo);
More (and worse) than this, the AutoPolygon constructor will reload the same SpriteSheet texture file each time it's called, for each SpriteFrame. This takes a lot of time for large spritesheets. It should just lookup the texture name in the texture cache.
@zawasp Yes, you are right. Polygon Sprite is not a mature product, and I think we need a detailed discuss about it and relative tool.
I've extended SpriteFrameCache to load sprite frames with polygon information from a plist file. The format now contains 3 new optional values which can be used to pass the vertices and triangles:
triangles
: 3 indices per triangle, pointing to vertices and verticesUV coordinatesvertices
: vertices in sprite coordinates, each vertex consists of a pair of x and y coordinatesverticesUV
: vertices in the sprite sheet, each vertex consists of a pair of x and y coordinatesThe SpriteFrameCache creates standard quad sprites If these additional values are not present.
The API from a user's perspective is untouched. You simple load the plist file using
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("spritesheet.plist");
The sprites are created as usual:
auto sprite = Sprite::createWithSpriteFrameName("grossini-dance-05.png");
I've just opened a pull request here: https://github.com/cocos2d/cocos2d-x/pull/14049
Plist files with polygon data can be created using TexturePacker, see: Performance optimization for cocos2d-x using polygon sprite meshes
Awesome, will test with the new beta TexturePacker (off-topic: does the 3.x license include an upgrade for 4.x?)
@zawasp We don't care about major or minor releases. You get all released that are covered within your upgrade period. E.g. if you have upgrades included until 2015-12 you can use the current version.
Does any other solution if i don't have TexturePacker v4 ? Maybe we need add generate SpriteFrame AutoPolygon method?
Thanks
Right now AutoPolygon only supports generating PolygonInfo's from individual sprite files. We need to create them from a given SpriteFrame (loaded from SpriteFrameCache).
Currently, there's no direct way to do this.