'잡다한것들전부/Basic Concepts'에 해당되는 글 7건

  1. 2014.01.09 [Transitions] Scene의 장면전환 효과
  2. 2014.01.09 [Effects] cocos2-dx 이펙트에 대해서 알아보자!
  3. 2014.01.09 [Basic Concepts] Director, Scene, Layer, Sprite 개념 정리
  4. 2014.01.09 [Coordinate System] cocos2d-x 좌표 시스템
  5. 2014.01.08 [Animations] cocos2d-x 에니메이션 적용하기
  6. 2014.01.08 [Action] cocos2d-x 액션 사용법
  7. 2013.09.23 cocos2d-x 기본 컨셉

[Transitions] Scene의 장면전환 효과

|

Transitions

소개

cocos2d-x의 멋진 특징중 하나인 두개의 씬 사이에 장면을 전환하는 효과입니다. 예를들어서(wipe, fade, zoom, and split등)
Transition Sceneclass은 CocosNode와 Layer로 부터 파생되어 나왔습니다.
일반적으로 transition scene은 새로운 scene로 넘어가기 전에 장면 전환 효과를 수행하게 됩니다.

Create transition

첫번째 인자의 시간은 트랜지션를위한 시간 (초)입니다. 다음과 같은 장면 전환을 적용하려면 구문은 다음과 같습니다

1CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5,newScene));


일부 트랜지션은 사용자 지정 매개 변수 (들)을 가지고 있습니다. 예를 들어, FadeTransition 매개 변수로 페이드 색깔이있다.
static CCTransitionFade* create(float duration,CCScene* scene, const ccColor3B& color);

장면 전환을 하는 것은 매우 쉽습니다.

 1CCScene *s = SecondPage::scene();
 2
 3//CCTransitionProgressRadialCW,CCTransitionProgressRadialCCW,CCTransitionCrossFade需要以下设置
 4//CCConfiguration::sharedconfiguration()->getGlesVersion<=GLES_VER_1_0
 5
 6//启动摄像机测试景深,只有CCTransitionPageTurn才需要
 7CCDirector::sharedDirector()->setDepthTest(true);
 8
 9//false为下一页,true为上一页
10CCTransitionScene *transition = CCTransitionPageTurn::create(3.0f, s, false);

“page turn” 효과를 사용하면 이것은 책을 넘기는 효과 처럼 보인다.

트랜잭션의 종류



class  CCTransitionEaseScene
 CCTransitionEaseScene can ease the actions of the scene protocol. More...
 
class  CCTransitionScene
 Base class for CCTransition scenes. More...
 
class  CCTransitionSceneOriented
 A CCTransition that supports orientation like. More...
 
class  CCTransitionRotoZoom
 CCTransitionRotoZoom: Rotate and zoom out the outgoing scene, and then rotate and zoom in the incoming.More...
 
class  CCTransitionJumpZoom
 CCTransitionJumpZoom: Zoom out and jump the outgoing scene, and then jump and zoom in the incoming.More...
 
class  CCTransitionMoveInL
 CCTransitionMoveInL: Move in from to the left the incoming scene. More...
 
class  CCTransitionMoveInR
 CCTransitionMoveInR: Move in from to the right the incoming scene. More...
 
class  CCTransitionMoveInT
 CCTransitionMoveInT: Move in from to the top the incoming scene. More...
 
class  CCTransitionMoveInB
 CCTransitionMoveInB: Move in from to the bottom the incoming scene. More...
 
class  CCTransitionSlideInL
 CCTransitionSlideInL: Slide in the incoming scene from the left border. More...
 
class  CCTransitionSlideInR
 CCTransitionSlideInR: Slide in the incoming scene from the right border. More...
 
class  CCTransitionSlideInB
 CCTransitionSlideInB: Slide in the incoming scene from the bottom border. More...
 
class  CCTransitionSlideInT
 CCTransitionSlideInT: Slide in the incoming scene from the top border. More...
 
class  CCTransitionShrinkGrow
 Shrink the outgoing scene while grow the incoming scene. More...
 
class  CCTransitionFlipX
 CCTransitionFlipX: Flips the screen horizontally. More...
 
