Random animation

0 favourites
  • 13 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Oy lads

    I've got some problem with the code now and even when I was looking for a solution here on the forum, I have no idea how to fix it.

    I created a sprite with animations and now I want from my game to pick randomly 1-3 animations from that sprite and save it in the 3 buttons. I setted few variables for this sprite regarding what it will have but I don't know how to create that command "random" after each turn. Since this command is used for numbers and not the texts so I can't point it like "random(sprite.AnimationName)". Any ideas how to fix this?

  • I'd like to know too, so the random only picks the number once.

  • So, lets start from the beginning, what I would of done was this (this is a example of clicking a button to randomize it, but it could be anything):

    Create a new global variable and have it be a number.

    Button On Clicked, System -> Set Value -> (Your global variable) -> "round(random(1,3))" ( remove quotes when typing). This is setting the global variable to be a random number between 1 and 3.

    Now for another event: Click on your character -> Set Animation -> (Your Global Variable name here without those quotes).

    BTW, if you want I can make an example CAPX

    • Ryan, Kdot Development
  • G, this is good. I'll try to explain on what I'm working. That capx would help a lot.

    Sprite: "Planets_Types"

    Vars: Food_amount, Water_Amount

    Boolean: Habitable

    Animation structure:

    Folder: Habitable

    Animations: Habit_TYPE

    Folder: Unhabitable

    Animations: Unhabit_TYPE

    I setted everything for those vars. So the problem is only this animation. I'm using command "tokenat" to find what planet have "water" or "ice" in the name to set higher amounts of water on it.

    If you need something more, feel free to ask me.

  • Insta, will check it tonight. I'm quite busy at the moment. I'll write back asap

  • Well, your logic with the Array is great. For me it is too much time to spend on the thing that is not so necessary for now But still, I'll use it later when I find some more time for the problem I have. Cheers!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oy lads

    I've got some problem with the code now and even when I was looking for a solution here on the forum, I have no idea how to fix it.

    I created a sprite with animations and now I want from my game to pick randomly 1-3 animations from that sprite and save it in the 3 buttons. I setted few variables for this sprite regarding what it will have but I don't know how to create that command "random" after each turn. Since this command is used for numbers and not the texts so I can't point it like "random(sprite.AnimationName)". Any ideas how to fix this?

    What I would do is name all animations as Anim1, Anim2 and Anim3, then when you play the animation simply type

    "Anim"&global_variable

    and that should work..

  • Rob! You made my day! Damn! I have 2 folders with planets in the Sprite animation. Habitable and Unhabitable. Then those planets animations starts with "Habi_" or "Unhabi_" and after the planet section is the type of planet. And every of those instance variables are set for each planet in the code already (With the easiest way - (Tokenat -> look for "Unhabi", set values, ELSE set values).

  • Oh I understand your situation. Changing the animation names everywhere is a pain in the neck. Well, then you can simply put all animation names (strings) into an array and simply pick a random animation. That would be less work in your case.

  • This is what Insta showed me in his capx. Right now I have to set my FTL traveling system right and due I have no such an experience with timers etc I have to find a way how I can fix this problem. Planets are not major problem compare to the FTL. If you want to discuss this, we can thru our PM's.

  • Yeah sure. Btw, may I ask what's FTL?

  • Ehm.... "Faster Than Light"?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)