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
153
S
40
G
33
Posts: 4,336
Reputation: 52,570

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
382
S
223
G
86
Posts: 23,991
Reputation: 189,739

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
153
S
40
G
33
Posts: 4,336
Reputation: 52,570

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
382
S
223
G
86
Posts: 23,991
Reputation: 189,739


Return to Construct 2 General

Who is online

Users browsing this forum: snafu79213 and 5 guests