(SOLVED) Need help with animation end...

Help me please :) I'm trying to get an object to return to its idle animation after teleporting.

Step event:
Code:
if position_meeting(Fence.x, Fence.y, Fence) {
    sprite_index = spr_cleric_teleport;
}

if sprite_index = spr_cleric_teleport {
    if image_index = 5 {
        action_move_to(obj_teleport.x, obj_teleport.y);
    }       
}
Animation End event:
Code:
if sprite_index = spr_cleric_teleport {
    sprite_index = spr_cleric;
    image_speed = .1;
    image_index = 0;
}
I am completely lost as to why this is not working. It switches to the teleport sprite just fine, teleports just fine, but it won't change back to the regular sprite after the teleport animation plays through all of its images :(
 
E

ewlf5

Guest
Try the following and post the result:
Code:
if position_meeting(Fence.x, Fence.y, Fence) {
   sprite_index = spr_cleric_teleport;
}

if sprite_index = spr_cleric_teleport {
    if image_index = 5 {
        action_move_to(obj_teleport.x, obj_teleport.y);
        sprite_index = spr_cleric;
        image_speed = .1;
        image_index = 0;
    }       
}
 

jo-thijs

Member
@ewlf5, that's not what the OP wants though.

@Luke Pierson, why do you use:
Code:
if position_meeting(Fence.x, Fence.y, Fence) {
rather than just:
Code:
if position_meeting(x, y, Fence) {
It feels like that would always be true (except if you have some wierd masks or if you have no instance of type Fence).
 
@jo-thijs I actually do have a mask on the fence, because the enemies typically spawn near the fence and were getting stuck more often than not. After putting the mask, the spawning works almost 100% now
 

jo-thijs

Member
Ok, but that was a side note.
Can you answer the question as to why you're using Fende.x and Fence.y?
Also, you could answer ewlf5's question as to what happens when you try out his code.
 
The reason why is because when I simply used x and y, the sprite did not change to the teleportation sprite. When I put Fence.x and Fence.y, it triggered the teleportation sprite change.

Put in the debug message now, gonna run it and then post the result. After this, I'll try out ewlf5's code. Is his code supposed to just be in the step event?

UPDATE: The debug message went off and said that it was indeed not triggering.
 

psyke

Member
Two notes:
1 - When the Cleric hits the Fence, it should stop triggering the position_meeting function until he finishes teleporting.
Example:
Code:
if(bCanTeleport && position_meeting(x, y, Fence)){
   bCanTeleport = false;
   sprite_index = spr_cleric_teleport;
   image_index = 0;
}
In the Animation End Event, you can set this variable back to true, like this:
Code:
if sprite_index = spr_cleric_teleport {
   bCanTeleport = true;
   sprite_index = spr_cleric;
   image_speed = .1;
   image_index = 0;
}
2 - Also, be careful with the image_index, since it's a float number (like 5.4 or 5.8) it may never trigger your comparison depending on the image_speed. You may want to use something like this: floor(image_index+image_speed) == 5 (You can use a FLAG here too, so it can only trigger once).
 
@psyke
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object Cleric:

Variable Cleric.bCanTeleport(100046, -2147483648) not set before reading it.
at gml_Object_Cleric_StepNormalEvent_1 (line 17) - if(bCanTeleport && position_meeting(x, y, Fence)){
############################################################################################
 
@jo-thijs @ewlf5
Tried Ewlf5's code. The enemy's sprite still does not change. They still teleport, but it seems to have caused another piece of code to not trigger. I don't want them to be able to shoot at the player while their teleport animation is playing, but now they do shoot while the teleport animation is still active.
 
N

Nadder

Guest
It's very hard to determine why your code isn't working without seeing all the code for your cleric. By the sounds of it you've potentially got other code in another event or script that is changing the sprite_index, image_speed or image_index so that your spr_cleric_teleport never actually ends.

I would create a brand new object, paste ONLY the teleport code into it, in your room place the new object on top of the fence and see if it changes animation when you run the game.

On a side note, unless you have only one fence object in the game your Fence.x and Fence.y is going to break, as jo-thijs noted above. If you use object IDs as an identifer, GM:S automatically only picks the first instance of that object for the code resolution. Hence it may end up always being positive or always being negative, and is not actually doing proper collision checking.
 
Top