I still can't figure out this...

0 favourites
  • 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?

  • Well i cant imagine doing it that way would affect performance at all.

  • 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.

  • As far as i can see any testing you need to do on lots of objects will have to involve using For each.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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.

  • 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 <img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz">

  • 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.

  • What about the System expression: Pick overlapping point?

  • Colludium Exactly. That is the one I used in my example. But can't fix it where I am atm.

    But pick overlapping point

    • stone.x
    • stone.y

    And with the correct conditions is should work

  • So if I'm not missing the point, I guess the easiest way would be something like:

    Overlapping (Image) point

  • Pick by overlapping point? System condition?

  • tunepunk Yeah it's a system expression

    LittleStain That seems to work fine! Had the same thing going on but messed up the conditions

  • My only reservation about using it is I have no idea whether or not it uses collision cells. No biggie for a single check per tick, I guess, but on mobile devices...

    Anonnymitet - I am using my phone and didn't realize you'd already got there!

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