canvas drawing help (setpen,lineto,putpixel,moveto,erase)

You must understand the Game Editor concepts, before post here.

canvas drawing help (setpen,lineto,putpixel,moveto,erase)

Postby savvy » Wed Apr 20, 2011 4:53 pm

Code: Select all
lineto(0,0);

a function used to draw lines in a canvas from one point to another... helpful in many ways including images.
heres how it works::

Code: Select all
setpen(255,200,250,0,1);

this turns the canvas into.. a canvas of art ;)
255:red
200:green
250:blue
0:transparency
1:line thickness

moveto(0,0);
moves the starting point of your shape/line to this point.
(bare in mind the points are now relevant to the canvas, 0,0 is the top left corner of the canvas.)

lineto(20,20);
this will draw a line from point 0,0 to point 20,20 on the canvas.
the next lineto will draw a line from the above 20,20 to the new point.

for example: a box,
Code: Select all
setpen(255,0,0,0,1);
moveto(0,0);
lineto(0,10);
lineto(10,10);
lineto(10,0);


simple 10x10 pixel box.

can also make the canvas itself a box by replacing the x 10s with width and the y 10s with height.

throughout a canvas you can make the pen colour change, if you want to outline the canvas in blue then draw a box in red. just simply write
setpen with another colour value before your box.

Code: Select all
setpen(0,0,255,0,1);
moveto(0,0);
lineto(width,0);
lineto(width,height);
lineto(0,height);

setpen(255,0,0,0,1);
moveto(10,10);
lineto(10,20);
lineto(20,20);
lineto(20,10);


there is also erase(0,0,0,0);
this is used to remove any unwanted lines/pixels. put this at the top of a script. (below any variable declarations (int i = 0;))

then putpixel(0,0);
this places 1 pixel in the position indecated.

hope this was helpful :) its how many minimaps are made on GE and many games in general, experiment with it and enjoy.

savvy
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby littlenatnatz101 » Wed Apr 20, 2011 4:58 pm

Love this tutorial!! It's awesome.
:wink: well done xxx
littlenatnatz101
 
Posts: 3
Joined: Tue Sep 07, 2010 8:08 pm
Score: 0 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby SuperSonic » Sun May 22, 2011 8:11 pm

Nice :D
(I'd give you a point but I just gave one to Hblade) :(
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby savvy » Fri May 27, 2011 1:38 pm

lol, cheers mate ;)
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby SuperSonic » Sat May 28, 2011 7:25 pm

Never mind, you've got a point now^^
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby Hblade » Sun May 29, 2011 1:30 pm

Nice
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: canvas drawing help (setpen,lineto,putpixel,moveto,erase

Postby ITomi » Sun May 14, 2017 7:07 am

Interesting...
I tried to draw a rectangle with the mouse, but it always shows the previous draws on the screen. What is wrong? Here is the code of my canvas actor:
Code: Select all
int w,h;

setpen(0,0,255,0.0,1);
screen_to_actor(&xmouse, &ymouse);
w=x-xmouse;
h=y-ymouse;
moveto(0,0);
lineto(0,h);
lineto(w,h);
lineto(w,0);
User avatar
ITomi
 
Posts: 48
Joined: Sun Aug 21, 2016 1:56 pm
Location: Hungary
Score: 5 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron