Question about runtime function

For developers using the Construct 2 Javascript SDK

Post » Tue Nov 06, 2012 5:40 pm

I'm trying to use the function

runtime.testAndSelectCanvasPointOverlap(type, x, y, inverted)

to test if a point is overlapping a solid. I'm having trouble with not knowing what is returned by this function and referencing the type variable.

I gave up on using this function and used

runtime.testOverlapSolid(inst)

But this seems the wrong way to go about this.

Any Help
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Thu Nov 08, 2012 12:46 pm

var loccnt = 0;

this.inst.y += this.Mazenavdistance;
this.inst.set_bbox_changed();
var collobj = this.runtime.testOverlapSolid(this.inst);
if ( collobj )
{
    loccnt += 1;
}

this.inst.y -= (this.Mazenavdistance*2);
this.inst.set_bbox_changed();
var collobj = this.runtime.testOverlapSolid(this.inst);
if ( collobj )
{
    loccnt += 2;
}

this.inst.y += this.Mazenavdistance;
this.inst.x += this.Mazenavdistance;
this.inst.set_bbox_changed();
var collobj = this.runtime.testOverlapSolid(this.inst);
if ( collobj )
{
    loccnt += 4;
}

this.inst.x -= (this.Mazenavdistance*2);
this.inst.set_bbox_changed();
var collobj = this.runtime.testOverlapSolid(this.inst);
if ( collobj )
{
    loccnt += 8;
}

this.inst.x += this.Mazenavdistance;
this.inst.set_bbox_changed();

This is the code i'm using to check if there is a solid object in the up, down, right, and left direction. It seems slow to actually have to move the object to the location and then check to see if its overlapping. I would like to use the
runtime.testAndSelectCanvasPointOverlap function, but every attempt has failed(javascript error). I did look at the mouse plugin, but it didn't help me solve the problem.

Any help
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Thu Nov 08, 2012 2:19 pm

You should not use testAndSelectCanvasPointOverlap. It is used internally and modifies the picked objects, which you probably don't want to do. Moving an object then testing for collisions is fine; that's how the Platform behavior works.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Nov 08, 2012 3:20 pm

@ashley

Thank You

B
17
S
9
G
7
Posts: 249
Reputation: 6,922


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests