专职C++

不能停止的脚步

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

常用链接

留言簿(13)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

60天内阅读排行

(基于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 冬瓜 阅读(1364) 评论(0)  编辑 收藏 引用 所属分类: 原创cocos2dx

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理