Jump to content


Photo

Switch to image 1 for 1 step


  • Please log in to reply
9 replies to this topic

#1 willowvayle

willowvayle

    Hello World!

  • GMC Member
  • 412 posts
  • Version:GM8.1

Posted 19 August 2012 - 11:37 PM

Hello World! I have this enemy that has an attacking animation of 2 images, when he is attacking I want it to stay as the first image for 49 steps, then move to image 1 for 1 step...

Here is my fail of a try in the end step event
var done;
    done = 0
    if done = 0 {alarm[2] = 49; done = 1}
    if event_perform(ev_alarm,2)
    {
        image_index = 1;
        image_speed = 1;
        alarm[3] = 1
    }
    if event_perform(ev_alarm,3)
    {
        image_index = 0;
        image_speed = 0;
        done = 0;
        alarm[2] = 49;
    }

But does not work :skull: How would I accomplish this? Thanks World!

Edited by willowvayle, 20 August 2012 - 05:59 PM.

  • 0

#2 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 19 August 2012 - 11:46 PM

I think you're confused about what event_perform is:

event_perform(type,numb) Performs event numb of the indicated type to the current instance.



Instead of using those 2 IFs, take that code and put it in their respective Alarm events (Alarm2 and Alarm3). Alternatively, you can try this in the Step event:

if image_index == 0
image_speed = 1/49

if image_index == 1
image_speed = 1

Also, you probably shouldn't use variables called "done". The code snippet in the forum shows them in bold, which might mean that they're used in the GML syntax.

Edited by PetzI, 19 August 2012 - 11:47 PM.

  • 1

#3 willowvayle

willowvayle

    Hello World!

  • GMC Member
  • 412 posts
  • Version:GM8.1

Posted 19 August 2012 - 11:51 PM

Both those don't seem to work :skull:

It never changes to image 1 it just stays at image 0

Edited by willowvayle, 19 August 2012 - 11:52 PM.

  • 0

#4 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 19 August 2012 - 11:59 PM

I just tested my second method and it works. Make sure to also delete all your code from the End Step event.
  • 0

#5 willowvayle

willowvayle

    Hello World!

  • GMC Member
  • 412 posts
  • Version:GM8.1

Posted 20 August 2012 - 12:10 AM

Uh... I can't delete what is in the end step because I have stuff dealing with changing his sprites when he is moving and standing still as well :/ I tried putting the code in the begin step event but that did not work either...
  • 0

#6 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 20 August 2012 - 12:12 AM

Then don't delete all of it, just the part that you posted.
  • 0

#7 willowvayle

willowvayle

    Hello World!

  • GMC Member
  • 412 posts
  • Version:GM8.1

Posted 20 August 2012 - 12:15 AM

Did not work...

Here is the code which your code is in...
if enemy_fighting = true
{
    image_speed = 0;
    switch (temp_dir)
    {
        case 1: sprite_index = LightDragonKnight_Fighting_Up;
            break;
        case 2: sprite_index = LightDragonKnight_Fighting_Left;
            break;
        case 3: sprite_index = LightDragonKnight_Fighting_Down;
            break;
        case 4: sprite_index = LightDragonKnight_Fighting_Right;
            break;
        default: break;
    }
    if image_index == 0
    image_speed = 1/49

    if image_index == 1
    image_speed = 1

}

EDIT: Changed the code like so...
if enemy_fighting = true
{
    if image_index == 0
    image_speed = 1/49

    if image_index == 1
    image_speed = 1
    switch (temp_dir)
    {
        case 1: sprite_index = LightDragonKnight_Fighting_Up;
            break;
        case 2: sprite_index = LightDragonKnight_Fighting_Left;
            break;
        case 3: sprite_index = LightDragonKnight_Fighting_Down;
            break;
        case 4: sprite_index = LightDragonKnight_Fighting_Right;
            break;
        default: break;
    }
}

And now the image is constantly moving :confused:


EDIT 2: Anyone? Anyone? Bueler?

Edited by willowvayle, 20 August 2012 - 01:47 AM.

  • 0

#8 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 20 August 2012 - 08:02 AM

When image_speed is a fractional number, image_index likely result in fractional like 0.9998967, so it rarely comes exactly equal to a whole number like 0 or 1.

if image_index == 0
    image_speed = 1/49

    if image_index == 1
    image_speed = 1

Try to change those conditions into inequalities.
if (image_index < 1) {
    image_speed = 1/49;
}
else {
    image_speed = 1;
}

  • 1

#9 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 20 August 2012 - 10:47 AM

It doesn't matter if it comes out fractional, if it comes out as 0.9998967 GM rounds it and the IF test returns equal. I've tested it and it works fine, so the problem is something else in his code.

What exactly is happening when you say "it's constantly moving"? Also, you did delete the first code that you posted, right?
  • 1

#10 willowvayle

willowvayle

    Hello World!

  • GMC Member
  • 412 posts
  • Version:GM8.1

Posted 20 August 2012 - 04:57 PM

@torigara Well that did the trick thank you! :thumbsup:

@PetzI When I said it was constantly moving I meant it was just doing the animation at a speed of 1, thanks you for your help as well :thumbsup:
And yes I did delete the code I first posted

Edited by willowvayle, 20 August 2012 - 04:58 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users