배경이미지 스크롤시 끊김 문제 해결
h++)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #ifndef test252_hpp #define test252_hpp #include "cocos2d.h" USING_NS_CC; class Test : public cocos2d::Layer { public: static cocos2d::Scene* createScene(); virtual bool init(); // implement the "static create()" method manually CREATE_FUNC(Test); void initBG(); //배경 }; #endif | cs |
c++)
가로크기만큼 배경이미지를 오른쪽 끝에 추가한다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include "test252.hpp" USING_NS_CC; Scene* Test::createScene() { auto scene = Scene::create(); auto layer = Test::create(); scene->addChild(layer); return scene; } bool Test::init() { if ( !Layer::init()) { return false; } initBG(); return true; } //배경그리기 void Test::initBG(){ //배경레이어를 추가한다 auto bgLayer = Layer::create(); this->addChild(bgLayer); //배경이미지를 배경레이어에 추가한다 auto sprite = Sprite::create("background2.png"); sprite->setAnchorPoint(Point::ZERO); sprite->setPosition(Point::ZERO); bgLayer->addChild(sprite); //가로크기만큼 추가 스프라이트 이미지 객체를 만들어서 배경레이어 오른쪽 끝에 추가한다 auto sprite1 = Sprite::create("background2.png", Rect(0, 0, 480, 320)); sprite1->setAnchorPoint(Point::ZERO); sprite1->setPosition(Point(2000,0)); bgLayer->addChild(sprite1); //이미지의 가로크기인 2500만큼 왼쪽으로 이동한다 auto action0 = MoveBy::create(10.0, Point(-2000,0)); //이미지의 오른쪽 끝에 위치하면 원래 위치로 이동한다 auto action1 = Place::create(Point::ZERO); //2개의 액션을 묶는다 auto action2 = Sequence::create(action0, action1, NULL); //묶은 액션을 반복한다 auto action3 = RepeatForever::create(action2); //배경레이어에 애니메이션 적용한다 bgLayer->runAction(action3); } | cs |
결과
오른쪽 긑에 도달하여도 배경이미지가 끊기지 않는다
'IT > - 프로그래밍' 카테고리의 다른 글
Cocos ParallaxNode를 이용한 배경스크롤 구현하기 (0) | 2017.03.16 |
---|---|
Cocos 여러이미지로 배경 스크롤하기 (0) | 2017.03.15 |
Cocos 배경이미지 스크롤하기 (0) | 2017.03.13 |
Cocos 프로젝트 생성, 안드로이드 컴파일, 실행 (0) | 2017.03.12 |
Cocos jni/../../Classes/AppDelegate.cpp:77: error: undefined reference to 'Test401::createScene()' (0) | 2017.03.12 |