[PLUGIN] Canvas

Post your completed addons to share with the community

Post » Mon Jul 22, 2013 11:21 pm

yes, check on previous pages comments by R0J0hound
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Wed Jul 24, 2013 7:02 pm

Hi,

I'm trying to make a game that is relying heavily on lighting / dynamic shadows. I found this demo posted by R0J0hound using the canvas plugin:
https://www.dropbox.com/s/y2z9fjaflqrqdkc/shadow_cast%20.capx

Apparently the size of the canvas affects the frame rate. I have tried adding canvas alone to a 1280 * 1024 layout for example and the frame rate dropped at 30 FPS.

I was wondering if it was possible to pin the canvas to an object like say the playable character. I have tried in the example above by pining the canvas to the light called target but the drawing of the shadows is all wrong now. I don't know if it's because I need to recalculate the shadows in the event or if it's simply not possible.

I want to be able to move the canvas around depending on the player position so I try to limit the size of the canvas to let's say 512*512 for example.

Any help would be greatly appreciated specially as I'm pretty bad with math.

Cheers,

EDIT: Well we managed to get the canvas follow the player, so it's working as intended. However depending on the computer, perfrormance are very different and I need to find way to optimize this.
DoudouSupreme2013-07-25 00:08:29
B
12
S
2
Posts: 85
Reputation: 899

Post » Tue Aug 27, 2013 10:17 pm

I find this plugin really interesting for drawing dynamic paths. However, like others have mentioned, the fps hit is terrible when using WebGL and a large canvas object.

Does anyone know what's causing this?

The plugin code is quite clean and small, but my knowledge of WebGL is too limited to understand what could be causing this slowdown in the drawGL() function.
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Thu Aug 29, 2013 6:39 pm

Just did an update to fix to eliminate the memory leak when using webgl. Download on first post.

I also isolated the reason the minifier fails down to the floodfill function, but beyond that I don't know what needs to be changed. So still no fix other than possibly removing that feature.
@Ashley is there a way to display an error log of the closure compiler if it fails? I could not find any laying around the c2 folder.

@SirSpunky
It is slow with webgl on because it copies the canvas to a texture every frame. It's faster with webgl off as it avoids doing that.
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Thu Aug 29, 2013 7:26 pm

Well do you really need that feature?
Its not like you can't fill via paths.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Thu Aug 29, 2013 9:05 pm

@R0J0hound
Wow, amazing, you did it! Now it runs perfect for me with WebGL enabled. Thanks a lot!!!
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Sat Aug 31, 2013 5:33 am

@SirSpunky How large is the canvas object in your app? I downloaded R0J0's updated from the link in the first post and I'm still seeing about 9 FPS on iOS. At this time my canvas object is about 50% of the screen. Got a solid 60 FPS prior to CJS 1.4 and WebGL.

Btw, R0J0, thanks for the great plugin and for continuing work on it!

Thanks!
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

Post » Sat Aug 31, 2013 6:45 am

@R0J0hound not sure if you can help with this, but I'm seeing this error when switching off of a layout that contains a canvas object. This is new since your update:

Uncaught ReferenceError: glw is not defined
http://localhost:50000/c2canvas_plugin.js, line 248 (col undefined)

I'll see if I can get around this by explicitly destroying the object or something, but thought I would share. Thanks!
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

Post » Sat Aug 31, 2013 11:15 am

@clrammer
My canvas is 1920x1080. I've only tested on desktop though, and so far I'm only using it to draw basic shapes like lines and circles that I redraw every tick. I'm just using a single canvas object.

Before the update I had 30 fps, but now I'm back at 250, which is the same as without the canvas.

I'm not getting your ReferenceError, although it looks like it might be a bug in instanceProto.onDestroy() as I don't see how glw could be defined. Not sure if this is related to your performance though.

You mean your fps is the same as before the update, with WebGL enabled? And you're sure the fps drop is caused by the canvas? Maybe you could try on desktop to figure out if it's on iOS only?
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Sat Aug 31, 2013 3:25 pm

@SirSpunky
Thanks for the info. Quick summary of my situation:

1) One canvas object, about 50% of the screen, used exclusively to draw lines (drawing with your finger).

2) With CJS 1.3, performance on iOS was great (60 fps). Performance was stellar in Chrome as well.

3) After CJS 1.4, performance on iOS dropped to 9 FPS even when idle. Performance in Chrome is still excellent.

4) I tried disabling WebGL for my app, but it won't launch on iOS at all due to the memory management that is lost (several layouts with large images that work totally fine when they are only loaded into RAM when that layout is active - which is what CJS 1.4 introduced, apparently leveraging WebGL to do it).

Now that I understand more what's happening, it makes sense to me why all three statements above happened. So, at this point, I'm trying to figure out how to creatively work around the inherent performance hit of using WebGL and canvas together.

Think it would be possible to only spawn a very small canvas object when the user touches the screen that follows the finger and somehow "paste" the trailing line to the screen?

As a final note, I'm certain the glw error is not related to performance. I've been unable to figure out how to work around it, although I got lucky a few times and was able to exit out of the layout without getting the error, but I can't reliably reproduce that.
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest