coco2dx 精灵类

    CCSize size = CCDirector::sharedDirector()->getWinSize();

    CCSprite *bg = CCSprite::create("HelloWorld.png");
    bg->setPosition(ccp(size.width/2,size.height/2));//ccp CCPoint
    this->addChild(bg);

    CCSprite *sp1 = CCSprite::create("icon.png");
    sp1->setPosition(ccp(size.width*0.2,size.height*0.7));
    this->addChild(sp1);


    CCSprite *sp2 = CCSprite::create("icon.png",CCRect(28,28,29,29));
    sp2->setPosition(ccp(size.width*0.4, size.height*0.7));
    this->addChild(sp2);


    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("icon.png");//创建2d纹理

    CCSprite *sp3 = CCSprite::createWithTexture(texture);
    sp3->setPosition(ccp(size.width*0.6, size.height*0.7));
    this->addChild(sp3);


    CCSprite *sp4 = CCSprite::createWithTexture(texture, CCRect(0, 0, 40, 40));
    sp4->setPosition(ccp(size.width*0.8,size.height*0.7));
    this->addChild(sp4);


    CCSpriteFrame *frame = CCSpriteFrame::create("icon.png",CCRect(0,0,57,57));


    CCSprite *sp5 = CCSprite::createWithSpriteFrame(frame);//缓存帧
    sp5->setPosition(ccp(size.width*0.3,size.height*0.3));
    this->addChild(sp5);
    sp5->setScale(0.5f);
    sp5->setRotation(30.0f);//大于0顺时针小于0逆时针
    sp5->setSkewX(30);//倾斜 以图片的中央位置进行倾斜
    //sp5->setVisible(false);//不可见
    //sp5->setColor(ccc3(255,0,0));
    sp5->setOpacity(100);//0-255
    sp5->setTexture(CCTextureCache::sharedTextureCache()->addImage("CloseNormal.png"));
    /*
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("img.plist");

    CCSprite *sp6 = CCSprite::createWithSpriteFrameName("icon.png");//缓存帧
    sp6->setPosition(ccp(size.width*0.7,size.height*0.3));
    this->addChild(sp6);
    */

 

posted @ 2014-10-23 22:00  wuhn  阅读(293)  评论(0编辑  收藏  举报