class  CCTransitionFlipY
 CCTransitionFlipY: Flips the screen vertically. More...
 
class  CCTransitionFlipAngular
 CCTransitionFlipAngular: Flips the screen half horizontally and half vertically. More...
 
class  CCTransitionZoomFlipX
 CCTransitionZoomFlipX: Flips the screen horizontally doing a zoom out/in The front face is the outgoing scene and the back face is the incoming scene. More...
 
class  CCTransitionZoomFlipY
 CCTransitionZoomFlipY: Flips the screen vertically doing a little zooming out/in The front face is the outgoing scene and the back face is the incoming scene. More...
 
class  CCTransitionZoomFlipAngular
 CCTransitionZoomFlipAngular: Flips the screen half horizontally and half vertically doing a little zooming out/in. More...
 
class  CCTransitionFade
 CCTransitionFade: Fade out the outgoing scene and then fade in the incoming scene. More...
 
class  CCTransitionCrossFade
 CCTransitionCrossFade: Cross fades two scenes using the CCRenderTexture object. More...
 
class  CCTransitionTurnOffTiles
 CCTransitionTurnOffTiles: Turn off the tiles of the outgoing scene in random order. More...
 
class  CCTransitionSplitCols
 CCTransitionSplitCols: The odd columns goes upwards while the even columns goes downwards. More...
 
class  CCTransitionSplitRows
 CCTransitionSplitRows: The odd rows goes to the left while the even rows goes to the right. More...
 
class  CCTransitionFadeTR
 CCTransitionFadeTR: Fade the tiles of the outgoing scene from the left-bottom corner the to top-right corner.More...
 
class  CCTransitionFadeBL
 CCTransitionFadeBL: Fade the tiles of the outgoing scene from the top-right corner to the bottom-left corner.More...
 
class  CCTransitionFadeUp
 CCTransitionFadeUp: Fade the tiles of the outgoing scene from the bottom to the top. More...
 
class  CCTransitionFadeDown
 CCTransitionFadeDown: Fade the tiles of the outgoing scene from the top to the bottom. More...
 
class  CCTransitionPageTurn
 A transition which peels back the bottom right hand corner of a scene to transition to the scene beneath it simulating a page turn. More...
 
class  CCTransitionProgress
 
class  CCTransitionProgressRadialCCW
 CCTransitionRadialCCW transition. More...
 
class  CCTransitionProgressRadialCW
 CCTransitionRadialCW transition. More...
 
class  CCTransitionProgressHorizontal
 CCTransitionProgressHorizontal transition. More...
 
class  CCTransitionProgressVertical
 
class  CCTransitionProgressInOut
 
class  CCTransitionProgressOutIn
 




Trackback 0 And Comment 0

[Effects] cocos2-dx 이펙트에 대해서 알아보자!

|

Effects

소개.

Effects는 action의 한 종류이다.. 투명도를 조절하거나 회전 혹은 크기 변경 등 일반 속성을 수정할수있다, grid라는 속성을 수정합니다.

grid 속성은 matrix와 비슷한데, it is a network of lines that cross each other to form a series of squares or rectangles.

These special actions render any CocosNode object (Layer, Scene, Sprite, etc.) into the grid, and you can transform the grid by moving its vertices.

2가지 종류의 grid가 있는데 하나는 타일 그리드이고 나머지 하나는 non-tiled 그리드입니다. 

차이점은 타일 그리드는 각각의 타일이 정점으로 구성되는데 반해  non-titled그리드는 4개의 정점으로 구성됩니다.

(non-tiled) grid:
 

타일그리드
 

사용하는 방법

다른 Action과 마찬가지로 runAction에서 실행됩니다.

1// Create an sprite
2CCSprite* grossini = CCSprite::create("grossini.png");
3grossini->runAction(CCLiquid::create(4, 20, ccg(10,10), 5));


Liquid,다른 grid 와 마찬가지로 grid 피라메터를 받는다. 원하는 그리드의 크기를 증가시킴으로써 이펙트의 품질을 조정할 수있다. 그러나 FPS가 떨어질수있음..

당신이 다른 어떤 Action처럼 취급 할 수 있도록 효과 IntervalAction 작업입니다. 예를 들면 :

1// create a Lens3D action
2CCActionInterval* lens = CCLens3D::create(ccp(240,160),240,ccg(15,10),8);
3
4// create a Waved3D action
5CCActionInterval* waves = CCWaves3D::create(18,80,ccg(15,10),10);
6
7// create a sequence an repeat it forever
8grossini->runAction(CCRepeatForever::create((CCSequence*)CCSequence::create(waves, lens, NULL ) ) );


(non-tiled) 액션

Shaky3D  Waves3D  FlipX3D  FlipY3D  
Lens3D  Liquid  Waves  Twirl  
Ripple3D  


타일 그리드 액션

ShakyTiles3D  ShatteredTiles3D  ShuffleTiles  FadeOutTRTiles  
FadeOutBLTiles  FadeOutUpTiles  FadeOutDownTiles  TurnOffTiles  
WavesTiles3D Sort_descJumpTiles3D  SplitRows  SplitCols  

References


Trackback 0 And Comment 0

[Basic Concepts] Director, Scene, Layer, Sprite 개념 정리

|

Director Scene Layer and Sprite

Scenes

Cocos2d-x에서 씬은 하나의 게임을 그 기능과 성격에 따라 여러 부분으로 나눌 때 사용하는 개념이다. 어떤 개발자들은 씬을 스크린이나 스테이지라고도 부르는데 모두 같은 개념이다. 

씬은 게임의 흐름으로부터 매우 독립적이다. 보통 여러 개의 씬이 모여 하나의 게임을 이루는데 한순간에 하나의 씬만 활성화된다. 각각의 씬은 서로 연결될 수 있기는 하지만 독립된 프로그램으로 생각해도 무방하다.

예들 들어, 만들어진 하나의 게임은 인트로(Intro), 메뉴(Menu), 레벨(Level) 1, 컷씬(Cutscene) 1, 레벨(Level) 2, 승리 결과 화면(Winning cutscene), 패배 결과 화면(Losing cutscene), 랭킹(High score) 등의 씬을 갖게 된다. 

좀더 자세히 설명하면, 게임이 시작되고 인트로 씬이 끝나면 메뉴 씬으로 이동한다. 다음으로 레벨 1 씬으로 전환된 뒤 컷씬이 종료되면, 사용자의 승패 여부에 따라 승리 또는 패배 결과 화면으로 씬이 전환된다. 

cocos2d CCScene 은 하나이상의 CCNode로 구성되며 Scene의 자식으로 더해집니다.

CCLayer 및 CCSprite(CCNode를 상속받는)는 모양과 동작을 Scene에 더해준다. 

일반적으로, CCLayer와 CCScene의 빈 인스턴스로 너의 Scene은 구성됩니다.

CCNodes로 다른 그래픽과 게임 객체를 구현하고 사용자가 만든 CCLayer에 자식으로 추가합니다.

Scene는 CCNode의 하위 클래스이므로, 이들은 수동 또는 CCActions을 사용하여 변환 될 수있다. 자세한 내용은 작업을 참조하십시오.

CCTransitionScene 클래스로 구현 전환이라고 CCScene 클래스의 가족이 있습니다. 그래서, 예를 들어 퇴색 측면에서의 슬라이딩, 그리고 - 다른 하나의 장면에서 전환 할 때 이러한 특수 전환 효과를 만들 수 있습니다.


Director

CCDirector는 싱글톤 패턴이며 활성화된 Scene를 알고있으며 현재 Scene를 교체할수있으며, 스택방식으로 push 및 pop으로 Scene를 관리할수있습니다.
그럴 경우 CCDirector은 이전 Scene를 일시중지하지만 메모리에 유지시킵니다. 만약 나중에 너가 맨위 Scene를 pop하면 일시중지된 Scene로 다시 시작합니다.

CCDirector는 OpenGL을 ES를 초기화 할 책임이 있습니다.


Layers

CCLayer가 터치 이벤트를 처리할수있는 CCNode입니다. CCLayer 자체를 그리는 방법을 아는 플레이어가 그들 뒤에 다른 레이어를 볼 수 있도록 반투명 수 있습니다. CCLayers은 게임의 모양과 동작을 정의하는 데 매우 유용합니다, 그래서 당신은 당신이 필요로 할 CCLayer의 서브 클래스를 코딩 프로그래밍 많은 시간을 소비 할 것으로 예상해야한다.

TCCLayer는 터치 이벤트 핸들러를 정의하는 곳이다.터치 이벤트 (ccTouchBegan, ccTouchMoved, ccTouchEnded 또는 ccTouchCancelled) 중 하나를 처리하는 방법을 구현함으로써 CCLayer는 플레이어의 상호 작용에 반응 할 수있다. 일부 Layer은 이벤트를 포착하고 그것을 받아 들일 때까지 이러한 터치 이벤트는, 앞에서 뒤로, 장면 내의 모든 계층에 전파됩니다.

복잡한 응용 프로그램을 사용자 정의 CCLayer 서브 클래스를 정의 할 필요가 동안,적인 Cocos2D는 미리 정의 된 여러 레이어를 제공합니다. 몇 가지 예는 CCMenu (간단한 메뉴 Layer), CCColorLayer (색깔을 그릴수 있는 Layer), 그리고 CCLayerMultiplex (CCLayer를 하나만 쓰고 싶을때) 등이 있습니다.

레이어 CCSprites, CCLabels, 심지어 다른 CCLayer 개체를 포함하여, 아이로 어떤 CCNode를 포함 할 수 있습니다. 층 CCNode의 하위 클래스이므로, 이들은 수동 또는 CCActions을 사용하여 변환 될 수있다. 자세한 내용은 작업을 참조하십시오.

Multiple Layers Example:

 1    CCLayerGradient* layer1 = CCLayerGradient::create(ccc4(255, 0, 0, 255), ccc4(255, 0, 255, 255));
 2    layer1->setContentSize(CCSizeMake(80, 80));
 3    layer1->setPosition(ccp(50,50));
 4    addChild(layer1);
 5
 6    CCLayerGradient* layer2 = CCLayerGradient::create(ccc4(0, 0, 0, 127), ccc4(255, 255, 255, 127));
 7    layer2->setContentSize(CCSizeMake(80, 80));
 8    layer2->setPosition(ccp(100,90));
 9    addChild(layer2);
10
11    CCLayerGradient* layer3 = CCLayerGradient::create();
12    layer3->setContentSize(CCSizeMake(80, 80));
13    layer3->setPosition(ccp(150,140));
14    layer3->setStartColor(ccc3(255, 0, 0));
15    layer3->setEndColor(ccc3(255, 0, 255));
16    layer3->setStartOpacity(255);
17    layer3->setEndOpacity(255);
18    ccBlendFunc blend;
19    blend.src = GL_SRC_ALPHA;
20    blend.dst = GL_ONE_MINUS_SRC_ALPHA;
21    layer3->setBlendFunc(blend);
22    addChild(layer3);

Sprites

Cocos2D의 CCSprite는 다른 게임 엔진에서 찾을 스프라이트 유사합니다. 그것은, 회전, 이동 조정, 애니메이션 및 기타 변환을받을 수있는 2D 이미지입니다. (CCSprite 클래스를 사용하여 구현) 스프라이트는 어린이와 같은 다른 스프라이트를 할 수 있습니다. 부모가 변형 될 때, 모든 아이들은 물론 변환됩니다. 스프라이트 CCNode의 하위 클래스이므로, 이들은 수동 또는 CCActions을 사용하여 변환 될 수있다. 자세한 내용은 작업을 참조하십시오.

Trackback 0 And Comment 0

[Coordinate System] cocos2d-x 좌표 시스템

|

좌표 시스템

기존과 다른 좌표 시스템을 도입.Introduction of Different Coordinate Systems


직교 좌표 시스템(데카르트 좌표)

너는 아마 기하학 수업에 사용되는 좌표를 알고 있을 것이다.

모바일에서는 보통 3가지 정도의 좌표 시스템이 있다.

