How do I spawn only as many frames as are in an animation in a grid?

0 favourites
  • 5 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • C3 / Windows 11

    I have 17 animations.

    Each animation has between 5 and 40 frames.

    Depending on which button is tapped or clicked a var is changed triggering an animation.

    When the user taps that button I need all the frames to spawn in a 4 x ? grid.

    4 across and however many down - because setting up with copies of a sprite, each set to a different frame - doesn't work.

    If I don't spawn them, there are other issues with the frame selection. If I have 40 copies of the sprite each with a frame selected and there are 40 frames in the that animation it all works hunky dory. BUT If I click the next button and there are only 10 frames, then I get the 10 frames and then frame 10 is repeated 30 times. Not Ideal.

    BUT then it gets even less ideal. If I click on the first button again - the one with the animation with 40 frames - I get the first 10 frames and the 10th frame repeats itself 30 times. [Mother had no idea there would be days like this!]

    So, I thought, what if I told the program, when button 1 is pressed and var 1 is selected, look at how many frames there are in that animation 1 and spawn a 4 x ? grid of all those frames. And then when button 2 is selected, destroy all those frames and spawn all the frames in animation 2 in a 4 x ? grid.

    After 3 days - I'm rethinking my life choices.

    And just for an added level of difficulty, in the future I want these to scroll vertically. And they can't be random .... dear God - every demo seems to be random.

    Please tell me there is a demo for something like this. I'm not sure how many more brain cells I can spawn.

  • You can have the instances already laid out with a variable id for the frame to display. Then on button pressed you say : sprite set animation to relevant anim, this will change all the instances. Then set frame to sprite.id. You will need extra logic to make the irrelevant ones invisible, something like if sprite.id greater than animationframecount then set invisible.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is how far I got, but there are sooo many bugs.

    drive.google.com/file/d/1xXK-Xw7k9yt-QcI25NWb6kvsMw-mpJev/view

    The sprite (StoreItem) has 7 animation (Item_X) and each animation has between 1 and 15 frames.

    If Item_0 has 8 frames (0-7) then that's the number of frames every animation is allotted. If I change Item_0 to 15 frames, all the other animations are allotted 15 frames.

    And even when animation Item_0 has 15 frames, they don't line up right. All the other Item_X line up correctly, but not Item_0

    I can't begin to describe all the things I've tried. I even copied the text and pasted it into ChatGPT and sent it into an endless loop.

  • I cleaned it up and sorted it for you. Tbh the main problem was that you are referencing storeItem then creating storeItems and it gets confusing because on your 'destroy' event you destroy the original storeItem and it doesn't know what to do. So here I added a separate reference object called storeItem_ref

    dropbox.com/scl/fi/9eso4ul7rjdhx268vttjr/Grid-Slide_edited.c3p

    I also created a second option where it doesn't use a second object as maybe it's awkward to keep matching them with animations so this instead spawns tiles and destroys ones later that don't belong based on frame

    dropbox.com/scl/fi/ijmq8brajlwzlo8uy2lk2/Grid-Slide_edited2.c3p

  • lionz

    THANK YOU!!

    I like yours way much better. I need to get more comfortable with loops. I remember in programming glasses forgetting to close my loop and locking up the computer - it made me loop shy.

    Thanks again.

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