Page 1 of 1

Need help understanding screen_to_actor and actor_to_screen

PostPosted: Sat Mar 06, 2010 4:25 pm
by yttermayn
I'm having a hard time understanding the screen_to_actor and actor_to_screen functions... The tuts are not much help. I see they take an x and y argument, but where's the output? Also, the tuts show an & in front of xmouse and ymouse, what does that mean?

Re: Need help understanding screen_to_actor and actor_to_scr

PostPosted: Sat Mar 06, 2010 6:14 pm
by yttermayn
Here's what I'm trying to do:

Let's say we have two actors on the screen who are overlapping a canvas actor. I want to be able to draw a line between the two actors onto the canvas actor. How can this be accomplished?

Re: Need help understanding screen_to_actor and actor_to_scr

PostPosted: Sat Mar 06, 2010 6:41 pm
by Hblade
Make the canvas' Z-Depth all the way up, and the view's all the way down (Assuming the 2 actors have the view as the parent), then use this code
Code: Select all
erase(0, 0, 0, .9999); //Reset the drawing
setpen(r, g, b, 0, 1); //r g b = your color
moveto(actor1.x, actor1.y); //Move to the first actor
lineto(actor2.x, actor2.y); //place a line from the first actor to the second actor


Would you like me to make a demo?

Re: Need help understanding screen_to_actor and actor_to_scr

PostPosted: Sat Mar 06, 2010 11:48 pm
by yttermayn
I don't need a demo, I think I get what your showing me. I eventually found a solution on my own, but there are elements of yours that are more elegant. I would appreciate a better explanation of how screen_to_actor works, the ampersand symbol (&), and now erase(): I don't understand what the color and transparency arguments are for.

Thank you!

Re: Need help understanding screen_to_actor and actor_to_scr

PostPosted: Sun Mar 07, 2010 12:53 pm
by Hblade
I never use ScreeN_To_Actor. You can try watching the tutorials built into Game Editor, I think one of them uses ScreeNToActor

Re: Need help understanding screen_to_actor and actor_to_scr

PostPosted: Sun Mar 07, 2010 1:15 pm
by skydereign
First off, you can think of screen_to_actor as a way of converting xy coordinates to a new coordinate system where the origin is the Event Actor. This is really only used with xmouse and ymouse, but what the function essentially does is change xmouse and ymouse within the script that you use screen_to_actor to be xy relative to the actor. You would only want to use this if you want the xmouse or ymouse to be in relation to your actor where (0,0) is now your actor.

For erase, it is a way of filling in a canvas completely, so the values are as follows. Usually people erase to black, or transparent, but erase does allow you to erase to red, or any other color you want.
Code: Select all
erase(r,g,b,transp);


The & sends the address of a pointer, instead of the variable itself, since the screen_to_actor takes to int*, the ampersand is required. This is the main reason screen_to_actor is not used, as you would need to create int* and set them to use, while it is much easier to use basic math to accomplish the same thing.