Loop issues.

Game Editor comments and discussion.

Loop issues.

Postby Guardian69 » Fri Jul 01, 2011 12:56 pm

Hi guys,

I have declared a global variable called m0nst3rAnimPos, and initiated it to 0 in the actors create event.

I have then put the following script in the actors draw event script.

if (m0nst3rAnimPos == 0)
{
m0nst3rAnimPos = 1;
playerOverlay.animpos = 0;
}
if (m0nst3rAnimPos == 1)
{
m0nst3rAnimPos = 0;
playerOverlay.animpos = 8;
}

Essentially, I am alternating a frame every loop to prototype an idle animation. However, it seems to get stuck on frame 8.

This seems like it should be really simple. Any ideas?
User avatar
Guardian69
 
Posts: 17
Joined: Thu May 26, 2011 9:05 pm
Location: United Kingdom
Score: 0 Give a positive score

Re: Loop issues.

Postby Guardian69 » Fri Jul 01, 2011 1:02 pm

I'm actually realised there is a better way and I am going to change this anyway, but would like to know the answer, just incase it is something to do with global scope???
User avatar
Guardian69
 
Posts: 17
Joined: Thu May 26, 2011 9:05 pm
Location: United Kingdom
Score: 0 Give a positive score

Re: Loop issues.

Postby Kodo » Fri Jul 01, 2011 3:04 pm

We all started somewhere Guardian69, and we are all still learning :)

If your m0nst3rAnimPos variable is going to be used by lots of clones you will want it to be an Actor Variable and not global. Otherwise all the clones will be updating the same single global variable rather than just their own version of it..

Also, the code you have in the draw actor is run every frame, so the animpos for the respective clone is being set/changed some 30 times a second, probably not what you want. If you wanted to change it once a second and the game is running at 30 frames a second you can use your own counter to control the animpos update, something like:

Note that 'count ' is an Actor variable (int)
Code: Select all
if (count == 30)
{
  count = 0; // reset the counter

  if (m0nst3rAnimPos == 0)
  {
   m0nst3rAnimPos = 1;
   playerOverlay.animpos = 0;
  }
  if (m0nst3rAnimPos == 1)
  {
   m0nst3rAnimPos = 0;
   playerOverlay.animpos = 8;
  }
}

count++; // adds 1 to count
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest