rapid fire on touch release

0 favourites
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • Hi Community,

    I'm trying to create an event: - that shoots 10 balls when touch is released.... similar function to mobrix's brick breaker 'https://www.youtube.com/watch?v=ye49bSWL7Po'


    Player holds down to move position. Angle stick follows touch. On release, it should spawn 10 balls (but this isn't happening)... one 1 is spawned, dispute System/Repeat assigned. Not sure if a while would suit this purpose, but I'll try searching on scirra for that one.

    Here's my attempt http://robfreeman.co.uk/demo/

    The project code is on the end.... pause the video to have a laugh.

    I'd be grateful if any assistance.

    Best Regards,


  • Hey RobertoFreemano!

    Are you sure it's not spawning all ten balls one over the other. I would guess that's what's happening...

    Check this capx: https://www.dropbox.com/s/ft721rvpbu8gw ... .capx?dl=0

    Hope this helps. Cheers"

  • RobertoFreemano

    Just to add to Bruno's answer - when you have a problem like this, start your game in Debug mode (Ctrl-F4). You would see that the number of ball instances is 10, as they are all spawned at the same moment.

    Debug Mode is the one of the best features in C2 and everybody should use it!

  • Wow Bruno, your example is awesome. I will try rebuild mine from scratch - based on your example.

    ...and thank you dop2000, I've never really used the Debug mode TBH. Are there any tutorials about this online?

    Thanks again Guys!

    Muchos appreciated


  • You don't need tutorials, just run the game in Debug Mode and explore all tabs, click everything and see what happens

  • One more associated question, if I may?

    Q: How would you restrict the player from firing again - once all 10 shots fired? I want to avoid being able to shoot again until all the balls are destroyed.

    I've tried:

    * spCannon.shotsfired > 10 -- spCannon Destroy

    (This is where I get bamboozed) - spBullet.On destroyed -- system create spCannon.

    Now I used Debug (thanks dop2000) and it shows creating spCannon per bullet destroy (ouch); which is 10 times (ouch)

  • Do you always destroy a gun after firing one clip?

    Just add another condition to your "On touch end" event:

    System -> Compare two variables -> spBullet.Count=0

    You need to make sure that all bullets get destroyed eventually. You can add "Destroy outside of layout" behavior.

  • Awesome!!!

    Thanks dop2000.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, in the capx I sent you can only fire again after the instance variable shooting is set to false. Currently, I was setting it to false when the last shot was fired. But you could just as easily set it to false only after the last shot is destroyed.

  • Thanks Bruno!

    i have another issue (related to same project)... would it be rude to add to this or would you prefer i raise a new POST?

  • Now that I have bullets, the objective is to knock out incoming badGuys (in the form of blocks((at this stage)).

    The badGuys randomly spawns at the top of the screen and slowly descends.


    . each badGuy has a Instance variable (health). I used PIN to pin a textbox to that badGuy.

    .. when a ball strikes, the badGuy's health goes down.

    ... if badGuy's health is <=0, he is destroyed && so is the textbox that's pinned.

    The issue(s) I'm having:

    . some badGuy's lose their health textbox

    . other's inherit other badGuy's loss.

    Hope this make's sense. I'm not sure if this is caused by over-lapping badGuy sprites?????

    I've updated the URL to show you what's happening.


  • Add 'Text2' and 'bad' to the same container.

    These two objects will be created together, destroyed together and logically linked to each other.

    When you create bad, text2 will appear automatically. You destroy bad and text2 will be destroyed too.

    So remove steps where you create/destroy text2, you only need to pin it.

    Also, when you have to repeat the same code twice, this means you need to move it into a function.

    Create a function "SpawnBad" and call it when you need to spawn a new enemy.

  • Wow dop2000, your suggestions are really super helpful.

    I don't know why I didn't use a function, I have used them before.

    As for the container (wow)... that almost fixed it... my game has developed a bizarre issue.

    When i run in debug, 2 badGuys are created - one scrolling right & the correct one scrolling down.

    Any ideas? I've posted http://robfreeman.co.uk/demo/



  • As I said in my previous comment, you don't need to destroy text2 and you don't need to create text2!

    Remove entire event 16, and remove "create Text2" from event 18.

    When you create Text2, another pair of Bad+Text2 is created (as they are in the same container). That's why you have some sprites scrolling to the right.

    Also, why are you destroying and then immediately creating the spCannon? What's the point?

  • Thanks sooooo much dop2000, I've learnt a lot from You & Bruno. I managed to clean up my messy code.

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