Drawing directly to the C2 canvas from plugin

Get help using Construct 2

Post » Thu Nov 27, 2014 7:29 am

I'm trying to draw a box directly to the C2 canvas from a plugin... how do I do this?

I tried the following... but perhaps I'm missing something:

Code: Select all
var c = document.getElementById("c2canvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);


It gives me the error: cannot set property "fillstyle" of null

This exact code works fine in any other javascript... so I'm confused. I know I have the right canvas name (c2canvas). Any help?

Perhaps I'm going about this the wrong way... what I want to do, is have only one instance of my plugin, but be able to draw images, and other drawings directly to the canvas at any time, so I'm not limited to just one picture on one layout. I hope I'm making sense. The easiest help you could give me I guess, is how can I make that code above work inside a plugin?

Thanks!
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Thu Nov 27, 2014 7:42 am

you could do it like this
You do not have the required permissions to view the files attached to this post.
B
250
S
39
G
15
Posts: 1,953
Reputation: 40,623

Post » Thu Nov 27, 2014 7:55 am

That will only draw on the canvas that the canvas plugin you inserted created for you. I want to be able to draw something on the main Construct2 canvas. Mainly cause my plugin cannot have more than one instance... and this method would force that.

I also looked inside the canvas plugin, and couldn't find a way to make it draw to the main c2 canvas.... this one will only draw on it's own instance.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625


Post » Thu Nov 27, 2014 8:32 am

If you are writing a plugin and need help, a more appropriate place to post might be in the 'Work in Progress Addons' section.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,386
Reputation: 58,454


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 8 guests