VioletaBabel
14일 : 애니메이션 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //Character.h bool Character::init() { FileUtils::getInstance()->addSearchPate("res"); //이걸 하면 이제 경로의 res를 입력 안해도 된다. Rect rt(0,0,88,73);//x,y,이미지사이즈 SpriteFrame* pSpriteFrame1 = SpriteFrame::create("파일이름1",rt); SpriteFrame* pSpriteFrame2 = SpriteFrame::create("파일이름2",rt); SpriteFrame* pSpriteFrame3 = SpriteFrame::create("파일이름3",rt); Animation* ani = Animation::create(); ani->addSpriteFrame(pSpriteFrame1); ani->addSpriteFrame(pSpriteFrame2); ani->addSpriteFrame(pSpriteFrame3); ani->setLoops(true); // 시작 ani->setDelayPerUnit(0.016f); //1프레임당 바뀌게 함(너무 빠르지만 일단 테스트니까) Animate* animate = Animate::create(ani); // 애니메이트라는 액션을 만들어준다. Sprite* pChar = Sprite::create("파일이름1"); // 애니메이트를 실행해 줄 스프라이트를 만든다. RepeatForever* pRF = RepeatForever::create(animate); //Repeat라는 함수도 따로 있다. 이건 무한반복 pChar->runAction(pRF);//pChar->StopAllAction(); // 이건 모든 액션 중지 addChild(pChar); } | cs |
1 2 3 4 5 6 7 | //GameLayer.cpp #include "Character.h" //... Character* pChar = Character::create(); pChar->SetPosition(600,600); addChild(pChar); | cs |
'BCA > 2. Cocos2d-x' 카테고리의 다른 글
16일 : 파일 입출력 - 바이너리 저장, JSON (0) | 2018.03.02 |
---|---|
15일 : 파일 입출력, 오디오, 러닝게임 완성 (0) | 2018.02.28 |
13일 : 복습 겸 아주 자잘한 팁 (0) | 2018.02.26 |
12일 : 플래피 버드 완성하기 (0) | 2018.02.23 |
11일 : 터치, 업데이트, 배경, 장애물 등장 (0) | 2018.02.22 |
Comments