• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Visual Animation End Event doesn't work with a Reversed Sprite

Greetings you magnificent bastards!
Once again I'm here to ask you for help!

This time is nothing memory related, but Event related.
Hear me out: I'm trying to use a 5 frame animation and then reverse it at the end. Since reversing it in the sprite editor costs memory, by making more frames, I decided to do this way:

_____________________________________________________

[ Create Event ]

Variable = Obj.rev 0

[ Step Event ]

Sprite "Druggeljug" = speed 1

[ End Animation Event ]

If Sprite "Druggeljug"...

then Change Sprite to "Druggeljug" = speed -1
then Set Variable Obj.rev to 1 (not relative)

If Sprite "Druggeljug"...
If Variable Obj.rev is 1...

then Change Sprite to "Druggeljug" = speed 1
then Set Variable Obj.rev to 0 (not relative)


_____________________________________________________

This, would have created a loop where the animation starts normal, but when it ends, it changes to it's own version but in reverse.
For some reasons, when the animation is in reverse, the Animation End Event doesn't execute.
Is there a reason for that? Or I just can't use this event for it?
Also, keep in mind that I'm using DRAG AND DROP, I'm not into coding yet, so I would really appreciate a solution from you guys that
can be replicated in DnD. If there is no solution with it, I'll accept a code, but please explain to me how it works the code you made up!

Thank you so much guys, I'll never thank you enough for the support.
I will appreciate even the smallest answer.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
This won't work simply because the animation end event is only triggered when the current animation frame value (the image_index) goes over the maximum number of frames -1. So, the easiest way you can resolve this is to deal with it in the STEP event and create a new variable "up" in the CREATE event and set it to true. You'd then do some checks in the STEP event like this:

GML:
if variable "up" equals true
    Add to the image index
    if image_index greater than image_number - 1
        Set variable "up" to false
else
    Subtract from the image_index
    if image_index less than zero
        set variable "up" to true.
 
This won't work simply because the animation end event is only triggered when the current animation frame value (the image_index) goes over the maximum number of frames -1. So, the easiest way you can resolve this is to deal with it in the STEP event and create a new variable "up" in the CREATE event and set it to true. You'd then do some checks in the STEP event like this:

GML:
if variable "up" equals true
    Add to the image index
    if image_index greater than image_number - 1
        Set variable "up" to false
else
    Subtract from the image_index
    if image_index less than zero
        set variable "up" to true.
Thanks, but is there a way I can use this solution without messing with the image_index value and doing it with DnD?
 

Slyddar

Member
Since reversing it in the sprite editor costs memory, by making more frames,
If you duplicate the frames at the end of your sprite animation so it plays forward, then in reverse, Gamemaker notices there are duplicate frames, and only writes one of them to the texture page, so no extra memory is used.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Thanks, but is there a way I can use this solution without messing with the image_index value and doing it with DnD?
Certainly. Simply use a custom variable for the image_index, then draw the sprite using the Draw Sprite action, supplying the custom variable for the Frame Index value.
 
If you duplicate the frames at the end of your sprite animation so it plays forward, then in reverse, Gamemaker notices there are duplicate frames, and only writes one of them to the texture page, so no extra memory is used.
Are you certain? Because I'm using freaking GameMaker 8.1, and this version doesn't even have the option to gradually load the assets.

Certainly. Simply use a custom variable for the image_index, then draw the sprite using the Draw Sprite action, supplying the custom variable for the Frame Index value.
Thanks alot then! I'll try it!

EDIT:
I found a simpler solution with the Animation End Event anyway! This is what I have done:
_______________________________________________________________

Create Event:

set the sprite to pol_idle with subimage 0 and speed 1
set variable pol.rev to 0

Step Event:

if pol.rev is larger than -1
set variable pol.rev relative to -1
If Sprite Is pol_idle
if pol.rev is equal to 0
set the sprite to pol_idle with subimage 0 and speed 1

Other Event: Animation End:
If Sprite Is pol_idle
set the sprite to pol_idle with subimage 4 and speed -1
set variable pol.rev to 4

_______________________________________________________________

It's a bit more complicated, but works just fine!
Anyway, I'm still curious about what @Slydarr said. Because if so, it wouldn't be necessary to do this.
Remember, I'm using GM8 because I'm dumb and not experienced enough to use a real Game Maker (like the studio version).
 
Last edited:

woods

Member
Remember, I'm using GM8 because I'm dumb and not experienced enough to use a real Game Maker (like the studio version).
i cant use drag n drop.. i get lost in the weave way too easy.. like making chainmail...
and only one way to get experience with the coding block is to dive in.

if you can follow the flow using DnD, then you will have an easy time making the jump to using code.
is just a matter of relating the 10 or so icons from DnD to the line or two of a script.. is just a matter of exposure ;o)
 

Slyddar

Member
Anyway, I'm still curious about what @Slydarr said. Because if so, it wouldn't be necessary to do this.
Well I know for a fact it works that way in GMS2. I've even duplicated a huge sprites frames multiple times, ran in debug mode, and then paused the game and looked at the texture pages, and they only show the duplicate frames once. Don't know if the same thing happens in 8.1 though.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Well I know for a fact it works that way in GMS2. I've even duplicated a huge sprites frames multiple times, ran in debug mode, and then paused the game and looked at the texture pages, and they only show the duplicate frames once. Don't know if the same thing happens in 8.1 though.
Pretty sure it doesn't...
 
Top