ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • cocos2d-x CCSpriteFrame & CCAnimaion & CCParalllaxnode
    Pause @/Cocos2d-x2 2013. 7. 7. 22:49

    2. CCSpriteFrame

    File로 직접 Frame 생성하기

    CCSpriteFrame *frame = CCSpriteFrame::create("test.png", rect);

     

    Cache에 등록된 이름으로 Frame 생성하기

    CCSpriteFrameCache::sharedSpriteFrameCache()->

    addSpriteFramesWithFile("test.plist");

    CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->

    spriteFrameByName("grossini_dance_01.png");

    ③ Frame으로 Sprite 생성하기

    CCSprite *spr = CCSprite::createWithSpriteFrame(frame);

    Cache에 등록된 Frame 이름으로 바로 Sprite 생성하기

    CCSpriteFrameCache::sharedSpriteFrameCache()->

    addSpriteFramesWithFile("test.plist");

     

    CCSprite *spr = CCSprite::createWithSpriteFrameName("grossini_dance_01.png");


     

    3. Create CCSprite

    CCSprite *spr = CCSprite::create("test.png");

    CCSprite *spr = CCSprite::create("test.png", rect);

    CCSprite *spr = CCSprite::createWithSpriteFrame(frame);

    CCSprite *spr = CCSprite::createWithSpriteFrameName("grossini_dance_01.png");

    CCSprite *spr = CCSprite::createWithTexture(texture);

    CCSprite *spr = CCSprite::createWithTexture(texture, rect);

     

    CCAnimation

    1. Animation Process

    CCSprite -> CCAnimation -> CCAnimate -> runAction;


    dance_man.zip


    2. File : addSpriteFrameWithFileName

    CCAnimation *animation = CCAnimation::create();

    animation->setDelayPerUnit(0.3f);

    animation->addSpriteFrameWithFileName("grossini_dance_01.png");

    animation-> addSpriteFrameWithFileName("grossini_dance_02.png");

    animation-> addSpriteFrameWithFileName("grossini_dance_03.png");


    CCAnimate *animate = CCAnimate::create(animation);


    spr->runAction(CCRepeatForever::create(animate));


    3. Texture : addSpriteFrameWithTexture

    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("grossini_dance_atlas.png");

    for(int i=0;i<14;i++) {

    animation->addSpriteFrameWithTexture(texture, CCRect((i%5)*85, (i/5)*121, 85, 121));

    }


    4. CCSpriteFrame : addSpriteFrame

    CCSpriteFrameCache::sharedSpriteFrameCache()->

    addSpriteFramesWithFile("grossini_gray.plist");


    char buf[256];

    for(int i=1; i<15;i++) {

    sprintf(buf, "grossini_dance_gray_%02d.png", i);

    CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(buf);

    animation->addSpriteFrame(frame);

    }

     

    CCSpriteBatchNode

    CCSpriteFrameCache::sharedSpriteFrameCache()->

    addSpriteFramesWithFile("grossini_gray.plist");


    CCSpriteBatchNode *sprBatch = CCSpriteBatchNode::create("grossini_gray.png");

    this->addChild(sprBatch);


    CCSprite *spr = CCSprite::createWithSpriteFrameName("grossini_dance_gray_01.png");

    spr->setPosition(ccp(i*10, i*10));

     

    sprBatch->addChild(spr);

     

    CCParallaxNode

    1. Process

    CCLayer -> CCParallaxNode -> CCSprite


    - CCLayer 생성

    CCLayer *bgLayer = CCLayer::create();

    this->addChild(bgLayer);


    - Parallax 생성

    CCParallaxNode *node = CCParallaxNode::create();

    bgLayer->addChild(node);


    - CCSprite 생성후 addChild

    CCSprite *sprBG = CCSprite::create("bg.png");

    sprBG->setAnchorPoint(ccp(0, 0));

    node->addChild(sprBG, 1, ccp(1, 0), ccp(0, 0));

    // CCNode(CCSprite), Z-order, parallaxRatio(이동속도 비율), PositionOffset(위치)

     

     

     

    'Pause @ > Cocos2d-x2' 카테고리의 다른 글

    cocos2d-x 정리(2)  (0) 2013.07.13
    cocos2d-x CCArray  (0) 2013.07.07
    cocos2d-x 메뉴전환정리  (1) 2013.07.07
    cocos2d-x 프로젝트1 정리  (0) 2013.07.03
    cocos2d-x 프로젝트 1  (0) 2013.07.03
Designed by Tistory.