Collision triggering one event at a time

0 favourites
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi all

    I have falling blocks. I want them to collide with the player character at the bottom of the screen.

    When the falling block collides with the player character, I want the animation frame for another sprite on the right to change from default (in the example, it's zero) to whatever.

    Once the first sprite's animation has been triggered by the falling block colliding with the player, I want the sprite next to it to change it's animation frame from zero to something else.

    I have been at this for days, and I can get it to either change the first sprite ONLY or ALL the sprites at the same time. I can't figure out how to trigger the sprites changing just by colliding with the falling blocks in sequence (ex: the first falling block collision changes the first sprite, the second falling block collision changes the second sprites, the third falling block changes the third sprite etc).

    I also want the falling blocks to stop falling once all the sprites animations have been changed (in this example, after three collisions).

    I would really appreciate any help anyone could give. I'm going outta my mind!

    dl.dropbox.com/u/93047429/fallingtest.capx

  • I can't seem to open your capx. Anyone else getting a grey screen?

    I'm sure others here will have better solutions, but you could do something like add an instance variable called "Order" to your number sprites, then give your first box "1", your second "2" and your last "3". You can then have a condition that says "Sprite instance variable is = to 1" or 2 or 3, giving you the box you are looking for (so it's like manually setting and picking an ID).

    The actual number could be a global variable, so you can say "start global variable at 1", then do the the "where sprite instance variable is = 1", do your animation and then increment the global variable by 1 to 2, then the last number sprite after he has done his animation can set it back to 1.

    <img src="http://i.imgur.com/FM9TE.png" border="0" />

    In the screenshot above I'm setting the next number box ("CurrentNumberBox") in the same area you would have the animation run, but you could easily move the part where the block collides with the player.

    I'm not sure if I'm making myself clear, but it might be enough to get you started :)

  • Is there any chance you could upload a capx? What you're saying makes a lot of sense, I'm just having trouble fitting it all together.

    I updated my capx. The grey screen was a problem, and I think it was a problem with the while loop.

    My capx now correctly triggers the first sprite, but not the second or third :/

    dl.dropbox.com/u/93047429/fallingtest.capx

    Thanks so much!

  • Is this what you want?

    CAPX

  • This is what I want:

    On the first collision, the first sprite goes from transparent to whatever (in this case 0)

    <img src="http://dl.dropbox.com/u/93047429/fall1.png" border="0" />

    On the second collision, the second sprite goes from transparent to whatever (in this case 1)

    <img src="http://dl.dropbox.com/u/93047429/fall2.png" border="0" />

    On the third collision, the third sprite goes from transparent to whatever (in this case 2)

    <img src="http://dl.dropbox.com/u/93047429/fall3.png" border="0" />

    That's what I would like. I can;t seem to figure it out :/

    Thanks guys!

  • Following exactly what you're asking in the post above here is a capx.

  • Awesome, and you are correct, it will do exactly what I illustrated, but what I illiustrated wasn't entierly what I wanted to do.

    The falling block is also supposed to be on of the green sprites, and also a random number each time it falls. When it collides with the player, it makes the corresponding sprite on the right match the number that was on the block. In this way the player can build numbers or words or whatever by colliding or avoiding the blocks.

    I had already figured out how to make the animations of the falling block and the matching sprite match (ex: if the falling block spawned a 7, then on collision the sprite would also switch to a 7), I just can't get it to do so one at a time, and only on collision.

    Think of it like tetris a bit with the falling blocks, only the player can choose to collide with them or not. On collision, the falling block's number or letter gets added to the sprites on the left to make a word or multi digit number.

    So if the falling block spawned C A F T, the player could collide with the C A, avoid the F and collide with the T to spell CAT. Or the player could collide with certain numbers to make a larger number.

    That's what I'm trying to do :/

    It ain't workin :/

    Thanks so much for the help thus far guys. Every little bit helps!

  • Here's an updated capx, still not doing what I want, but I don't know why it isn't. Logically, I don't see why it wouldn't be doing exactly what I am asking it to, as I have described above :/

    http://dl.dropbox.com/u/93047429/fallingTestWhileLoop.capx

    I'm sure I'm doing the while loop incorrectly, but at least I'm not caught in an infinite loop and just getting the grey screen of death any more :/

  • How do you like this?

    CAPX

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Getting there!

    Problem is, if I try to run the second event, they run at the same time.

    I added a wait 3 second to the second event and now it waits to run, but it run automatically after three seconds, even if you move the player out from the collision with the falling block.

    Here's an updated Capx, with movement for the player and the wait added in.

    fallingTest3.capx

  • Right now, I do not understand the problem <img src="smileys/smiley6.gif" border="0" align="middle" />

    But what I definetly can say is, that you haven't understood the Event-Paradigma C2 is based on. Maybe you should start with some of the tutorials to get the hang of it.

    In your last CAPX you have two events, that will be triggered at the same time:

    <img src="https://dl.dropbox.com/u/51594736/SpriteTrigger001.PNG" border="0" />

    Therefore you will get strange results!

  • Following exactly what you're asking in the post above here is a capx.

    I'm gonna go and take another swing at understanding this a bit better Kyatric. I think of everyone you've come the closest, but I don't have much experience with UID's or whatever they are o.9

    This is what I want:

    On the first collision, the first sprite goes from transparent to whatever (in this case 0)

    <img src="http://dl.dropbox.com/u/93047429/fall1.png" border="0">

    On the second collision, the second sprite goes from transparent to whatever (in this case 1)

    <img src="http://dl.dropbox.com/u/93047429/fall2.png" border="0">

    On the third collision, the third sprite goes from transparent to whatever (in this case 2)

    <img src="http://dl.dropbox.com/u/93047429/fall3.png" border="0">

    That's what I would like. I can;t seem to figure it out :/

    Thanks guys!

    Weishaupt:

    Yes, I need those two events in the picture you posted above NOT to be triggered at the same time. I need them to be triggered by the same CONDITION, which is the red box colliding with the green box.

    There must be second condition to make them run separately, because as you say, now they are running at the same time, but I don't know what that condition is. That is what we are looking for. That's the problem.

    The other problem is how to make it such that the red falling blocks keep spawning until each sprite on the right has changed frame.

    For what I want in terms of what the problem is, see my quote above.

    I really appreciate all the help you've given me thus far everyone. I'm learning a lot!

  • <img src="https://dl.dropbox.com/u/51594736/SpriteTrigger002.PNG" border="0" />

    this will prevent the events to be triggered at the same time

  • WAIT 3.00 seconds is what is preventing it from triggering it at the same time. If you move the green player rectangle out of the way of the second falling block, the event still runs, even though the player and the falling block are not colliding :/

  • Following exactly what you're asking in the post above here is a capx.

    Not surprisingly, this works. Two questions:

    How would I get it to stop spawning falling blocks when the third sprite is switched?

    Is there a way you can think of to make the falling block and the sprite face match? For example, if the fallling block was blue, then on collision it would turn the sprite on the right blue as well. I'm working on figuring this out, and had done so before, but I don't understand instance variables very well, or currFrame, so it's like having to relearn it :3

    Thanks again!

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