2011. 3. 30. 23:22 cocos2d 메뉴얼(번역)
cocos2d : Actions : Ease (번역)
Actions: Ease
Ease action은 내부 action의 시간을 바구는 특별한 구성 action이다. Flash에서는 Tweening 또는 Easingaction 이라고른다.
이 Action들은 내부 action의 속도를 수정하지만 전체 시간은 바뀌지 않는다. 예를들어 내부적으로 5초간 행동하면 전체 5초동안 진행된다.
Ease actions 시간을 선형적으로 바꾼다.
예를들어 이 Action들은 내부 action을 가속하거나 감속한다.
이 Action은 3가지 타입으로 나뉜다.
- In actions: 시작부분에서 가속
- Out actions: 끝부분에서 가속
- InOut actions: 시작과 끝부분에서 가속
easing와 tweening action에 대해 더 자세한 정보를 얻고싶다면 다음페이지를 살펴보자.
Ease actions
다음 공식을 사용하여 내부 action을 가속한다 :
-(void) update:(ccTime) t { [inner update: powf(t,rate)]; }
변이:
CCEaseIn
: 시작부분 가속CCEaseOut
: 끝부분 가속CCEaseInOut
: 시작과 끝부분 가속
rate인자는 가속도를 나타낸다.
예제:
// 시작 부분 가속 id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseIn actionWithAction:action rate:2]; [sprite runAction: ease]; // 끝부분 가속 id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseOut actionWithAction:action rate:2]; [sprite runAction: ease]; // 시작과 끝부분 가속 id action = [CCMoveTo actionWithDuration:2 position:ccp(100,100)]; id ease = [CCEaseInOut actionWithAction:action rate:2]; [sprite runAction: ease];
EaseExponential actions
지수 action:
CCEaseExponentialIn
CCEaseExponentialOut
CCEaseExponentialInOut
예제:
id scaleAction = [CCScaleTo actionWithDuration:2.5 scale:.8]; id easeAction = [CCEaseExponentialIn actionWithAction:scaleAction]; [label runAction: easeAction];
EaseSine actions
사인 actions :
CCEaseSineIn
CCEaseSineOut
CCEaseSineInOut
예제:
// 시작부분 사인 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineIn actionWithAction:move]; [sprite runAction:action]; // 끝부분 사인 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineOut actionWithAction:move]; [sprite runAction:action]; // 시작과 끝부분 사인 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseSineInOut actionWithAction:move]; [sprite runAction:action];
EaseElastic actions
이 action은 고무줄같은 시간 시뮬레이션으로 바꾼다. 고무줄 action 1보다 크고 0보다 작은 시간값을 사용하므로 내부 actions은 이 특이값을 다룰수 있는 준비가 되어있어야한다.
어떤 시간 값은 한번 이상(이 함수는 전단사-1:1대응 함수가 아니다) 동작되므로 내부 action은 이값을 다룰준비가 되어있어야한다. CCMoveBy, CCScaleBy, CCRotateBy 같은 간단한 actions은 EaseElastic action 들과 잘 동작하지만 CCSequence 또는CCSpawn action 은 예상치 못한 결과가 나올 수 있다.
Elastic action:
CCEaseElasticIn
CCEaseElasticOut
CCEaseElasticInOut
예제:
// 'period' is how elastic is the action. // recommended values: between 0.3 and 0.45 // Elastic at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticIn actionWithAction:move period:0.3f]; [sprite runAction: action]; // Elastic at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticOut actionWithAction:move period:0.3f]; [sprite runAction: action]; // Elastic at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseElasticInOut actionWithAction:move period:0.3f]; [sprite runAction: action];
EaseBounce actions
EaseBounce action은 바운딩(바닥에 팅기는)효과를 시뮬레이션한다.
어떤 시간 값은 한번 이상(이 함수는 전단사-1:1대응 함수가 아니다) 동작되므로 내부 action은 이값을 다룰준비가 되어있어야한다. CCMoveBy, CCScaleBy, CCRotateBy 같은 간단한 actions은 EaseBounce action 들과 잘 동작하지만 CCSequence 또는CCSpawn action 은 예상치 못한 결과가 나올 수 있다.
Available bounce actions:
CCEaseBounceIn
CCEaseBounceOut
CCEaseBounceInOut
Examples:
// 시작부분 튕김 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceIn actionWithAction:move]; [sprite runAction: action]; // 끝부분이 튕김 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceOut actionWithAction:move]; [sprite runAction: action]; // 시작과 끝부분이 튕김 id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBounceInOut actionWithAction:move]; [sprite runAction: action];
EaseBack actions
어떤 시간 값은 한번 이상(이 함수는 전단사-1:1대응 함수가 아니다) 동작되므로 내부 action은 이값을 다룰준비가 되어있어야한다. CCMoveBy, CCScaleBy, CCRotateBy 같은 간단한 actions은 EaseBack action 들과 잘 동작하지만 CCSequence 또는CCSpawn action 은 예상치 못한 결과가 나올 수 있다.
Back action:
CCEaseBackIn
CCEaseBackOut
CCEaseBackInOut
Examples:
// Back at the beginning id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackIn actionWithAction:move]; [sprite runAction: action]; // Back at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackOut actionWithAction:move]; [sprite runAction: action]; // Back at the beginning and at the end id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCEaseBackInOut actionWithAction:move]; [sprite runAction: action];
Actions: Speed
Speed action
CCSpeed
action은 내부 action의 기간을 바꾼다.
id move = [CCMoveBy actionWithDuration:3 position:ccp(350,0)]; id action = [CCSpeed actionWithAction: move speed:1.0f]; // no speed modification // but you can modify the speed later [action setSpeed: 2.5f]; // speed is 2.5 faster [action setSpeed: 0.5f]; // speed is 0.5 faster (it means 2 times slower)