Cocos2d-x 在缓存创建图片

/* 加载图片资源到SpriteFrame缓存池*/
    CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile("ghosts.plist", "ghosts.png");
    /* 创建CCTexture2D对象*/
    CCTexture2D *texturee=CCTextureCache::sharedTextureCache()->textureForKey("ghosts.png");
    /* 使用CCTexture2D对象创建BatchNode */
    CCSpriteBatchNode *batchnode=CCSpriteBatchNode::createWithTexture(texturee, 10);
     /* 添加BatchNode到场景*/
    this->addChild(batchnode,1);
    /* 批量创建精灵,并把精灵加入batchnode  */
    batchnode->setPosition(ccp(size.width/3,size.height/3));
    for (int i=0; i<10; i++) {
        int x=CCRANDOM_0_1()*320;
        int y=CCRANDOM_0_1()*32;
        CCSprite *spritte=CCSprite::createWithSpriteFrameName("father.gif");
        spritte->setPosition(ccp(x,y));
        batchnode->addChild(spritte);
       

       
    }
    //从缓存总读取图片,图片是在ghosts.png中集成的
    CCMenuItemImage *closed=CCMenuItemImage::create();
    closed->setNormalSpriteFrame(cache->spriteFrameByName("sister1.gif"));
    closed->setSelectedSpriteFrame(cache->spriteFrameByName("sister2.gif"));
    closed->initWithTarget(this, menu_selector(HelloWorld::menuCloseCallback));
    closed->setPosition(ccp(size.width/5,size.height/5));
    //this->addChild(closed);
    CCMenu *menus=CCMenu::create(closed,NULL);
    this->addChild(menus);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值