How to cycle frames on collision?

0 favourites
  • 5 posts
  • So, since yesterday I've been trying to make it so that when I shoot at a cube, it's color will change from red > blue > yellow and it would loop back to red and go through each color again. For the most part I've got it down to the point where the colors will cycle all the way to yellow but when I try to loop it back to red it either doesn't work (and will just stay yellow) or it will go up to blue and then back to red.

    My current setup is this:

    -The Red block has Blue and Yellow colorings in its animation frames (initially I was going to try this with different objects instead but figured this would be less complicated)

    -In the events I have the Collision with another object event as the condition (with the bullet as the colliding object) and the action is the Red Blocks animation Frame being increased by one everytime it is hit.

    Things I've tried so far are:

    -Making a condition where if the bullet hits and the frame = the frame yellow is, it goes back to frame 0 (Results in frame just switching between red and blue).

    -I also tried a greater than or equal to which in hindsight made no sense since the bullet doesn't hit multiple times on one collision.

    -I started to mess around with containers until I figured that was for something else.

    And a couple of other methods that I can't think of off the top of my head. Needless to say, i'm as stumped about this as when I tried to make it work back in Game Maker Studio, everything seems to make sense but I feel like i'm missing one really obscure piece to the puzzle here that I can't figure out. Any assistance, be it tips or answers would be appreciated and thank you in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would do :

    Every tick set animation frame to 'variable'

    Bullet on collision with red block, add 1 to 'variable'

    Bullet on collision with red block

    and variable = 3, set variable to 0.

  • Thanks dude, i'll try this when I get the chance and tell you how it goes.

  • Compact version:

    + Bullet: On collision with Block

    -> Block: Set animation frame to Self.AnimationFrame=2?0:Self.AnimationFrame+1

    This is a conditional operator, and basically means "Is self.animationframe currently 2? If yes, set to 0, if no, add 1."

    So every time a bullet collides with a block, the blocks animation frame will go from 0 to 1, 1 to 2, or 2 to 0.

  • Yep, that did it. Thanks guys, appreciate the help.

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