This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:community:sausage:realistic_walk_movement [2015/10/28 19:28 (9 years ago)] – ↷ Links adapted because of a move operation sausage | en:tutorials:animation:realistic_walk_movement [2022/06/21 07:49 (22 months ago)] (current) – minor typo iarwain | ||
---|---|---|---|
Line 21: | Line 21: | ||
===== Prerequisite ===== | ===== Prerequisite ===== | ||
- | You are best to be familiar with the [[tutorials: | + | You are best to be familiar with the [[en:tutorials:animation:anim|Anim Tutorial]] before this one. |
- | ===== Simple Movement | + | ===== Fixed Distance |
- | With a simple movement, for each frame change, the object is usually moved x pixels along. With this solution, a list of varying distance values is used. For each frame change, an evant value is taken, and the character is moved that many pixels along. | + | With a simple movement, for each frame change, the object is usually moved a certain amount of pixels along. With this solution, a list of varying distance values is used. For each frame change, an event value is taken, and the character is moved that many pixels along. |
That is the concept in a nutshell. | That is the concept in a nutshell. | ||
Line 32: | Line 32: | ||
I have provided a set of animation frames for this tutorial here. | I have provided a set of animation frames for this tutorial here. | ||
- | {{tutorials: | + | {{tutorials: |
The graphic is 506 x 100 and each frame varies in width. Save to the data/anim folder. | The graphic is 506 x 100 and each frame varies in width. Save to the data/anim folder. | ||
Line 39: | Line 39: | ||
- | <code ini> | + | <code ini> |
- | AnimationList | + | [DroidObject] |
- | LinkList = DroidIdle2Walk# | + | Graphic = DroidGraphic ; Default frame size for all the animation frames. |
+ | AnimationSet = | ||
+ | Position = (5, 130, 0) | ||
+ | |||
+ | [DroidGraphic] | ||
+ | Texture | ||
+ | Pivot = top right | ||
- | [DroidIdle2Walk] | + | [DroidAnimationSet] |
- | Source = DroidIdleAnim | + | Texture |
- | Destination | + | KeyDuration |
- | Property | + | Digits |
- | + | StartAnim | |
- | [DroidWalk2Idle] | + | DroidIdleAnim = 1 |
- | Source = DroidWalkAnim | + | DroidWalkAnim |
- | Destination = DroidIdleAnim | + | DroidIdleAnim-> = DroidIdleAnim |
- | Property | + | DroidWalkAnim-> = DroidWalkAnim |
- | Priority = 10 | + | |
- | + | ||
- | [DroidIdleLoop] | + | |
- | Source = | + | |
- | Destination | + | |
- | + | ||
- | [DroidWalkLoop] | + | |
- | Source = | + | |
- | Destination | + | |
[DroidIdleAnim] | [DroidIdleAnim] | ||
- | KeyData1 | + | Direction |
- | KeyDuration1 | + | |
- | Property | + | |
- | [DroidWalkAnim] | + | [DroidIdleAnim01] |
- | DefaultKeyDuration | + | TextureSize |
- | KeyData1 | + | KeyEvent |
- | KeyData2 | + | |
- | KeyData3 | + | |
- | KeyData4 | + | |
- | KeyData5 | + | |
- | KeyData6 | + | |
- | KeyData7 | + | |
- | EventName1 = AR1 | + | |
- | EventTime1 = | + | |
- | EventValue1 = 13 | + | |
- | EventName2 = AR1 | + | |
- | EventTime2 = | + | |
- | EventValue2 = 6 | + | |
- | EventName3 = AR1 | + | |
- | EventTime3 = 0.6 | + | |
- | EventValue3 = 18 | + | |
- | EventName4 = AR1 | + | |
- | EventTime4 = 0.8 | + | |
- | EventValue4 = 10 | + | |
- | EventName5 = AR1 | + | |
- | EventTime5 = 1.0 | + | |
- | EventValue5 = 19 | + | |
- | EventName6 = AR1 | + | |
- | EventTime6 = 1.2 | + | |
- | EventValue6 = 14 | + | |
- | EventName7 = AR1 | + | |
- | EventTime7 = 1.4 | + | |
- | EventValue7 = 21 | + | |
- | </ | + | |
- | + | ||
- | The [DroidWalkAnim] section contains the custom events which are very important. Each EventName is set the same as this is not important for this tutorial. But the EventTime and EventValue values are very important, and are defined in order to be in sync with the EventHandler. The KeyDuration for the animation is 0.2 so each EventTime is as well, starting with: 0.2, then 0.4, 0.6, 0.8 etc etc. | + | |
- | + | ||
- | We start with 0.2, not 0.0 because we don't want a movement on the first frame. | + | |
- | + | ||
- | And each EventValue contains a pixel distance | + | |
- | + | ||
- | + | ||
- | <code ini> | + | |
- | [DroidObject] | + | |
- | Graphic = droid1; This will do as a default. | + | |
- | AnimationSet = DroidAnimationSet | + | |
- | Position = (5, 130, 0) | + | |
- | + | ||
- | [DroidGraphic] | + | |
- | Texture | + | |
- | Pivot = top right | + | |
- | [droid1@DroidGraphic] | + | [DroidWalkAnim01] |
- | TextureCorner = (0, 0, 0) | + | |
TextureSize = (63, 100, 0) | TextureSize = (63, 100, 0) | ||
+ | KeyEvent | ||
- | [droid2@DroidGraphic] | + | [DroidWalkAnim02] |
- | TextureCorner = (63, 0, 0) | + | |
TextureSize = (72, 100, 0) | TextureSize = (72, 100, 0) | ||
+ | KeyEvent | ||
- | [droid3@DroidGraphic] | + | [DroidWalkAnim03] |
- | TextureCorner = (135, 0, 0) | + | |
TextureSize = (78, 100, 0) | TextureSize = (78, 100, 0) | ||
- | + | KeyEvent | |
- | [droid4@DroidGraphic] | + | |
- | TextureCorner = (213, 0, 0) | + | [DroidWalkAnim04] |
TextureSize = (78, 100, 0) | TextureSize = (78, 100, 0) | ||
- | + | KeyEvent | |
- | [droid5@DroidGraphic] | + | |
- | TextureCorner = (291, 0, 0) | + | [DroidWalkAnim05] |
TextureSize = (65, 100, 0) | TextureSize = (65, 100, 0) | ||
- | + | KeyEvent | |
- | [droid6@DroidGraphic] | + | |
- | TextureCorner = (356, 0, 0) | + | [DroidWalkAnim06] |
TextureSize = (80, 100, 0) | TextureSize = (80, 100, 0) | ||
+ | KeyEvent | ||
+ | |||
+ | [DroidWalkAnim07] | ||
+ | TextureSize = (70, 100, 0) | ||
+ | KeyEvent | ||
+ | </ | ||
- | [droid7@DroidGraphic] | + | The '' |
- | TextureCorner = (436, 0, 0) | + | |
- | TextureSize = (70, 100, 0)</ | + | |
+ | Also in the '' | ||
+ | |||
+ | Each event value contains the pixel distance value used to move our character each step. These vary as you can see above: 30, 5, 0, 19, 22, 4 & 26 pixels. | ||
You'll notice there is only right hand movement defined, just to keep the tutorial simple. | You'll notice there is only right hand movement defined, just to keep the tutorial simple. | ||
- | |||
- | |||
- | |||
===== Setting Up ===== | ===== Setting Up ===== | ||
- | A few things to set up, first our little droid object: | + | A few things to set up, first our little droid object |
<code c> | <code c> | ||
- | orxOBJECT *droid = orxObject_CreateFromConfig(" | + | droid = orxObject_CreateFromConfig(" |
orxObject_SetCurrentAnim(droid, | orxObject_SetCurrentAnim(droid, | ||
+ | </ | ||
+ | |||
+ | And then the object variable at the top of the code: | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | orxOBJECT *droid; | ||
</ | </ | ||
Line 174: | Line 134: | ||
case orxANIM_EVENT_CUSTOM_EVENT: | case orxANIM_EVENT_CUSTOM_EVENT: | ||
- | orxLOG("< | + | orxLOG("< |
orxVECTOR droidVector; | orxVECTOR droidVector; | ||
orxObject_GetPosition(droid, | orxObject_GetPosition(droid, | ||
- | droidVector.fX = droidVector.fX + pstPayload-> | + | droidVector.fX = droidVector.fX + pstPayload-> |
orxObject_SetPosition(droid, | orxObject_SetPosition(droid, | ||
Line 190: | Line 150: | ||
- | In the event handler, the orxANIM_EVENT_CUSTOM_EVENT is fired because the EventTime(s) | + | In the event handler, the orxANIM_EVENT_CUSTOM_EVENT is fired because the KeyEvents |
Setting the proper animation with key on and key off is done with: | Setting the proper animation with key on and key off is done with: | ||
<code c> | <code c> | ||
- | if(orxInput_IsActive(" | + | |
- | orxObject_SetTargetAnim(droid, | + | |
- | } | + | } |
- | + | | |
- | if(!orxInput_IsActive(" | + | orxObject_SetTargetAnim(droid, " |
- | orxObject_SetCurrentAnim(droid, " | + | } |
- | } | + | |
</ | </ | ||
- | When you run the program, the droid's feet should plant nice and firmly on the ground as it walks along. | + | And you'll need a key map: |
+ | <code c> | ||
+ | [MainInput] | ||
+ | KEY_ESCAPE = Quit | ||
+ | KEY_RIGHT | ||
+ | </ | ||
+ | When you run the program, the droid' | ||
- | |||
- | |||
- | |||
- | |||
- | Possible pitfalls: | ||
- | |||
- | 1) Be careful to make all your Config EventTime(s) different. Two EventTime(s) the same will crash. |