1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Drag And Drop Play sprite animation once in game

Discussion in 'Programming' started by 1R85, Jul 9, 2019.

  1. 1R85

    1R85 Member

    Joined:
    Jul 2, 2019
    Posts:
    6
    In the sprite maker one can toggle between "loop" or "ping-pong",
    but why are there not a "play once" option? Or play x times - where one can change the number of times.

    With DND: How do I make a sprite only play once inside the game?
     
  2. HeWhoShallNotBeNamed

    HeWhoShallNotBeNamed Member

    Joined:
    Nov 9, 2018
    Posts:
    62
    I'm not that familiar with DND, but there should be an event called Animation End. In this, set image_speed to 0. You could also set image_index to 0 if you wanted your sprite to return to its first sub-image after playing.
     
    Toque likes this.
  3. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,330
    Those options are only to preview the animation, they aren't settings you can choose to have the sprite behave in that way when the game is run.
     
  4. 1R85

    1R85 Member

    Joined:
    Jul 2, 2019
    Posts:
    6
    Thank you for the suggestion!
    But I can't seem to figure out how to make an Animation End event with DND. When I search the DND options I don't get any hits.
    Anyone?

    Oh. How do one make the animation ping-pong with DND?
     
  5. pipebkOT

    pipebkOT Member

    Joined:
    Dec 13, 2018
    Posts:
    208
    @1R85
    its called Animation End event, Its and EVENT ,NOT and drag n drop action.

    its on add event >> other >> animation end

    in this event you put the code that checks if the sprite index equals to the sprite that you don't want to loop and set an action.
    example

    Code:
    if sprite_index==sp_player_attack
    {
    sprite_index=sp_player_idle
    image_speed=0.3
    }
    in this example, when the attack animation has ended, the player sprite is set to idle.





    to do a ping pong animation you could just duplicate the sprites of the animation and then sort them in reverse in the sprite editor.
    so you have like in example

    5 animation frames
    +5 duplicated frames in reverse.


    or just put image_speed*=-1 in the animation end event
     
    Last edited: Jul 10, 2019
  6. 1R85

    1R85 Member

    Joined:
    Jul 2, 2019
    Posts:
    6
    Thanks!
    Well, I found:
    Object > Events > Add event > Other > Animation End

    Here I can put DND - or code I guess.

    But:
    Can I do this with DND - and if so - how?
    And if I must code it: How do I add code here? (I hoped I could make games with DND only.. I am not a coder.)
     
  7. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    821
    As others have said image_speed controls the animation playback. 1 is normal speed play back -1 is normal speed but reverse. So multiplying the current speed by minus one will reverse it.

    image_speed = image_speed * -1;

    Can't really help with dnd never used it
     
  8. pipebkOT

    pipebkOT Member

    Joined:
    Dec 13, 2018
    Posts:
    208
    @1R85
    you have two options,


    1 you add a code block only for this time since you don't want to code, with the drag n drop action "execute code"
    and paste the code there. which will take you like 10 seconds

    2 you do it all in drag n drop with is more tedious, since you have to search for every action.

    in both, drag and drop and gml you need to know about coding, and believe me that gml is far more easy, fastest and clean looking than drag and drop.


    here is the code you need in gml

    Code:
    if sprite_index==sp_player_attack   ///or whatever sprite that you don't want to loop
    {
    sprite_index=sp_player_idle
    image_speed=0.3
    but all this depends on what are your needs ,since i don't know if you want to change the sprite after the animation has ended, or if you simply want the animation to stop.


    if you want to do it in drag and drop, you would need a "if variable" action, a "set sprite" action , and a "set speed" action,
    then use the logic to understand what you need to do to fit your needs


    as you see, using drag and drop doesn't guarantee you that you will not need to learn how to code, you in need should learn how to code, how if statements works, how variables work, and what are the built in variables of an object, like image_speed, image_index, sprite_index, etc
     
    Last edited: Jul 11, 2019
  9. 1R85

    1R85 Member

    Joined:
    Jul 2, 2019
    Posts:
    6
    @JackTurbo and @pipebkOT

    Thank you both for your helpful suggestions!
    Woopdeedoo it finally works! :)

    It turned out it was not that much work to do this in DND:
    Object > Events > Add event > Other > Animation End > (DND)
    Set animation (self) speed -1
    Destroy Instans (self)

    Without the "Destroy instans" the animation would play once and then show the first frame of the animation.
    (DND that was done before this was that if the main character touched a special type of enemy an animation would play out.)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice