Activate near switch sprite with keyboard ?

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello !

    I didn't find any answer with search, so I'm here to ask.

    I want to activate event (for example turn on/off a switch, or call an elevator, or talk to a PNJ) when my sprite player is near an other sprite and the space key is pressed.

    My example is in top view, like old 16 bits RPG and I can't find a easy way to do what I want.

    With coordinates ? It's complicate if there are many points where the event can be run.

    With collision ? Hmmm, not really. The event should be run also when the player sprite isn't moving.

    Any other ideas ? It seems to be a classic issue, but I can't find any easy way to do it in tutorials or Kiatric FAQ !

  • Example capx

    It is pretty much using how events work.

    Also the collision has nothing to see with the fact that the sprite is moving or not, it just checks at that moment if the sprites are in collision/overlapping each other.

    In this example, having as top event the "On "Space" pressed" trigger allows to make sure the sub events (collisions) are not checked each tick.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for your quick answer !

    I forgot a little thing : my "switch/PNJ/Sprite2 in your capx example" has a solid behavior, so I can't overlap it, I think. How can I run the event in this case ?

    EDIT : Hmmm I can use an other sprite, invisible and a little bigger than the solid, pinned to it, and use the overlapping event between the player sprite and this invisible sprite.

    But not very optimize, isn't it ?

  • Optimisation isn't a big deal.

    Or to be more precise, optimisation is probably not what you think.

    Check this manual entry as well as this one.

    They both present what elements/best practices really make a difference as far as optimisation goes.

    There's also this blog article from Ashley : optimisation: don't waste your time.

    That's it for optimisation.

    For your issue, indeed an invisible sprite could do the job.

    Perhaps explaining clearly what you're trying to do and posting the capx of your project for us to see the settings would help answer you in a definitive way.

    But if you've found a way that's working, just keep with it. As long as it does not mess with the rest of the project it's good enough.

    Also you can, instead of checking for an overlap, check for a distance between Sprite and Sprite2.

    Such example is listed in the how do I FAQ.

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