Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Pages: [1] 2 3  All

Author Topic: Video entites, Menu music & Random Idle Animations  (Read 15384 times)

0 Members and 1 Guest are viewing this topic.

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Video entites, Menu music & Random Idle Animations
« on: March 11, 2006, 01:59:29 AM »

Hi!

1.I've just read this thread: http://forum.dead-code.org/index.php?topic=1077.0
And my question is: How do I actually insert the video as an entity in the scene?

2.I want my game to change to the main theme music when I enter the Main Menu, so I figured out how to do it, but when I want to return to the game the Menu music continues to play! :'( How can I change it back to the music of the scene?
Thanx!

EDITED: Changed the title to a more appropriate one.
« Last Edit: March 11, 2006, 03:33:28 PM by vadbag »
Logged
WME rocks!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: 2 q-s
« Reply #1 on: March 11, 2006, 09:15:43 AM »

1. You don't. Any entity of your scene can become a "video entity" if you call its PlayTheora() method from a script.
var SomeEntity = Scene.GetNode("some entity name");
SomeEntity.PlayTheora("some_video.ogg");

2. There are 10 music channels available to you, so simply pause your main music channel when entering the menu, play the menu music in another channel, and when leaving the menu stop the menu music channel and resume the original one.

Game.PauseMusic();
Game.PlayMusicChannel(1, "menu_music.ogg");
...
Game.StopMusicChannel(1);
Game.ResumeMusic();
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Thanx
« Reply #2 on: March 11, 2006, 12:48:14 PM »

 ;D ;D ;D
Thank you!!! It works now (I mean the music thing)

Just one more question. There was this thread in the forum: http://forum.dead-code.org/index.php?topic=585.0
So, I put this code:

Code: [Select]
#include "scripts\base.inc"

var IsIdle = false;
var IdleStartTime = 0;

while(true) // endless loop
  {
   if(Game.Interactive == true) // is the actor doing something?
     {
      if(!IsIdle)
         {
          // actor enters idle state
          IsIdle = true;
          IdleStartTime = Game.CurrentTime;
          }
       else if(Game.CurrentTime - IdleStartTime > 5000) // is the actor idle for 5 seconds?
         {
         IdleStartTime = Game.CurrentTime;
         switch(Random(1, 6))
             {
               case 1: actor.PlayAnim("actors\sharik\idle\01\idle.sprite"); break;
               case 2: actor.PlayAnim("actors\sharik\idle\02\idle.sprite"); break;
               case 3: actor.PlayAnim("actors\sharik\idle\03\idle.sprite"); break;
               case 4: actor.PlayAnim("actors\sharik\idle\04\idle.sprite"); break;
               case 5: actor.PlayAnim("actors\sharik\idle\05\idle.sprite"); break;
               case 6: actor.PlayAnim("actors\sharik\idle\06\idle.sprite"); break;
             }
         }
    }
    else IsIdle = false; // actor is busy; set IsIdle to false
    Sleep(100); // wait for 100 milliseconds
 }

It works, but only one time.  :-\ When I make the actor to do something and then again leave him idle he doesn't play those random animations. Is there anything wrong with the code.

Thanx!
Logged
WME rocks!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: 2 q-s
« Reply #3 on: March 11, 2006, 12:54:58 PM »

The script probably gets interrupted as the actor starts performing other action while playing the idle animation. Try using PlayAnimAsync instead of PlayAnim to prevent this.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: 2 q-s
« Reply #4 on: March 11, 2006, 01:07:53 PM »

Sorry, I'm quite new to wme.  ::) Where do I put the PlayAnimAsync?

Thanks!
Logged
WME rocks!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: 2 q-s
« Reply #5 on: March 11, 2006, 01:28:12 PM »

In the code above replace PlayAnim with PlayAnimAsync. That way your idle script won't wait for the actor to finish the animation, and cannot be interrupted by other script, which orders the actor to do something else.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: 2 q-s
« Reply #6 on: March 11, 2006, 01:37:20 PM »

Thank you for your time!  But it still doesn't work, the way I want it to work.

Now the actor stops in the middle of the action  :-\ If, for example I make him walk, at some point he just stops and play the random sprite.  :-[
What I want him to do is to play the random animation only when the actor is in standing position. Perhaps, I should make the script to check whether the actor is in stand.sprite, and then allow the animations to play?  ??? How should I do it?
Logged
WME rocks!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: 2 q-s
« Reply #7 on: March 11, 2006, 01:54:24 PM »

Well in the original script in the thread you mentioned above there was a condition "if(actor.Ready) ...". That's exactly what you need to add to your script.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: 2 q-s
« Reply #8 on: March 11, 2006, 02:07:22 PM »

Thank you very much!!!!  ::rock ::rock
It works!!!  ;D ;D ;D
Logged
WME rocks!!!

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: 2 q-s
« Reply #9 on: March 11, 2006, 03:12:01 PM »

Dear Mnemonic,

Just one more thing. In my random animations the actor turns to different directions, but after the animation is finished, he returns to the initial direction. How can I make him to stay in the directions of the random animation?

I tried this:
Code: [Select]
switch(Random(1, 6))
 {
 case 1: actor.PlayAnimAsync("actors\sharik\idle\01\01.sprite") && actor.Direction = DI_RIGHT; break;
 case 2: actor.PlayAnimAsync("actors\sharik\idle\02\02.sprite") && actor.Direction = DI_DOWN; break;
 case 3: actor.PlayAnimAsync("actors\sharik\idle\03\03.sprite") && actor.Direction = DI_LEFT; break;
 case 4: actor.PlayAnimAsync("actors\sharik\idle\04\04.sprite") && actor.Direction = DI_UP; break;
 case 5: actor.PlayAnimAsync("actors\sharik\idle\05\05.sprite") && actor.Direction = DI_LEFT; break;
 case 6: actor.PlayAnimAsync("actors\sharik\idle\06\06.sprite") && actor.Direction = DI_DOWN; break;
 }

But it doesn't work :'( The wme just crashes.
How can I do it?
« Last Edit: March 11, 2006, 03:20:12 PM by vadbag »
Logged
WME rocks!!!

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Video entites, Menu music & Random Idle Animations
« Reply #10 on: March 11, 2006, 03:39:36 PM »

just put away those two &&. They don't make any sense.

It should look like:

case 1:
   actor.PlayAnimAsync("actors\sharik\idle\01\01.sprite");
   actor.Direction = DI_RIGHT;
   break;

etc.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: Video entites, Menu music & Random Idle Animations
« Reply #11 on: March 11, 2006, 04:02:42 PM »

Thanks indeed! Works well!  ;D
Logged
WME rocks!!!

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: Video entites, Menu music & Random Idle Animations
« Reply #12 on: March 12, 2006, 01:22:25 AM »

Hi again!

Everything was working just fine until I created a second scene. Now when I start the game the random animation script works, then I go to the secod scene, where it also works. However, if I return to the first scene, the script stops working quite often.  :( :( :(

Here is the full code that I'm using:
Code: [Select]
#include "scripts\base.inc"

var IsIdle = false;
var IdleStartTime = 0;

while(true) // endless loop
  {
   if(actor.Ready && Game.Interactive == true) // is the actor doing something?
     {
      if(!IsIdle)
         {
          // actor enters idle state
          IsIdle = true;
          IdleStartTime = Game.CurrentTime;
          }
       else if(Game.CurrentTime - IdleStartTime > 1000) // is the actor idle for 10 seconds?
         {
         IdleStartTime = actor.Ready;
         switch(Random(1, 7))
             {
               case 1: actor.TurnTo(DI_DOWN);
                   actor.PlayAnimAsync("actors\sharik\idle\01\stand.sprite");
                   actor.Direction = DI_DOWN;
                   Sleep(1000);
                   break;
               case 2: actor.TurnTo(DI_RIGHT);
                   actor.PlayAnimAsync("actors\sharik\idle\02\stand.sprite");
                   actor.Direction = DI_RIGHT;
                   Sleep(1000);
                   break;
               case 3: actor.TurnTo(DI_LEFT);
                   actor.PlayAnimAsync("actors\sharik\idle\03\stand.sprite");
                   actor.Direction = DI_LEFT;
                   Sleep(1000);
                   break;
               case 4: actor.TurnTo(DI_UP);
                   actor.PlayAnimAsync("actors\sharik\idle\04\stand.sprite");
                   actor.Direction = DI_UP;
                   Sleep(1000);
                   break;
               case 5: actor.GoTo(Random (1,800), Random(1,600));
               Sleep(1000);
               break;
               case 6: actor.GoTo(Random (1,800), Random(1,600));
               Sleep(1000);
               break;
               case 7: actor.GoTo(Random (1,800), Random(1,600));
               Sleep(1000);
               break;
             }
         }
    }
    else IsIdle = false; // actor is busy; set IsIdle to false
    Sleep(100); // wait for 100 milliseconds
 }

Can anybody suggest how to avoid this problem?

Thanx!
Logged
WME rocks!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Video entites, Menu music & Random Idle Animations
« Reply #13 on: March 12, 2006, 09:36:23 AM »

Just two obvious errors:
1) 1000 milliseconds is not 10 seconds, it's 1 second
2) you may want to use GoToAsync instead of GoTo for the same reasons you had to use PlayAnimAsync

Also, I don't see a reason for those Sleep() calls after each action.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vadbag

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 65
    • View Profile
Re: Video entites, Menu music & Random Idle Animations
« Reply #14 on: March 12, 2006, 02:01:10 PM »

Thank you for your answer!  ;D

1)I know about 1 second  :D I just put it for the testing purposes, so that I don't wait 10 sec until the actor starts using the script.
2)I'll try GoToAsync.

I put sleep calls temporalily, util I make the random animations. So far they consist of one frame, so I wanted the game to waint for some time. The same with walking. Without the sleep() calls the actor just goes to a point and then immediately performes another animation.

After I posted my problem here, I tested the game several times and found out that it's not just returning to the previous scene. The problem happens at different time during the game. Sometimes I return to the first scene 5 or 6 times and everything works OK.

I think that the script gets interrupted somehow during the game. But I'll try GoToAsync, and see If it helps.

Thanx!
Logged
WME rocks!!!
Pages: [1] 2 3  All
 

Page created in 0.046 seconds with 23 queries.