How do you tie into the canvas?

For developers using the Construct 2 Javascript SDK

Post » Tue Jun 11, 2013 8:26 pm

Hi,

I'm trying to understand how the canvas works. So I had pulled up a bunch of tutorials on implementing the canvas in javascript. When I follow the directions and try to fetch the 2d element from the canvas tag it pops up an error.

Can you please guide me into how to hook into the canvas that c2 uses? getelementbyid is just not working for me. :(
www.h1k3.tech

We are here for you!
B
78
S
22
G
15
Posts: 709
Reputation: 16,010

Post » Tue Jun 11, 2013 9:36 pm

The engine already calls getContext on the canvas, and you cannot call it again. Within the scope of the SDK, you should only draw using the canvas 2D context passed to you in the draw() function, and you must also provide a drawGL() function for the WebGL renderer.
Scirra Founder
B
382
S
222
G
85
Posts: 23,987
Reputation: 189,461

Post » Tue Jun 11, 2013 10:20 pm

@Ashley

I apologize for the silly question, but what is the reference point in the draw function?   Something like this.ctx.drawline...?
www.h1k3.tech

We are here for you!
B
78
S
22
G
15
Posts: 709
Reputation: 16,010

Post » Wed Jun 12, 2013 1:01 pm

Look at the other plugins in the install directory to see what they do. They draw something at their X and Y co-ordinate, or inside their bounding quad. Note in the C2 engine plugins are not allowed to draw outside their bounding quad.
Scirra Founder
B
382
S
222
G
85
Posts: 23,987
Reputation: 189,461

Post » Wed Jun 12, 2013 6:00 pm

Thanks I figured it out last night. :)
www.h1k3.tech

We are here for you!
B
78
S
22
G
15
Posts: 709
Reputation: 16,010


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest