Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Animation always played to its last frame  (Read 7182 times)

0 Members and 1 Guest are viewing this topic.

AndyT

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 14
    • View Profile
Animation always played to its last frame
« on: April 26, 2013, 08:16:31 AM »

Hi to all!

Could someone give me advice, if there is a way to do following:

When a 2D actor is in idle animation (and the game is interactive), the animation is interrupted anytime the player clicks to perform some other action. Is there any way so that the actor would start f.e. walking somewhere until the animation always reaches its last frame?

I am not so good at scripting, so i spent some time searching the forum, but cannot find a solution...

Thanks a lot for possible advice...
Logged

ciberspace

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 116
    • View Profile
    • Tele Juego
Re: Animation always played to its last frame
« Reply #1 on: April 26, 2013, 11:20:45 AM »

in scene.script in folder script

change de code:
Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////
  4. on "LeftClick"
  5. {
  6.   // when the scene is left-clicked, just send the actor to the specified point
  7. }
  8.  

for
 

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////
  4. on "LeftClick"
  5. {
  6.   // when the scene is left-clicked, just send the actor to the specified point
  7.   if actor.IsWalking()== false
  8.       {
  9.       actor.GoTo(Scene.MouseX, Scene.MouseY);
  10.       }
  11. }
  12.  
« Last Edit: April 26, 2013, 11:23:36 AM by ciberspace »
Logged

AndyT

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 14
    • View Profile
Re: Animation always played to its last frame
« Reply #2 on: April 26, 2013, 12:16:16 PM »

Thanks for a reply,

but i had something completely different on my mind. This makes the actor always finish his walk to the point we clicked without interruption (might be useful sometime).

But i need something else:
when we click, so that the actor being in idle looping animation would wait until the idle animation sprite reaches its last frame (initial pose, which is the same for every first and last frame of each animation, so that the animations play fluently), before he goes somewhere or do something etc...

Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Animation always played to its last frame
« Reply #3 on: April 26, 2013, 12:19:51 PM »

In general, from the gameplay's point of view this isn't so good. The player will wait for the end of the current action (animation) whereas he already gave the order and immediately wants to receive result - that is to begin the next action.
But purely technically it is possible to try. I will give very rough example, for me it is interesting too, will it work or not :)

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   Game.Interactive = false;
  4.   // after this and before actor start walking the game will be noninteractive to prevent of many "LeftClick" calls
  5.   // and redefinition of expectation of the end of animation that used in the next strings
  6.   var anim = actor.GetSpriteObject();
  7.   while (anim.CurrentFrame != anim.NumFrames-1)
  8.     Sleep(0);
  9.   Game.Interactive = true
  10. }

Exists probably more graceful decisions that includes for example using an event call by the last animation frame (that can be defined in the sprite editor), but for first time try to use this defined example.
Logged

AndyT

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 14
    • View Profile
Re: Animation always played to its last frame
« Reply #4 on: April 26, 2013, 01:47:39 PM »

So i´ve tried and it doesn´t work... But it looks so promising and so close to what i need  ;D
as i said i am still very amateur coder, i would never be able to write it myself.

Shouldn´t be the Sleep command defined other than 0? (Excuse me my boldness  8) )
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Animation always played to its last frame
« Reply #5 on: April 26, 2013, 03:15:54 PM »

Yeah, already readed docs. GetSpriteObject() works only with SetSprite().
So second attempt.
In SpriteEdit for all of your idle animations set Event parameter (enter the text): for first frame to FirstFrame, for last frame to LastFrame.
Then in your actor script add such code:

Code: WME Script
  1. on "FirstFrame"
  2. {
  3.         this.LastFrame = false;
  4. }
  5. on "LastFrame"
  6. {
  7.         this.LastFrame = true;
  8. }

Then in scene.script:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.        while (!actor.LastFrame)
  4.           Sleep(0);
  5.        actor.GoTo(Scene.MouseX, Scene.MouseY);
  6. }

Sleep(0) - cause of your animation's frame delay may be lower than any your entered here value and thus your may catch infinite loop.
For example, frame delay is 50 ms, and used Sleep(100);
While loop "sleeps" 100 ms, animation meantime plays last frame with delay 50 ms (ans sets actor.LastFrame to true), and after that plays first frame with delay 50 ms (and sets actor.LastFrame to false). So for the next loop's iteration (after 100 ms) actor.Last frame will be false, again and again.
« Last Edit: April 26, 2013, 03:22:52 PM by 2.0 »
Logged

AndyT

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 14
    • View Profile
Re: Animation always played to its last frame
« Reply #6 on: April 26, 2013, 04:19:55 PM »

It works great!!!!!  :D Brilliant...
Thank you so much!!!  ;D
Logged
 

Page created in 0.057 seconds with 20 queries.