UI 좌표 시스템

안드로이드나 아이폰에서의 좌표 시스템

  • 좌측 상단이 (0,0) 이다.
  • X 축은 왼쪽에서부터 오른쪽으로 갈수록 증가한다.
  • Y 축은 화면 상단에서 부터 아래로 내려 갈수록 증가한다.

looks like this

Direct3D 좌표 시스템

DirectX 에서는 왼손좌표계를 사용한다.


OpenGL 그리고 Cocos2d 의 좌표시스템

openGL과 cocos2d는 오른손 좌표계를 사용한다.


우리는 2d게임에서 오직 x,y축만 사용합니다. 

  • 좌측 하단이 (0,0) 좌표이고 오른손 좌표계를 사용합니다.
  • X 축은 왼쪽에서부터 오른쪽으로 갈수록 증가합니다.;
  • Y 축은 아래부터 시작하며 위로 갈수록 증가합니다.

좌표 시스템을 좀더 이해하기 쉽도록 아래 사진이 준비되어있음

다이렉트x나 일반적 ui시스템과 다른 좌표시스템이다.


Parent and Childrens

CCNode를 상속받는 모든 클래스는 anchorPoint 속성을 가지고 있습니다.

CCNode를 상속받는 객체를 그릴때(sprite, layer, 기타등등) , cocos2d-x는 anchorpoint와 position를 결합합니다. 또한 물체를 회전할때 Anchorpoint를 기준으로 회전하게됩니다.

우리는 회색배경의 부모 클래스를 만들었고 파란색 배경의 자식클래스를 만들었습니다. 부모의 좌표는((100,100)이고 자식의  anchor point는 중앙입니다.

 1    CCSprite* parent = CCSprite::create("parent.png");
 2    parent->setAnchorPoint(ccp(0, 0));// Anchor Point
 3    parent->setPosition(ccp(100, 100));
 4    parent->setAnchorPoint(ccp(0, 0));
 5    addChild(parent);
 6
 7    //create child 
 8    CCSprite* child = CCSprite::create("child.png");
 9    child->setAnchorPoint(ccp(0.5, 0.5));
10    child->setPosition(ccp(0, 0));
11    parent->addChild(child);//add child sprite into parent sprite.


자식의 위치가 (0,0) 이고 부모의 위치가 (100,100)일때 아래 그림과 같다.

Anchor Point

앵커 포인트의 위치와 개체를 회전 모두에 사용됩니다.앵커 포인트의 좌표는 일반적으로 개체 내 지점에 해당하는 상대 좌표입니다. 예를 들어, 앵커 포인트 CCP (0.5, 0.5)는 객체의 중심에 대응한다.물체의 위치를 설정할 때, 객체는 앵커 포인트로 setPosition () 호출에 지정된 좌표에있을 것이다되도록 위치된다.객체를 회전시킬 때 마찬가지로, 그 기준점에 대해 회전된다.

예를 들어 sprite가 앵커포인트 와 위치가 0,0일때

그 결과 sprite는 하단 왼쪽 모서리에 배치됩니다.

1// create sprite
2CCSprite* sprite = CCSprite::create("bottomleft.png");
3sprite->setAnchorPoint(ccp(0, 0));// Anchor Point
4sprite->setPosition(ccp(0,0));
5addChild(sprite);


예를 들어 sprite가 앵커포인트는 (0.5,0.5) 이고 위치가 0,0일때

1// create sprite
2CCSprite* sprite = CCSprite::create("center.png");
3sprite->setAnchorPoint(ccp(0.5, 0.5));// Anchor Point
4sprite->setPosition(ccp(0,0));
5addChild(sprite);


위와 같이 sprite의 중심이 좌표 0,0에 위치합니다. 앵커포인트는 화소값이 아닌 노드에 상대적인 크기입니다. 0~1 까지 존재함.

getVisibleSize, getVisibleOrigin vs getWinSize

VisibleSize 은 OpenGL상에서 보여지는 크기를 리턴합니다.이 값은  CCEGLView::setDesignResolutionSize()이 함수를 호출하지 않으면 getWinSize와 같습니다.

getVisibleOrigin은 OpenGL상에서 보이는 x,y의 좌표를 반환합니다.


How to convert co-ordinates

convertToNodeSpace:

convertToNodeSpace will be used in, 예를 들어 타일 기반 게임에서, 너가 큰 맵을 가지고 있을때. convertToNodeSpace는 너의 OpenGL 터치 좌표를 큰맵에 있는 좌표계를 기준으로 변형해줍니다.

Example:

다음그림은 보여줍니다. node1의 앵커포인트(0,0)이고 node2의 앵커포인트(1,1)입니다.

우리가  호출하면CCPoint point = node1->convertToNodeSpace(node2->getPosition()); convert node2의 스크린 좌표계는 node1의 좌표계를 기준으로 구해지게 되며 그 결과 node2 의 좌표는 (-25,-60) 이 됩니다.

convertToWorldSpace:

convertToWorldSpace(const CCPoint& nodePoint) coordinates.convertToWorldSpace 항상 우리의 스프라이트의 화면 위치를 반환합니다 당신은 당신의 스프라이트에 탭을 캡처 할하지만 레이어를 확장 / 이동해야하는 경우 매우 유용 할 수 있습니다 화면에 노드 좌표입니다 변환합니다.


일반적으로, 자식 노드의 위치와 부모 노드 호출이 방법은 결과로 아이의 세계의받은 위치를 반환합니다. 호출자가 부모가 아닌 경우이 메서드를 호출 아무 의미도하지 않습니다 것 같다 ...

Example:

1CCPoint point = node1->convertToWorldSpace(node2->getPosition()); 

위의 코드는 화면의 좌표로 노드 2의 좌표를 변환합니다.

예를 들어, 노드 1의 앵커 위치 (0, 0)이 화면에 필요없는 노드 1의 왼쪽 하단 모서리, 그러나되는 경우. 이 화면에 점의 (-5, -20) 좌표 노드 1에 대해 (이 경우)가 (15, 20입니다) (-20, -5)는 노드 2의 위치를 ​​변환합니다.결과는 다음 그림에서 보여줍니다

convertToWorldSpaceAR,

convertToWorldSpaceAR 지점을 고정하는 relatevely 위치를 반환합니다, 그래서 우리의 장면 경우 - 루트 층은 CCP의 앵커 포인트 (0.5F, 0.5F)이 - 기본, convertToWorldSpaceAR은 상대적으로 화면 중앙에 위치를 반환해야합니다.

convertToNodeSpaceAR -. convertToWorldSpaceAR와 동일한 논리

Sample code:

 1
 2CCSprite *sprite1 = CCSprite::create("CloseNormal.png");
 3
 4sprite1->setPosition(ccp(20,40));
 5
 6sprite1->setAnchorPoint(ccp(0,0));
 7
 8this->addChild(sprite1);
 9
10CCSprite *sprite2 = CCSprite::create("CloseNormal.png");
11
12sprite2->setPosition(ccp(-5,-20));
13
14sprite2->setAnchorPoint(ccp(1,1));
15
16this->addChild(sprite2);
17
18CCPoint point1 = sprite1->convertToNodeSpace(sprite2->getPosition());
19
20CCPoint point2 = sprite1->convertToWorldSpace(sprite2->getPosition());
21
22CCPoint point3 = sprite1->convertToNodeSpaceAR(sprite2->getPosition());
23
24CCPoint point4 = sprite1->convertToWorldSpaceAR(sprite2->getPosition());
25
26CCLog("position = (%f,%f)",point1.x,point1.y);
27
28CCLog("position = (%f,%f)",point2.x,point2.y);
29
30CCLog("position = (%f,%f)",point3.x,point3.y);
31
32CCLog("position = (%f,%f)",point4.x,point4.y);
33

Result:

 1
 2position = (-25.000000,-60.000000)
 3
 4position = (15.000000,20.000000)
 5
 6position = (-25.000000,-60.000000)
 7
 8position = (15.000000,20.000000)
 9



Trackback 0 And Comment 0

[Animations] cocos2d-x 에니메이션 적용하기

|

Animations

Frame Animation

아래와 같이 여러개의 이미지 파일로 애니메이션을 만들 수 있다.

 1CCAnimation *animation = CCAnimation::create();
 2
 3// load image file from local file system to CCSpriteFrame, then add into CCAnimation
 4for (int i = 1; i < 15; i++)
 5{
 6    char szImageFileName[128] = {0};
 7    sprintf(szImageFileName, "Images/grossini_dance_%02d.png", i);
 8    animation->addSpriteFrameWithFileName(szImageFileName);  
 9}
10
11animation->setDelayPerUnit(2.8f / 14.0f); // 14개의 이미지를 2.8초 동안 보여줄때 각 프레임 간격.
12animation->setRestoreOriginalFrame(true); // 14개의 이미지를 돌린다음에 다시 1프레임으로 돌아간다
13
14CCAnimate *action = CCAnimate::create(animation);
15sprite->runAction(action);  // run action on sprite object

Note that CCAnimation is composed by sprite frames, delay time per frame, durations etc, it's a pack of "data". While CCAnimate is an action, it is created base on CCAnimation object.


Sprite Sheet Animation

위 에니메이션 방식은 이해하기 쉽지만, 실제 게임에서는 잘 사용되지 않습니다, 대신 스프라이트 시트 에니메이션을 일반적으로 사용합니다.

다음은 일반적인 스프라이트 시트입니다. 그것은 애니메이션 스프라이트 프레임 시퀀스이거나 같은 장면에서 사용될 이미지 팩이 될 수있다.


Creating from .png and .plist file

CCSpriteSheet 는 1.x  버전이나 그 이하 버전에서 사용되었지만. 2.x 이상 버전에서는 CCSpriteBatchNode 를 사용한다.
CCSpriteBatchNode는 사실상 스프라이트 프레임 이미지 텍스쳐 이다.  너는 반드시 Scene에 이것을 add해야됩니다. 이것은 add를 해도 실제로는 그려지지 않지만
렌더링 파이프 라인의 일부가 됩니다.
예를들면:
1CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create("animations/grossini.png");

그다음에 너는 CCSpriteFrameCache 싱글톤 클래스를 사용하여 plist 파일을 로드합니다.

1CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
2cache->addSpriteFramesWithFile("animations/grossini.plist"); 

CCSpriteBatchNode와 프레임이로드 및 스프라이트 시트를 장면에 추가되면, 당신은 "createWithSpriteFrameName"방법을 사용하고, CCSpriteBatchNode  자식으로 추가하여 이러한 프레임을 사용 스프라이트를 만들 수 있습니다 :

1m_pSprite1 = CCSprite::createWithSpriteFrameName("grossini_dance_01.png");
2spritebatch->addChild(m_pSprite1);
3addChild(spritebatch);

createWithSpriteFrameName

 이 메서드는  posit 파일을 이용하여 해당되는 사각형 영역을 찾을수 있습니다.

CCArray 오브젝트에 에니메이션 프레임을 더합니다. 에니메이션 사이즈는 14 프레임이고 우리는 이것을 사용하면 됩니다.

 1CCArray* animFrames = CCArray::createWithCapacity(15);
 2
 3char str[100] = {0};
 4
 5for(int i = 1; i < 15; i++) 
 6{
 7    sprintf(str, "grossini_dance_%02d.png", i);
 8    CCSpriteFrame* frame = cache->spriteFrameByName( str );
 9    animFrames->addObject(frame);
10}

마지막으로 우리는 CCAnimate 만들고 CCSprite에 runAction을 해줍니다. CCRepeatForever를 이용해서 무한으로 에니메이션을 돌릴수 있습니다.

1CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3f);
2m_pSprite1->runAction( CCRepeatForever::create( CCAnimate::create(animation) ) );


