Behavior Help ?

For developers using the Construct 2 Javascript SDK

Post » Tue Sep 25, 2012 12:49 pm

I have created a behavior that moves a enemy in a grid and is restricted by solid objects. I would like to make each enemy not overlap each other inside the behavior. Can anybody point me in the right direction to add the functionality to my behavior.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Tue Sep 25, 2012 1:40 pm

So basically i'm asking how do I get the x and y postion of each instance so i can check for overlap?
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Tue Sep 25, 2012 2:15 pm

Tried the following code and it gets stuck at cnd.type, it says its null.

[CODE]
var runtime = this.runtime;
var cnd = runtime.getCurrentCondition();
var mytype = cnd.type;
var mysol = mytype.getCurrentSol();
var myinstances = mysol.getObjects();
var mylen, myl;
var myflag = 0;

for (myl = 0, mylen = myinstances.length; myl < mylen; myl++)
{
    myinst = myinstances[myl];
    if ( myinst.x == this.inst.x && myinst.y == this.inst.y )
    {
        myflag = 1;
    }
}
[/CODE] rfisher2012-09-25 14:18:40
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Tue Sep 25, 2012 3:57 pm

Here is the code that solved my problem.

[CODE]

var mylen, myl;
var myflag = 0;
var mytype = this.inst.type;
var myinstances = mytype.instances;

for (myl = 0, mylen = myinstances.length; myl < mylen; myl++)
{
    myinst = myinstances[myl];
    if ( myinst.x == this.inst.x && myinst.y == this.inst.y && this.inst.get_iid() != myinst.get_iid() )
    {
        myflag = 1;
    }
}

[/CODE]
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