버전 2.2.1
시작하세요 교재 311
#include "HelloWorldScene.h"
USING_NS_CC;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
//화면 크기 가져오기
//기존 코드
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
//추가한 코드
winSize = CCDirector::sharedDirector()->getWinSize();
tmap = CCTMXTiledMap::create("TestDesert.tmx");
this->addChild(tmap, 0 , 11);
//Ojbects라는 이름의 오브젝트 레이어 객체 가져오기
CCTMXObjectGroup* objects = tmap->objectGroupNamed("Objects");
//오브젝트 레이어에서 spawnPoint라 지정한 속성값 읽어오기
CCDictionary* spawnPoint = objects->objectNamed("SpawnPoint");
int x = ((CCString*)spawnPoint -> objectForKey("x"))->intValue();
int y = ((CCString*)spawnPoint -> objectForKey("y"))->intValue();
//가져온 정보(위치)에 드래곤 생성하기
dragonPosition = ccp(x,y);
this->createDragon();
return true;
}
void HelloWorld::createDragon(){
//리소스를 texture로 등록하기
CCTexture2D *texture = CCTextureCache::sharedTextureCache() -> addImage("dragon_animation.png");
//애니메이션 생성하고 애니메이션 주기 0.1초로 세팅하기?
CCAnimation *animation = CCAnimation::create();
animation->setDelayPerUnit(0.1);
//애니메이션에 texture이미지 더하는데 frame 방식(batch)으로 하기, 이미지가 가로 몇개 세로 몇개 인지에 따라서 ccrectmake 설정해주기
for (int i=0; i<6; i++) {
int index = i%4;
int rowIndex = i/4;
animation->addSpriteFrameWithTexture(texture, CCRectMake(index*130, rowIndex*140, 130, 140));
}
dragon = CCSprite::createWithTexture(texture, CCRectMake(0, 0, 130, 140));
dragon->setPosition(dragonPosition);
this->addChild(dragon);
//드래곤 방향을 바꿔준다
dragon->setFlipX(true);
//드래곤 사이즈 줄여준다.
dragon->setScale(0.5);
//드래곤 애니메이션
CCAnimate *animate = CCAnimate::create(animation);
CCAction* rep = CCRepeatForever::create(animate);
dragon->runAction(rep);
}
---------
집 띄울 때는 공사중인 집 모양 스프라이트 설정해놓고
animation->setDelayPerUnit(4.0);
이런식으로 하면 되겠다
오늘 문득 든 생각인데, 코딩하는 것도 수학 공부하는거랑 비슷하다고 생각이 들었다.
남이 풀이해준거는 아무 소용없고,
남이 풀이해준걸로 한번 공부한 후에 집에 가서 곰곰히 식을 하나 하나 짚어가면서
복습을 해야 내 스킬이 될 것 같다.
오늘부터라도 날마다 코딩한 것을 집에 가져가서 프린트를 해서 읽든, 타블렛 펜으로 표시해가며 읽든 해야겠다.
'개발일지 > cocos2d-x' 카테고리의 다른 글
나중에 살펴볼 함수들 (0) | 2014.02.13 |
---|---|
동적으로 파일 가져오기 (0) | 2014.02.10 |
3.0 터(퍼옴) (0) | 2014.01.16 |
3.0 beta 프로젝트 생성 방법 (0) | 2014.01.16 |
공통헤더 (0) | 2014.01.14 |