Sign in to follow this  

Animation Code

This topic is 4273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok well it's not really a keyword, but i need help putting the algorithm together. basically in my head the code should go like this:
else if (!facing_left) 
        {
            //change the animation from standing to shooting
            sprite_index = PMbackLBlast; 
            //speed at which animation should cycle; < 1 means slower cycle
            image_speed = 0.75;
            //image_index holds the animation cell index of the current one shown
            when (image_index == 11) 
            {
                PMBB = instance_create(x-5, y-32, PMBackBullet);
                PMBB.sprite_index = PMBackRBullet;
                PMBB.direction = 0;
            }
        }
        //keeps gun from firing before it's time
        backBlastReady = false;
        //sets timer for variable above to be true.
        //in this case every 20 frames or 3 bullets a second. 
        alarm[1] = 20;
} //ending outer if block
any ideas? edit: i solved the problem. i had to make it so it got a range of indexes namely:
if (image_index >= 11 && image_index <= 21) ... 
those are the cells of the animation that show the arm raised. but any suggestions to prove on this is more than welcomed. cuz i'm pretty sure this isn't the best way. edit2: added shooting animation code for PharaohMan. edit3: thread formerly: "coming up with an equivalent to the when keyword" [Edited by - Alpha_ProgDes on May 7, 2006 2:11:21 PM]

Share this post


Link to post
Share on other sites
I'm sorry, I'm not understanding you. What is the difference between "when" and "if"? What should be the functionality of the code?

Share this post


Link to post
Share on other sites
Maybe he wants the operation in the block to be queued and triggered asynchronously when the condition becomes true.

Spawn a new thread, poll the variable.

Share this post


Link to post
Share on other sites
@Sneftel: well the animation is in two parts. basically the sprite has his arm lowered then raises it and then a blast (bullet) is supposed to shoot out. putting an if in place of the when shows the shooting animation but no bullets are coming out.

so i want it so when the animation cycle gets to the cell that shows the character's arm raised, the bullet is created and then shot out. also synched so the bullet only shoots when the arm is raised.

i hope that made my situation clearer.

@Fruny: I'm using Game Maker's scripting language so no threads [sad]

@at everybody: there is no when keyword, i'm just using it as pseudo code to express what i want to happen in the code.

Share this post


Link to post
Share on other sites
ok. here's the code for my bad guy sprite when he needs to shoot.


if (abs(x-MegaMegaMan.x) <= 256)
{

var PMB;
if (readyToShoot)
{
if (facing_left)
{
if (instance_exists(PMbullet))
{
image_index = 11;
}
else
{
sprite_index = PMfrontLBlast;
}
if (image_index >= 11 && image_index <= 22)
{
PMB = instance_create(x+9, y+14, PMbullet);
PMB.direction = 180;
}

}
else if (!facing_left)
{
if (instance_exists(PMbullet))
{
image_index = 11;
}
else
{
sprite_index = PMfrontRBlast;
}
if (image_index >= 11 && image_index <= 22)
{
PMB = instance_create(x+22, y+14, PMbullet);
PMB.direction = 0;
}
}

readyToShoot = false;
alarm[0] = 10;

}
}
else
{
var PMBB;
if (backBlastReady)
{
if (facing_left)
{
sprite_index = PMbackRBlast;
image_speed = 0.75;
if (image_index >= 0 && image_index <= 10)
{
PMBB = instance_create(x+5, y-32, PMBackBullet);
PMBB.sprite_index = PMBackLBullet;
PMBB.direction = 180;
}
}
else if (!facing_left)
{
sprite_index = PMbackLBlast;
image_speed = 0.75;
if (image_index >= 11 && image_index <=21)
{
PMBB = instance_create(x-5, y-32, PMBackBullet);
PMBB.sprite_index = PMBackRBullet;
PMBB.direction = 0;
}
}
backBlastReady = false;
alarm[1] = 20;

}
}

Granted this is using the Game Maker Scripting Language but it should be to easy to follow if you program in C or C++. So my question is: "is this ugly"? if yes, what can I do to clean it up?

Share this post


Link to post
Share on other sites
Sign in to follow this