Get random animation when sprite is linked to an array

0 favourites
  • 11 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Hello Scirra Universe!

    Let me start by saying that I am currently using the free version, once this issue is resolved, I can finally buy the full version (yay!)

    I have a question, which I am completely embarrassed about having to ask (especially because it is probably something stupidly easy). I just cannot figure it out no matter how much I play around with it or how much I search on the topic, but here it goes:

    I have this lovely template that was posted quite a while back, that allows me to make a quiz-type of game. I was able to use it just fine for one of my level types, but now I am having an issue with my next level type.

    I have two sprites: QuestionSprite (22 frames)

    AnswerSprite (2 frames-current level)

    (The sprites are linked through arrays: ArrayTrivia,

    ArrayCorrectAnswer, ArrayQuestionOrder)

    In my previous level type, QuestionSprite would appear, and the player would click the AnswerSprite that matched the QuestionSprite. After each click both the QuestionSprite and AnswerSprite would change animations.

    For my new level type, QuestionSprite will be spawned from 4 different spawn points, each animation will be random, and will move from top to bottom. When AnswerSprite shows an image, player will click the QuestionSprite that matches. AnswerSprite should continue randomly changing animations, while QuestionSprite should never change.

    So here is my problem: QuestionSprite won't come up randomly, at all, no matter what I try. Every animation coming from the spawn points is Animation 0 (so instead of seeing different animations, its all the first animation in my sprite). I have tried using random(does nothing), int(random) (flips through animations too fast to see them), choose (which I knew wouldn't work, but what the heck right?). Also, if I try .width on any of them, or .animationframe, it either flips through too fast, or creates issues with AnswerSprite and QuestionSprite matching.

    I have been working on this for a while now (too long to say, because I am really ashamed I couldn't figure it out). If anyone out there could help me, I would appreciate it more than you could ever imagine! I look forward to hearing something soon (hopefully ) Thanks!!!

  • Are you sure your array contains any data when this function is executed?

    I suggest running your game in Debug Mode (Ctrl-F4) and check everything.

    If you still unable to solve this, please share your capx.

  • Looks like some comments for the past hour or so disappeared..

    Try this file:

    dropbox.com/s/up42tkyv7r3oumn/IDPractice-share2.capx

    There are lots of problems with the code, I fixed the most obvious few.

  • I see that a few posts have been deleted as well, but when I go through my personal messages all the old pop up and not the new. So...

    I am not sure if you happened to see what I said before, but the images are random (perfect) but now the letter is not matching with the corresponding picture (beginning sounds). Would you mind if I send you a pm with a different capx. One that will maybe help you understand what the capx I sent is trying to do?

  • Dop,

    Apologies, I opened an email stating you sent me a pm, but when I click the link error 404 comes up. I will go ahead and just post both capx here instead of emailing.

    The first capx titled FITB-share is a project that is working perfectly. It is a "beginning" sounds game, in which the player matches the beginning letter with the matching letter. The sprite containing the "Question Images" is QuestionSprite, while AnswerSprite holds the "Answer Images"

    The capx titled ID-share is similar, though there are differences:

    • click on SpriteQuestion, instead of SpriteAnswer
    • SpriteQuestion drops from top to bottom, while SpriteAnswer stays in one spot
    • And of course, the problem I am having: SpriteQuestion should never change; there should be a random animation frame from SpriteQuestion that appears (with 4 sprite spawners,there should be 4 different images)-I want them to repeat, but I don't want all the images the same (which you will see they are with the capx I post)

    It is all set up to match, it is just the darned images all come up as one image. If I enter certain code, like (random),int(random), or floor(random) the images go haywire.

    Thanks again for your time, you're awesome! :D

    https://www.dropbox.com/s/spc47bipku0516m/FITB-Share.capx?dl=0

    https://www.dropbox.com/s/n7x9j3v2beu1x9c/IDPractice-share.capx?dl=0

  • Hey,

    Sorry, the project is a complete mess.. It will take a lot of time to make it right. You select an answer and then players should click correct questions?! This is some broken logic! :)

    I suggest you search for a better example, there should be lots of tutorials on how to make this kind of quiz games.

    .

    And all this can be done much much easier. You don't need any arrays.

    You need one "Question" sprite with animations A, B, C, D etc. Each animation contains one frame - big fancy letter.

    And one "Answer" sprite with animations also named A, B, C, D etc. Only in this sprite each animation should contain lots of different pictures starting with this letter. For example, in animation A you can have two frames - airplane and acorn.

    .

    So when the game starts, you set a random animation name to the question sprite, say "B".

    Then you spawn different answers, with random animations and random frames from each animation.

    When player clicks an answer, you simply check if question.AnimationName=answer.AnimationName

    If animation names match, the answer was correct, that's it!

  • "You select an answer and then players should click correct questions?! This is some broken logic! :)"

    Well, thing is: the FITB capx was the original. So I wanted to take that and pretty much do the opposite (but, because I did it in a lazy way, without renaming and such, it does seem like broken logic.It makes sense in my head, sort of ha!). Really, it was that i wanted my sprites to work opposite in the ID capx than in the FITB capx.

    I will try what you have suggested. In the past I have asked for help matching, and always was told to use arrays. As easy as your suggestion sounds, if I cannot figure it out after a couple of days, would you mind posting a capx? Not now, of course, just if i get to the point of ripping my hair out? ;)

  • dop2000 "When player clicks an answer, you simply check if question.AnimationName=answer.AnimationName"

    I am a little confused by this. How do you specify which animation name you are referring to? I guess, how does the system know which animations I am comparing

    Would you mind typing out a line or two as an example please? Not a capx or anything, just something simple as a guide.

    Thanks for your help, you're awesome!

  • So you have one Question sprite with animations A,B,C,D etc.

    And many Answer sprites also with animations A,B,C,D etc.

    When you spawn Answer sprites, you set random animation and random frame like this:

    Answer set animation to Choose("A", "B", "C", "D"...)
    Answer set frame to int(random(self.AnimationFrameCount))
    

    .

    Then when player clicks on the answer you check if animations match:

    Mouse On Click on Answer
     System Compare two values: Answer.AnimationName=Question.AnimationName
    

    If they match then the answer is correct.

  • Try Construct 3

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

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

    Thank you, thank you, and did I say, thank you...(?)! I assumed that there would be a way to call specific animations, without actually naming the animations the same name. You are an amazing life saver that I would hug if I could! I was totally in the dark, and you not only helped me get it, but you taught me something new that I will never forget. Thanks again Dop, you are really amazing!!! :D :D :D

  • Hey, no problem! :)

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