专职C++

不能停止的脚步

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

常用链接

留言簿(28)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

(基于cocos2dx 2.2.2)
如果很多图片很小或常用,可以使用CCSpriteFrameCache,来避免资源被反复加载。 
(注:对于plist,我这里使用的是一个免费的工具,SpritePacker,http://spritepacker.kernys.net)

如:CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("basetank.plist");
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>frames</key>
    <dict>
        <key>basetank_down.png</key>
        <dict>
            <key>frame</key>
            <string>{{0,0},{26,26}}</string>
            <key>offset</key>
            <string>{0,0}</string>
            <key>rotated</key>
            <false/>
            <key>sourceColorRect</key>
            <string>{{3,3},{26,26}}</string>
            <key>sourceSize</key>
            <string>{32,32}</string>
        </dict>
        <key>basetank_left.png</key>
        <dict>
            <key>frame</key>
            <string>{{0,27},{26,26}}</string>
            <key>offset</key>
            <string>{0,0}</string>
            <key>rotated</key>
            <false/>
            <key>sourceColorRect</key>
            <string>{{3,3},{26,26}}</string>
            <key>sourceSize</key>
            <string>{32,32}</string>
        </dict>
        <key>basetank_right.png</key>
        <dict>
            <key>frame</key>
            <string>{{0,54},{26,26}}</string>
            <key>offset</key>
            <string>{0,0}</string>
            <key>rotated</key>
            <false/>
            <key>sourceColorRect</key>
            <string>{{3,3},{26,26}}</string>
            <key>sourceSize</key>
            <string>{32,32}</string>
        </dict>
        <key>basetank_up.png</key>
        <dict>
            <key>frame</key>
            <string>{{0,81},{26,26}}</string>
            <key>offset</key>
            <string>{0,0}</string>
            <key>rotated</key>
            <false/>
            <key>sourceColorRect</key>
            <string>{{3,3},{26,26}}</string>
            <key>sourceSize</key>
            <string>{32,32}</string>
        </dict>
    </dict>
    <key>metadata</key>
    <dict>
        <key>format</key>
        <integer>2</integer>
        <key>realTextureFileName</key>
        <string>basetank.png</string>
        <key>size</key>
        <string>{32,128}</string>
        <key>smartupdate</key>
        <string>{None}</string>
        <key>textureFileName</key>
        <string>basetank.png</string>
    </dict>
</dict>
</plist>
这样,就可以完成一组图片资源加载。
            CCSprite * p1Pic = CCSprite::createWithSpriteFrameName(“basetank_up.png”);
            p1Pic->setPosition(GetPosition(pPlayerLayer, "Player1"));
            p1Pic->setAnchorPoint(ccp(0, 0));
            this->addChild(p1Pic);
如需更换图片,
p1Pic
->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("basetank_right.png"));
这里的作用相当于是把tank向右转
posted on 2014-03-24 00:08 冬瓜 阅读(1949) 评论(0)  编辑 收藏 引用 所属分类: 原创cocos2dx

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理