Toggles

0 favourites
  • 3 posts
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • I am not a programmer nor a game designer by any means, so I guess i'll be asking some dumb questions, but here we go: I am creating a simple fish tank game, where clicking on different fish causes different actions to occur.

    Question 1:

    I created a global number to toggle a bullet behavior on and off, however I guess because it is global it affects all the fish I create. How do I have the toggle only occur on the specific fish I click?

    Question 2:

    I have a "cursor over" action, that forces the fish to speed up when you mouse over them, how do I set it up that once the cursor is no longer near them they slow down? I would think there would be a "Cursor off" action, but I can't seem to find one.

    Question 3:

    Is there a cursor proximity action? Meaning the closer the cursor is to the object the more it affects it?

    Thanks!

    https://dl.dropbox.com/u/23591936/Fish3.capx

  • 1?> It's easy if you use a global variable "toogle_bullet" the "toogle_bullet" value is global "for all" so the same for all "fish" ... but if using a instance variable "toogle_bullet" in sprite object "fish" ... each fish will have is own "toogle_bullet" variable so different values are managed ! ... i change the number type to boolean because "toogle_bullet" can only be true or false ;-p

    2?) Not so easy because more than one fish ;-p, ok i use a for each "fish" with no problem and it works ! ... using "else" here avoid to reverse the test so "if mouse on this fish do action ..." and after creating a else event = "and if not on this fish do action ... "

    3?) You can use the "distance" function to retrieve the distance beetween a fish X/Y pos and the mouse X/Y pos ... as 2?) there is more than one fish so function is a little bit more difficult and need a for each fish system ... ok as sample i change the speed of each fish depending on distance between "this" fish and the mouse ! so 200 if on this fish and 200-distance between this fish and the mouse if not ;-p ... in fact using this system there is no need at all testing if the mouse is on this fish ;-p

    so i let you made the "final" change like this

    For each fish -> fish set bullet speed to clamp(200 - distance(Mouse.X,Mouse.Y,Fish.X,Fish.Y), 50,200)

    "Clamp" is a method to force a value to a min/max value if lesser than and more than ... so here bullet speed can never be less than "50" and never be more than "200" ... if 200-distance is between 200 and 50 it will take this value...

    The new capx link => here

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks! I can use this concept for sure! The only issue i have with your example is that the fish won't move unless the mouse is near them rather than just them speeding up when the mouse is near. But, this is really helpful, thanks again.

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