File animation

CCAnimationCache can load a xml/plist file which well describes the batch node, sprite frame names and their rectangles. The interfaces are much easier to use.

1CCAnimationCache *cache = CCAnimationCache::sharedAnimationCache(); // "caches" are always singletons in cocos2d
2cache->addAnimationsWithFile("animations/animations-2.plist");
3CCAnimation animation = cache->animationByName("dance_1");  // I apologize for this method name, it should be getAnimationByName(..) in future versions
4CCAnimate animate = CCAnimate::create(animation);  // Don't confused between CCAnimation and CCAnimate :)
5sprite->runAction(animate);


Trackback 0 And Comment 0

[Action] cocos2d-x 액션 사용법

|


Actions



Actions 클래스는 CCNode 를 상속받는 모든 객체에 명령을 부여합니다. 액션은  오브젝트의 위치, 회전, 크기 기타등등 값들을 수정합니다

일정기간동안 수정하는 작업이면 -> CCIntervalAction actions 그렇지 않으면 -> CCInstantAction 입니다.

 예를들면 CCMoveBy는 일정기간동안 수정합니다. CCIntervalAction 액션입니다.

액션의 사용 예:

1// 스프라이트가 오른족으로  50 픽셀, 밑으로 10 픽셀 움직임 2초동안.
2CCActionInterval*  actionBy = CCMoveBy::create(2, ccp(50,10));


가속 관련된 액션들 (점점 빨라지거나 느려지는등)

  • CCEaseIn
  • CCEaseOut
  • CCEaseInOut
  • CCSpeed
    Etc. (See the ActionsEaseTest.cpp example for more info)

CCActionManager를 사용하면 중간에 액션을 일시정지 하고 재시작 할수도있다.(해당객체의)

1// Pause actions
2CCDirector *director = CCDirector::sharedDirector();
3m_pPausedTargets = director->getActionManager()->pauseAllRunningActions();
4// resume actions
5CCDirector *director = CCDirector::sharedDirector();
6director->getActionManager()->resumeTargets(m_pPausedTargets);

Basic Actions

Basic actions are the ones that modify basic properties like:

Position(위치수정관련)

CCMoveBy
CCMoveTo
CCJumpBy
CCJumpTo
CCBezierBy
CCBezierTo
CCPlace

Scale(크기수정관련)

CCScaleBy
CCScaleTo

Rotation(회전)

CCRotateBy
CCRotateTo

Visibility(보이는거)

CCShow
CCHide
CCBlink
CCToggleVisibility

Opacity(알파값)

CCFadeIn
CCFadeOut
CCFadeTo

Color(색깔)

CCTintBy
CCTintTo

Example:

1CCSprite *sprite = CCSprite::create("Images/grossini.png");
2sprite->setPosition(ccp(100, 100));
3addChild(sprite);
4
5CCMoveBy* act1 = CCMoveBy::create(0.5, ccp(100, 0));
6sprite->runAction(CCRepeat::create(act1, 1));

The act1 will be a CCMoveBy action of duration 0.5, but with the position value of ccp(100,0).


 뒤에 By 붙는거와 To 붙는거 차이


By는 현재 값 기준으로 변경 To는 그냥 그런거 상관없이 변경

만약 현재 캐릭터 위치가 120 .30 이면

만약 CCMoveBy::create(2, ccp(50,10));    //현재 캐릭터 위치 기준으로 50,10만큼 이동 -> 170,40

       CCMoveTo::create(2ccp(50,10));      //좌표값에 50, 10으로 이동 -> 50,10


Trackback 0 And Comment 0

cocos2d-x 기본 컨셉

|

현재 cocos2d-x 홈페이지에 있는 내용을 간단하게 요약하여 정리 후 포스팅할 예정입니다.

혼자서 공부하면서 얻은 지식이나 방법들을 미약하지만 공유하고 싶습니다.

cocos2d-x 는 오픈소스 기반이며 쉽고 강력한 엔진입니다.

C++, Lua, javascript등의 언어를 지원하고 아이폰,안드로이드,윈도우폰,블랙베리,타이젠,등을 지원하는 

크로스 플램폼 엔진입니다.

cocos2d-x는 현재 150만명이 다운받았고 사용하고 있습니다 . 많은 게임들이 앱스토어나 구글플레이에서 높은 수익을 얻고 있습니다.

 

 

Trackback 0 And Comment 0
prev | 1 | next