//精灵帧缓存读取plist SpriteFrameCache *sfc = SpriteFrameCache::sharedSpriteFrameCache(); sfc->addSpriteFramesWithFile("pic/sprites.plist"); //加载大图 auto sprites = SpriteBatchNode::create("pic/sprites.png"); sprites->setPosition(Point::ZERO); this->addChild(sprites,1); //从大图中截取小图创建精灵 auto s = Sprite::createWithSpriteFrameName("grossini_dance_01.png"); s->setPosition(Point(CCRANDOM_0_1() * 480, CCRANDOM_0_1() * 320)); this->addChild(s);
工作中的代码:
self.cache = cc.SpriteFrameCache:getInstance() self.cache:addSpriteFrames("game_element.plist") cc.SpriteFrameCache:getInstance():addSpriteFrames("public/im_head.plist") local fishName=string.format("Avatar%d.png", GlobalUserItem.wFaceID) local sprite = cc.Sprite:createWithSpriteFrameName(fishName) sprite:setPosition(48.5,706.4) sprite:addTo(self) sprite:setScale(0.55) cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile("public/im_head.plist")