zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    「LibreOJ NOI Round #2」不等关系
    Atcoder Grand Contest 036 D
    「CTS2019」氪金手游
    「CTS2019」珍珠
    「APIO2016」烟花表演
    「PKUWC2018/PKUSC2018」试题选做
    「PKUWC2018」猎人杀
    「WC 2019」数树
    CodeForces 794 G.Replace All
    「BZOJ 4228」Tibbar的后花园
  • 原文地址:https://www.cnblogs.com/pangblog/p/3362229.html
Copyright © 2011-2022 走看看