Activate near switch sprite with keyboard ?

Get help using Construct 2

Post » Mon Jul 30, 2012 9:12 am

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 !
B
40
S
9
G
5
Posts: 127
Reputation: 6,609

Post » Mon Jul 30, 2012 9:46 am

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Mon Jul 30, 2012 10:07 am

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 ?Sylvain2012-07-30 10:25:55
B
40
S
9
G
5
Posts: 127
Reputation: 6,609

Post » Mon Jul 30, 2012 11:29 am

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.Kyatric2012-07-30 11:30:09
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805


Return to How do I....?

Who is online

Users browsing this forum: Callan S and 19 guests