[PLUGIN] Canvas

Post your completed addons to share with the community

Post » Wed Jul 12, 2017 4:05 pm

Hi I'm struggling with this Plugin but it's difficult as the URL to the example capx is broken :(
How can I resize an image in order to change its resolution? For example: I choose a 128x128 image with the FileChooser, use this Plugin to make it 32x32 and then load this image to a sprite. It is important because I want to encode images into base64 and I need the URLs to be as short as possible (and I don't really care about resolution).

Any clue?
B
20
S
6
Posts: 143
Reputation: 1,666

Post » Mon Jul 17, 2017 4:24 pm

@ome6a1717
Put int() around all the values. Numbers with decimals will make it not work.

@ChesVCF
There should be an action to set the canvas' resolution. That won't resize the image though. For that load the image in a sprite or something, make the sprite size 32x32 and paste it to a canvas of size 32x32.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Tue Jul 18, 2017 3:32 pm

@R0J0hound - ah I'll give that a shot - thanks!!
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Wed Jul 19, 2017 11:01 am

R0J0hound wrote:I really shouldn't make plugins since I have no intention to edit the plugin to fix it. .

@R0J0hound, you shouldn't worry: other people learn from studying the code. If it's 'broken', then at least it provides some motivation for others to learn it (and hopefully modify it to their needs). :D
B
40
S
12
G
1
Posts: 66
Reputation: 2,926

Post » Wed Jul 19, 2017 7:54 pm

@R0J0hound - unfortunately the default variables were already integers and not floats. It just keeps returning black (but when I set the "rgb(x,x,x)" to a text object, it looks the exact same as if I just set the color to "rgb(x,x,x)" using numbers (without variables)

EDIT - I'm wrong. That worked strangely enough. Thank you!
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Thu Jul 20, 2017 4:30 am

@R0J0hound - sorry, one more question. For some reason I got it to work using the int(), but I've just tried to recreate something I have in a different layout (which is working) and its literally the same code, but I can't figure out why it's not working in this new instance.

I'm trying to just get the rgb of a canvas object based on the mouse position (the canvas object is being filled by gradient). I'm just doing "set text box to "rgb("&userGradient.redAt(Mouse.X, Mouse.Y)&","&userGradient.greenAt(Mouse.X, Mouse.Y)&","&userGradient.blueAt(Mouse.X, Mouse.Y)&")", but it's always returning rgb(0,0,0).

I've tried int() on both individual mouse.x and mouse.y, as well as the entirety of the redAt, greenAt, etc.

It just keeps returning 0 for all the paramenters.

EDIT AGAIN (sorry)

AhHA! Got it - I didn't know this breaks when you resize a canvas. For those who were wondering you fix by setting the mouse.x - canvas.x, and mouse.y - canvas.y for each.
Last edited by ome6a1717 on Thu Jul 20, 2017 4:55 am, edited 1 time in total.
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Thu Jul 20, 2017 4:53 am

Is the canvas object at the top left of the layout?

Maybe use
Mouse.x-canvas.bboxleft
Mouse.y-canvas.bboxtop

If it isn't.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Thu Jul 20, 2017 12:23 pm

@R0J0hound

How can I remove canvas objects in memory?

when I create new canvas objects, memory going up.
after I destroy all nothing change
B
13
S
6
Posts: 33
Reputation: 1,081

Post » Thu Jul 20, 2017 11:04 pm

I'm no longer updating plugin's but there may be a leak. Garbage collection doesn't happen immediately when something is destroyed so there's that. The runtime also does something called object recycling that doesn't actually delete the destroyed object so new objects can use it. That is so less garbage is created.

I do know the main memory and cpu hog is every frame the canvas is drawn to I had it create a new webgl texture of it and discarded the previous. Honestly I've never been interested enough to improve that. The plugin was made before c2 had the webgl backend so maybe that explains that.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Previous

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests