about canvas, drawing and erasing

Game Editor comments and discussion.

about canvas, drawing and erasing

Postby elfdav » Mon Sep 17, 2012 11:29 pm

Hi guys,

I have made a simple program: i draw on a canvas with a pen. Pretty simple. The canvas back color is black, so if i want to erase what is drawn, i just have to turn the pen color to black and i'm done.

Now, i would like to use a more complex image with many differents colors as a new background. Let's say a sky with some clouds instead of a simple and uniform black back. So i created a new actor called BackGround and put in it my sky with some clouds. Then, i put on it my canvas. I draw some stuff on it (line, etc.). If i want to erase a part of a draw, i must handle transparency: If i draw a red line, i must be able to erase only a part of it and retrieve my original background showing sky and clouds.

I tried this:
erase(0,0,0,0);
putpixel(0,0);

but it erase all my canvas, not just some pixels. HOW can i do to erase just some pixels located unde the mouse and retrieve my original sky and clouds backgrounds instead ???

Thanks so very much for your answers.
elfdav
 
Posts: 14
Joined: Sat Feb 14, 2009 4:18 pm
Score: 0 Give a positive score

Re: about canvas, drawing and erasing

Postby skydereign » Tue Sep 18, 2012 12:11 am

You can make the pen be an eraser with the setpen function.
http://game-editor.com/docs/script_reference.htm wrote:setpen: Define the actual pen for the Event Actor
void setpen(int r, int g, int b, double transp, int pensize)

r: red component (0 - 255)
g: green component (0 - 255)
b: blue component (0 - 255)
transparency: (0.0 - 1.0)
pensize: size of pen

Script Editor Syntax:
setpen(0, 255, 0, 0.0, 3); //set pen color to green, no transparency, pensize 3

Notice you can set transparency, more specifically, setting it to 1.0 will make it an eraser.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: about canvas, drawing and erasing

Postby elfdav » Tue Sep 18, 2012 6:57 am

That's exactly what i was looking for.

Once again thanks for your help Skydereign... very reactive as usual...
elfdav
 
Posts: 14
Joined: Sat Feb 14, 2009 4:18 pm
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest