Extra resources for plugins

Discussion and feedback on Construct 2

Post » Mon Feb 07, 2011 3:48 pm

If I wrote a plugin that interacted with the DOM (I know it has limited use and is slightly off what C2 is about, but netherless I think there are lots of useful applications for it) how would you go about adding extra resources to a plugin so they get exported as well?

IE some images.
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,897

Post » Mon Feb 07, 2011 3:51 pm

There's no way yet, but a good workaround in the mean time would be to nick the texture of an existing sprite - the texture_img member of the Sprite type is a browser Image class for the texture. For example, this.runtime.types["MySprite"].texture_img would get the image for a sprite called "MySprite", which you can then put in the DOM somewhere.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Feb 07, 2011 3:53 pm

Out of curiosity how is that handled if the project doesn't have the sprite object available? (The user didn't add it).
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,897

Post » Mon Feb 07, 2011 6:47 pm

It's just ordinary javascript accesses, so this.runtime.types["MySprite"] will return undefined if the object type with the name "MySprite" doesn't exist, and this.runtime.types["MySprite"].texture_img will also return undefined if there is an object type called "MySprite", but for some reason they gave that name to a non-Sprite object (e.g. text).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to Construct 2 General

Who is online

Users browsing this forum: Ashley, Elliott and 17 guests