How do i get inst ctx from a behaviour

For developers using the Construct 2 Javascript SDK

Post » Tue Dec 20, 2016 6:55 pm

I'm making a behavior for the text plugin and i have a function call: Stroke Text.

I want to add:
Code: Select all
ctx.strokeText
.

But i don't have the ctx.

1. How do i get the ctx from text plugin to use?
2. Another thing, can i make a draw function in a behaviour? How do i draw in the instance from a behaviour?
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Tue Dec 20, 2016 10:42 pm

@andykenobi
1- If your behavior is going to be applied on the C2 Text plugin, then you can get access to its ctx with :
Code: Select all
var ctx = this.inst.myctx;

2- Unfortunately there is not drawing prototype in behaviors. I recommend making a plugin instead if you need to draw stuff.
Banned User
B
17
S
7
G
24
Posts: 388
Reputation: 14,494

Post » Wed Dec 21, 2016 11:45 am

That context is private to the Text object, you shouldn't mess with it. IIRC it creates its own 2D context, even in WebGL mode, for text rendering.
Scirra Founder
B
400
S
237
G
89
Posts: 24,550
Reputation: 195,537

Post » Thu Dec 22, 2016 8:56 pm

Ashley wrote:That context is private to the Text object, you shouldn't mess with it. IIRC it creates its own 2D context, even in WebGL mode, for text rendering.


Hum i got it. Thanks
B
14
S
6
G
2
Posts: 81
Reputation: 2,241


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests