slowdown when drawing lines for >100objects in canvas

Get help using Construct 2

Post » Mon Jan 18, 2016 7:42 am

@christina
Glad it helped the performance.

Changing the position and size of the canvas wouldn't affect the performance. What would affect it, I imagine, is the "resize canvas" action, which changes the texture size. If you can i'd leave the texture size be, and just change the object size. The only issue is the positions would be off when you zoom in and out because the line draw commands are relative to the texture, not the object. This doesn't apply for the "paste" action though, it will paste in place regardless.

Typically when the texture size is the same as the object size you can do this to map layout positions to the canvas:
sprite.x-canvas.left
sprite.y-canvas.top

When the sizes are different you can do this instead:
(sprite.x-canvas.left)*textureWidth/canvas.width
(sprite.y-canvas.top)*textureHeight/canvas.height

I didn't seem to include a way to read the texture width and height so you'll want to save them to variables. Just note when the canvas object is created the texture size will be the same as the object size. Then you if you ever use the "resize canvas" action you'll want to update those variables with the new size.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Jan 19, 2016 11:49 pm

@R0j0hound avoiding canvas resize didn't help unfortunately. Or it wasn't noticeable anyway, and the cost was that the code became a lot less readable with all the coordinate transformations.

But I did realize, I don't need continuous canvas redraws when I'm zooming! So I'm now only requesting a resize+redraw when layout scale is 1, 0.75 and 0.5. As you can imagine performance is stellar.

Thanks for everything <3
B
28
S
12
G
4
Posts: 193
Reputation: 4,581

Previous

Return to How do I....?

Who is online

Users browsing this forum: David181, OBLIVION and 48 guests