Page 1 of 1

using canvas

PostPosted: Sat Jul 26, 2008 7:06 am
by BlarghNRawr
can i make an actor colide only with the line drawn on a canvas to have a physical response?

Re: using canvas

PostPosted: Sat Jul 26, 2008 8:03 am
by feral
yes you can :D

the important thing to remember ,is to erase your canvas first ,otherwise the collision will occur with the entire canvas rather then what is draw on it ( as a canvas is only semi transparent when created until it is erased)

eg: in create actor (canvas)

erase(0, 0, 0, 1);

also your line should be wider then your motion otherwise you may still go through it
eg: if your motion is x=x+4, or xvelocity=4 then the line should be at least 4 pixels wide otherwise you may "skip" over it.

if your line needs to thinner you can use collsionfree to check for the line before you move.

hope that helps
:D

Re: using canvas

PostPosted: Tue Jul 29, 2008 12:11 pm
by speckford123
feral wrote:yes you can :D

the important thing to remember ,is to erase your canvas first ,otherwise the collision will occur with the entire canvas rather then what is draw on it ( as a canvas is only semi transparent when created until it is erased)

eg: in create actor (canvas)

erase(0, 0, 0, 1);

also your line should be wider then your motion otherwise you may still go through it
eg: if your motion is x=x+4, or xvelocity=4 then the line should be at least 4 pixels wide otherwise you may "skip" over it.

if your line needs to thinner you can use collsionfree to check for the line before you move.

hope that helps
:D


WOAH, WOAH, WOAH! woah................woah...........
for the past 2 years people in the forum have been telling me collisions with the canvas lines was impossible, when did this change all of a sudden?
unless EVERYONE forgot to erase the canvas first..........

well then, now i'm inspired.............

Re: using canvas

PostPosted: Tue Jul 29, 2008 10:33 pm
by BlarghNRawr
oooh, this could be useful, now i can remake that old game of mine...

PAPERWARS EXTREME!!!!! MUAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA :twisted: :twisted: :twisted:

Re: using canvas

PostPosted: Wed Jul 30, 2008 3:57 am
by feral
here is a simple demo of canvas lines and collisions
Just remember to erase canvas first ..



try to get close to the blue lines - cursor keys to move

canvasdraw.zip
(17.03 KiB) Downloaded 94 times


ps: if anyone remembers QIX - this is how to do it..

Re: using canvas

PostPosted: Wed Jul 30, 2008 11:09 pm
by BlarghNRawr
im not allowed 2 download ne thing so...

Re: using canvas

PostPosted: Wed Jul 30, 2008 11:52 pm
by feral
blarghNRawr wrote:im not allowed 2 download ne thing so...


ok ... for a simple demo..

create a canvas actor about half the size of the screen and put this code in the draw actor script

Code: Select all
int top;
int base;
top=rand(200);
base=rand(200);
erase(0,0,0,1);  // this is NEEDED see notes above
setpen(0, 0, 255, 0, 2);
moveto(top,0);
lineto(0,base);


it will draw a random flickering blue line. now simply create another normal actor and move it about and test collisions with the canvas.. and you will see how to use canvas drawn collisions

Re: using canvas

PostPosted: Sun Aug 03, 2008 8:49 pm
by BlarghNRawr
mkay, i will try it when i get home
(im using an ipod touch now :D )