Actions: Ease


정해진 시간동안 가속도를 변화를 줄수있어 sprite움직임을 단순하지 않고 다양하게 변화시킬 수 있다. Ease Action은 시작시, 끝날때, 시작과끝 에서 변화하는 각각의 3가지 타입이 있다.

  • In actions: 시작부분에서 가속
  • Out actions: 끝부분에서 가속
  • InOut actions: 시작과 끝부분에서 가속

Ease actions

  • CCEaseIn: 시작부분 가속이 있은 후 감속된다.
  • CCEaseOut: 끝부분에서 가속된다.
  • CCEaseInOut: 시작 시 가속되다가 다시 느려졌다가 끝날때 또 가속된다.

rate인자는 가속도를 나타낸다. 

EaseExponential actions

기본 액션값에 비해 느리다가 빨라지는 체감속도가 훨씬 크다.

EaseSine actions

기본값에 비해서 느리다가 빨라지는 체감속도가 덜하다.

EaseElastic actions

고무줄 팅기는 효과를 준다.
Sequence나 Spawn과 같은 action과 같이 쓰면 엉뚱한 값이 나올수 있다.

EaseBounce actions

바닥에 튕기는 효과를 준다.
Sequence나 Spawn과 같은 action과 같이 쓰면 엉뚱한 값이 나올수 있다. 

EaseBack actions

목표지점보다 더 갔다가 다시 복귀하는 효과를 준다. Elastic에서 period를 1값으로 준거랑 비슷한 효과가 나는것같다. 
Sequence나 Spawn과 같은 action과 같이 쓰면 엉뚱한 값이 나올수 있다.

Actions: Speed

Speed action

CCSpeed action은 내부 action의 기간을 바꾼다..는 중요하지 않고.
[
action setSpeed: 2.5f];
요딴식으로 나중에 스피드값을 바꿀려고 사용하는 action
 

 

Posted by DevMaster

CCSequence
Action리스트를 받아 순서대로 실행한다. 

 

icon = [CCSprite spriteWithFile:@"Icon-Small.png"];  

icon.position = ccp(50,200);

[self addChild:icon];

id action1 = [CCMoveTo actionWithDuration:2 position:ccp(100,100)];

id action2 = [CCMoveBy actionWithDuration:2  position: ccp(100,120)];

id action3 = [CCMoveBy actionWithDuration:2  position: ccp(0,120)];

action3 = [CCEaseInOut actionWithAction:[[action3 copy] autorelease] rate:5.0f];

[icon runAction: [CCSequence actions:action1, action2, action3, nil]];

 


CCSpawn 
여러 Actions을 동시에 실행한다. 


 

id action = [CCSpawn actions:

[CCRotateBy actionWithDuration2 angle720],
nil


[sprite runAction: action];

 

CCRepeat
times 인자의 숫자만큼 반복한다.

CCRepeatForever
무한 반복 액션
* CCSequence 액션 안에 CCRepeatForever 액션을 넣을 수는 없다.  





Posted by DevMaster

2011. 3. 29. 02:10 cocos2d

cocos2d : Basic Actions

아래와 같은 Actions를 사용하여 Sprite의 상태변화 또는 애니메이션 효과를 구현할 수 있다.
Action이름에 To가 붙은것은 상태변화의 최종값을 인자로 받는것이고 By가 붙은 것은 해당값만큼 변화시키것을 나타낸다. 

현재 position이 10,10 인경우 CCMoveTo 에 position 30,30 을 주면 30,30값으로 이동되는것이고
CCMoveBy 30,30값을 주면 최종 위치는 40,40이된다.

거의 모든 Actions는 reverse 메소드를 가지고 있으면 이는 반대 행동값을 나타낸다. 

    position
        CCMoveBy  CCMoveTo
        CCJumpBy  CCJumpTo
        CCBezierBy  CCBezierTo
        CCPlace
    scale
        CCScaleBy  CCScaleTo
    rotation
        CCRotateBy  CCRotateTo
    visible
        CCShow
        CCHide
        CCBlink
        CCToggleVisibility
    opacity
        CCFadeIn
        CCFadeOut
        CCFadeTo (reverse 없음)
    r, g, b
        CCTintBy  CCTintTo (reverse 없음)
[CCJumpTo 
actionWithDuration:1   //duration 시간간격 
position:location  //position 최종위치
height:100 //height 점프 높이 
jumps:2];
  //jumps 점프회수 (회수가 3번이던 4번이던 최종위치는 position임)

CCBezierTo

ccBezierConfig r;

r.endPosition = location;      //최정 지점

r.controlPoint_1 = ccp(200,100);  //베지어 포인트1

r.controlPoint_2 = ccp(300,10);   //베지어 포인트2

id move = [CCBezierTo actionWithDuration:1 bezier: r];

http://www.moshplant.com/direct-or/bezier/curve01.gif  

CCScaleTo
id move = [CCScaleTo actionWithDuration:2 scale:3.0f];
scale값으로 변화한다.(만일 이미 scale이 4.0이었다면 3.0으로 축소되는것임,현재 크기에서 항상 scale값만큼 확대되기를 원하면 CCScaleBy를 써야함)  
 


CCRotateTo

id move = [CCRotateTo actionWithDuration:2 angle:90.0f];
angle값만큼 기울인값으로 변화함 마찬가지로 현재 각도에서 추가로 angle값만큼 기울이기 위해서는 CCRotateBy를 쓰면됨.
angle값은 degree임(radian이 아님) 

CCShow
id move = [CCShow action]; 
즉시 보여짐 (duration 값 없음. 서서히 보여주고 싶은때는 CCFadeIn을 사용해야함)

CCHide

id move = [CCHide action];
즉시 사라짐 (duration 값 없음. 서서히 사라지게 하고 싶은때는 CCFadeOut을 사용해야함)

CCBlink

id move = [CCBlink actionWithDuration:4 blinks: 1];

blinks회수만큼 나타났다가 사라짐 
1일경우 사라짐 - 나타남 - 사라짐
2일경우 사라짐 - 나타남 - 사라짐 - 나타남 - 사라짐 

CCToggleVisibility 

id move = [CCToggleVisibility action];

Show상태일때는 Hide로 바꾸고 Hide상태일때는 Show로 바꿈. 즉시 변함  
 

CCFadeTo
id move = [CCFadeTo actionWithDuration:2 opacity:0x9d];
opacity값만큼 투명도를 조정함. opacity는 GLubyte 값이며 0x00 에서 0xFF사이의 값임

CCTintTo
id move = [CCTintTo actionWithDuration:2 red:0xFF  green:0xAA blue:0xAA]; 
 
색농도를 바꿈 








 

Posted by DevMaster

id move = [CCMoveTo actionWithDuration:1 position:location];

id accel = [CCEaseIn actionWithAction:[[move copy] autorelease] rate:5.0f];

[greenApple runAction: accel];

//CCEaseIn : 점점 빠르게

//CCEaseOut : 점점 느리게

//CCEaseInOut : 빨랐다가 느리게

//CCSpeed : 해당 속도값대로 


CCSpeed인 경우 인자가 rate가 아니고 speed이다.. 주의!!!
id accel = [CCSpeed actionWithAction:[[move copy] autorelease] speed:5.0f]; 

 

Posted by DevMaster

2011. 3. 28. 02:56 cocos2d

cocos2d : Menu

1. init 에 넣어준다.

CCMenuItemImage *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"menu1.png"

selectedImage: @"menu1_s.png"

target:self

selector:@selector(menu1Click:)];


CCMenuItemImage *menuItem2 = [CCMenuItemImage itemFromNormalImage:@"menu2.png"

selectedImage: @"menu2_s.png"

target:self

selector:@selector(menu2Click:)];

CCMenu * myMenu = [CCMenu menuWithItems:menuItem1,menuItem2,nil];

[myMenu alignItemsVertically];

[self addChild:myMenu];

2. click시 이벤트 메소트 

- (void) menu1Click: (CCMenuItem  *) menuItem ; 

Posted by DevMaster
1. 그냥 이동

[[CCDirector sharedDirector] replaceScene: [SomeOtherScene scene]];


2. 이동하면서 효과주기

[[
CCDirector sharedDirector] replaceScene:

[CCTransitionFade transitionWithDuration:0.5f scene:[MainScene scene]]]; 

    효과 종류 
    CCTransitionFade : Fade in & Fade out

    CCTransitionFlipAngular : 종이를 뒤집듯이 180도 회전 하면서 앵글이 아래로 갔다가 돌아옴.

    CCTransitionShrinkGrow : 기존 씬이 멀어지면서 새로운 씬이 가까워짐

    CCTransitionMoveInB : 아래에서 새 씬이 올라오고 기존씬이 사라짐

    CCTransitionMoveInT : 위에서 새 씬이 내래오고 기존씬이 사라짐

    CCTransitionMoveInL : 왼쪽에서

    CCTransitionMoveInR : 오른쪽에서 

    CCTransitionFadeTR : 

    CCTransitionFadeUp

    CCTransitionFlipX : 종이를 뒤집듯이 왼쪽에서 오른쪽으로 180도 회전

    CCTransitionFlipY : 종이를 뒤집듯이 위에서 아래로 180도 회전

    CCTransitionPageTurn : 책 페이지를 넘기듯이

    CCTransitionCrossFade : 새 씬이 일단 겹쳐지고 기존씬이 천천히 사라짐


Posted by DevMaster


1. 헤더 등록

#import "CCTouchDispatcher.h"
 

2. 델리게이트 등록

- (void) registerWithTouchDispatcher {

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];

}


3. 터치 구현

- (BOOL) ccTouchBegan:(UITouch *) touch withEvent:(UIEvent *) event {

return YES;

}


- (void) ccTouchEnded:(UITouch *) touch withEvent:(UIEvent *) event {

}



Posted by DevMaster
이전버튼 1 이전버튼

블로그 이미지
DevMaster

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.4
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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함