Multiple Overlapping Objects

Get help using Construct 2

Post » Fri Aug 17, 2012 9:49 am

Hey guys, just need a little bit of help on a game I've been working on.

The whole point of my game is to take pictures of a night sky, and you're basically rewarded for a picture that has the largest amount of things in it.

So I have randomly spawning meteors, stars, and a moon that follows a path. It's up to the player to try and time their photo correctly, and score the most points on it.

The screen is divided into 9 sections, and the arrow keys navigate around these sections. When spacebar is pressed, a photo is taken, and this is where I would want the score to be calculated.

The problem I am having is figuring how many meteors and stars are within the currently selected section.

I've looked at this thread, but there's one issue. My overlapping object is not circular. If I were to use this, I'd get a lot of false positives on if the selected screen is actually overlapping a meteor or star.

So basically, what is the easiest way to count up how many objects are overlapped by a rectangular object?

Here's the game if anyone is interested.

Thanks in advance.
B
7
Posts: 4
Reputation: 487

Post » Fri Aug 17, 2012 9:59 am

It's actually pretty easy if you stop to think about it.
The guy is checking the distance from each object to a master object, therefore he gets a circle, since they're 300 pixels away from a point in every direction.

Your case is even more straightforward: instead of checking for distance, check whether objects are within a set of X and Y coordinates.

for instance, object's X position is greater than 0, less than 640, and it's Y position is greater than 0 and less than 480, you just covered a 640x480 rectangle in the top-left corner.

Easy isn't it? Rectangles and circles are the easy part, it gets a lot more complex once your area is some weird concave irregular polygon, but it appears you won't be needing that.Fimbul2012-08-17 10:01:19
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Fri Aug 17, 2012 5:25 pm

You can check if the lens object is overlapping an object and then object.PickedCount will tell you how many it's overlapping.

moonStarMeteorOverlapping.capx (r99)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Aug 17, 2012 9:20 pm

That's even better than my method.
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Sat Aug 18, 2012 1:30 am

Well thanks for the help, I figured there would be some expression or something simple I was missing.

Thanks Ramones and Fimbul, I really appreciate it.
B
7
Posts: 4
Reputation: 487


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests