cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.15k stars 7.05k forks source link

Add SpriteFrame support for AutoPolygon #12882

Open zawasp opened 9 years ago

zawasp commented 9 years ago

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.

fusijie commented 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);
zawasp commented 9 years ago

@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.

fusijie commented 9 years ago

@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.

CodeAndWeb commented 8 years ago

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:

The 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

zawasp commented 8 years ago

Awesome, will test with the new beta TexturePacker (off-topic: does the 3.x license include an upgrade for 4.x?)

CodeAndWeb commented 8 years ago

@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.

Yehsam23 commented 8 years ago

Does any other solution if i don't have TexturePacker v4 ? Maybe we need add generate SpriteFrame AutoPolygon method?

Thanks