I still can't figure out this...

Discussion and feedback on Construct 2

Post » Wed Jul 15, 2015 6:27 am

2 years of C2, a very complex game in development, and still i can't do this:

I want an object to test if it is overlapping another object at a specific image point (in this case the Origin). I know i can spawn a test sprite at the image point, i just want to do it in the simpliest and more performance convenient way, is there one?
B
66
S
22
G
4
Posts: 360
Reputation: 6,584

Post » Wed Jul 15, 2015 7:18 am

Well i cant imagine doing it that way would affect performance at all.
B
49
S
16
G
9
Posts: 1,098
Reputation: 11,222

Post » Wed Jul 15, 2015 7:41 am

It does, i tried. I got hundreds objects, even if i check every 10 seconds, the lag caused by the evet is there. Because i need to put For Each object -> create test sprite -> test sprite overlaps/dont overlap. Basically, it has to repeat the event for every object.

While simply overlapping condition doesn't. I'm wondering if there is a way to avoid for each and just test if the sprite overlaps at the origin point.
B
66
S
22
G
4
Posts: 360
Reputation: 6,584

Post » Wed Jul 15, 2015 7:53 am

As far as i can see any testing you need to do on lots of objects will have to involve using For each.
B
49
S
16
G
9
Posts: 1,098
Reputation: 11,222

Post » Wed Jul 15, 2015 8:37 am

You can do some short cutting though. If you want to test an individual point faster you will have to do some of the optimisation the hard way I think. If your object fits in a box of size x by y then x+y is an upper bound on the distance from the point of any point in the box, and you could use this to eliminate a lot of sprite objects. Exactly how depends on what you are testing and what they are doing. If that doesn't work the solution might be a JS plugin
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Wed Jul 15, 2015 8:37 am

@spongehammer

Nope, here's an example:

All "Stones" that overlap "Tree" enable a variable, say "Shaded".

I can simply use:

Every 10 seconds
Stone overlaps Tree
-----------------------> Stone set Shaded to 1

And that's how it works now, it is very performant indeed, even with hundred stones.

I just need to know if i can test if the Stone is overlapping Tree at its Origin point, without using for each or creating new sprites.
B
66
S
22
G
4
Posts: 360
Reputation: 6,584

Post » Wed Jul 15, 2015 8:41 am

I came up with a workaround that seems to work for my case.

I simply reduce all objects size by a factor of 100, and then make them bigger again just after the check. This reduces the object to a tiny dot, basically, just what i wanted.

Since i use the self.width /height thing, the process doesnt require For Each, and as far as my testing is right, it is performance-friendly, there is no lag like with the other workarounds.
B
66
S
22
G
4
Posts: 360
Reputation: 6,584

Post » Wed Jul 15, 2015 10:18 am

With this you can easily test if it overlaps at the other sprites origin. Or have I misunderstood?

Demo¨(Drag & Drop)
https://dl.dropboxusercontent.com/u/100 ... index.html


Edit: Realized that I made a mistake. So this doesn't work :P
Last edited by Anonnymitet on Wed Jul 15, 2015 10:51 am, edited 2 times in total.
B
57
S
24
G
14
Posts: 771
Reputation: 13,133

Post » Wed Jul 15, 2015 10:25 am

Danwood wrote:It does, i tried. I got hundreds objects, even if i check every 10 seconds, the lag caused by the evet is there. Because i need to put For Each object -> create test sprite -> test sprite overlaps/dont overlap. Basically, it has to repeat the event for every object.

(Emphasis added)
Creating a sprite is a far more performance intensive than checking for an overlap! Instead you should just have one instance of a 1x1 sprite which you simply position to the image point, then test for overlap with. If you are just moving around one instance of the "detector" sprite and not constantly creating and destroying them, it should be perfectly performant.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Wed Jul 15, 2015 11:03 am

What about the System expression: Pick overlapping point?
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,244
Reputation: 45,962

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests