Noob Question

For questions about using Classic.

Post » Mon Jun 15, 2009 1:45 am

Hello. First post (obviously). I've been using GameMaker for some time and am now learning Construct because I like the flexibility with things such as particles, image distortion, etc. I also have some background in Python already, so it seemed like a logical extension. However, I've run into a rather simple problem. In the event editor I cannot seem to find any 'On Left Click' events. My goal in my test game is to destroy an object when I left click it. Fairly simple.. only I just can't seem to find where the event is at all.

Thanks.

EDIT: Nevermind, I solved this while randomly clicking around.
B
2
G
3
Posts: 68
Reputation: 986

Post » Mon Jun 15, 2009 1:52 am

[quote:35enhwic]EDIT: Nevermind, I solved this while randomly clicking around.[/quote:35enhwic]

I hope you solved it by discovering that you could add the Mouse & Keyboard object, and using it's On Mouse Button Clicked condition.

If not, that's how you do it :)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Jun 15, 2009 2:23 am

[quote="deadeye":1qee0mpu][quote:1qee0mpu]EDIT: Nevermind, I solved this while randomly clicking around.[/quote:1qee0mpu]

I hope you solved it by discovering that you could add the Mouse & Keyboard object, and using it's On Mouse Button Clicked condition.

If not, that's how you do it :)[/quote:1qee0mpu]

Yes, I did. But! But! I have another question. How can I stop the click from 'piercing' objects. In my game I am randomly spawning asteroids and if I click while one is ontop of the other it destroys both, whereas I'd prefer these to require separate clicks.
B
2
G
3
Posts: 68
Reputation: 986

Post » Mon Jun 15, 2009 3:06 am

I only found one solution
don't worry, most things in construct are easier to do than any other game making package
this is just one of those things

but anyway, the solution is here:
click me!
look at the cap first, before reading, or this will seem even more confusing

make a global variable to track whether any asteroid has been destroyed by the current click
you can make a global variable by making an action to Set a global variable (under system) or a condition to check a global variables value (also under system), when it asks you which variable you want, just click "add new"

then "on left mouse button clicked"
set the global value to zero. Zero will mean "no", because this is a new click, and no asteroids have been destroyed yet

then a subevent, "for each object ordered"
- this will do all your actions, once per object, and put the objects in the order you tell it
make it FOR EACH "asteroid" ordered by asteroid.zindex - descending -
this makes it so the object with the highest z index (in front of other objects) goes first

then another subevent "is global variable" zero
so if your global variable still equals zero, it will run the actions

the actions will be to destroy the Asteroid, and then set the global variable to 1, so when the loop goes to the next asteroid, it won't won't get past the "is global variable" zero condition, and it won't get destroyed
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 15, 2009 3:27 am

Thanks. I'm still going over the logic. It is certainly a... bizarre solution... perhaps an idea for future updates, haha.
B
2
G
3
Posts: 68
Reputation: 986

Post » Mon Jun 15, 2009 3:27 am

always> set pv 'z' to z index.

add a "pick object with the highest (or lowest, i forget if the z index works by going higher or lower) variable" to the click condition. and it will destroy the object which is ontop.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Mon Jun 15, 2009 3:35 am

oh yeah that works, too
here's an example of that solution

click me!

that probably makes more sense to a normal person, too :)
btw, I also forgot which one is topmost (highest or lowest)
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 15, 2009 3:07 pm

A simpler solution that might work:

+ Mouse clicked
+ Asteroid is overlapping some object
+ Pick a random asteroid
-> Destroy asteroid

This way if you click and two asteroids are overlapping, it picks a random one and runs the actions on just that.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests