Plugin help with objects?

For developers using the Construct 2 Javascript SDK

Post » Mon May 28, 2012 3:18 pm

I'm making a plugin and in the edittime.js i'm using AddObjectParam to add a object to my action. Then in runtime.js in the action function i would like to be get the object width and height. I could only fine the following method as a reference.

[CODE]var inst = this.runtime.createInstance(obj, layer,parseInt(temp[0]),parseInt(temp[1]));
var width = inst.width;
var height = inst.height;[/CODE]

I would like to not have to create a instance of the object to just get the width and height.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Mon May 28, 2012 7:18 pm

All instances have width and height properties - why not just access the ones from the object type given to you in the parameter?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon May 28, 2012 8:18 pm

@ashley

I tried

var width = obj.width;
var height = obj.height;

and i got a assertion failure. I think i'm still not doing something wrong.

I just figured it out.

var width = obj.instances[0].width;
var height = obj.instances[0].height;

THANK YOU!!!rfisher2012-05-28 20:28:16
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Tue May 29, 2012 1:01 am

AddObjectParam is to get the "type", not an instance. See the structure of "type" in firebug for more detail.
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests