Need help understanding screen_to_actor and actor_to_screen

Game Editor comments and discussion.

Need help understanding screen_to_actor and actor_to_screen

Postby yttermayn » Sat Mar 06, 2010 4:25 pm

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?
yttermayn
 
Posts: 48
Joined: Sun Nov 25, 2007 4:10 pm
Score: 2 Give a positive score

Re: Need help understanding screen_to_actor and actor_to_scr

Postby yttermayn » Sat Mar 06, 2010 6:14 pm

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?
yttermayn
 
Posts: 48
Joined: Sun Nov 25, 2007 4:10 pm
Score: 2 Give a positive score

Re: Need help understanding screen_to_actor and actor_to_scr

Postby Hblade » Sat Mar 06, 2010 6:41 pm

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?
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: Need help understanding screen_to_actor and actor_to_scr

Postby yttermayn » Sat Mar 06, 2010 11:48 pm

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!
yttermayn
 
Posts: 48
Joined: Sun Nov 25, 2007 4:10 pm
Score: 2 Give a positive score

Re: Need help understanding screen_to_actor and actor_to_scr

Postby Hblade » Sun Mar 07, 2010 12:53 pm

I never use ScreeN_To_Actor. You can try watching the tutorials built into Game Editor, I think one of them uses ScreeNToActor
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: Need help understanding screen_to_actor and actor_to_scr

Postby skydereign » Sun Mar 07, 2010 1:15 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron