Page 1 of 1

Character exiting the screen

PostPosted: Thu Dec 15, 2011 9:02 pm
by envy06
I would like to ask for help. How will I make my character when he exits on the left part of the screen, he will appear on the right part of the screen and vice versa? Any suggestions? Thanks a lot

Re: Character exiting the screen

PostPosted: Thu Dec 15, 2011 9:11 pm
by skydereign
You can add this event to the player.
player -> Out of Vision -> Script Editor
Code: Select all
x+=(view.width+width) * ((x>view.x+view.width) - (x<view.x));


What it does is move the player by the view's width plus the actor's width forward or backward when it leaves the view. That way it will appear to the right or left of the view. The (x>view.x+view.width)-(x<view.x) part returns a 1 or -1 during an out of vision event, and that is used to determine which direction the actor needs to move in.

Re: Character exiting the screen

PostPosted: Fri Dec 16, 2011 4:23 am
by envy06
skydereign wrote:You can add this event to the player.
player -> Out of Vision -> Script Editor
Code: Select all
x+=(view.width+width) * ((x>view.x+view.width) - (x<view.x));


What it does is move the player by the view's width plus the actor's width forward or backward when it leaves the view. That way it will appear to the right or left of the view. The (x>view.x+view.width)-(x<view.x) part returns a 1 or -1 during an out of vision event, and that is used to determine which direction the actor needs to move in.


err. i tried it sir but still nothing happens..

Re: Character exiting the screen

PostPosted: Fri Dec 16, 2011 4:42 am
by Jagmaster
Fixed:
Code: Select all
x-=(view.width+width) * ((x>view.x+view.width) - (x<view.x));


-= instead of +=.

Re: Character exiting the screen

PostPosted: Fri Dec 16, 2011 6:18 am
by skydereign
Oh yeah. I switched the sign, but forgot to switch the boolean bit to match. It should work with that switch.

Re: Character exiting the screen

PostPosted: Mon Mar 12, 2012 3:11 am
by stemersni
what do you mean of switch the bolean?

Re: Character exiting the screen

PostPosted: Mon Mar 12, 2012 6:30 am
by skydereign
How that bit of code worked was by using statements that resolved to 1s and 0s, as a way of determining direction. For instance (x>5) will return a 0 if x is less than 5, otherwise 1 signifying it was true. So, when I switched the sign from - to +, I forgot to switch the direction of the two statements.
Code: Select all
((x>view.x+view.width) - (x<view.x));
// that's pretty much saying (to the right of the screen) - (to the left of the screen)

If you multiply the result by -1 (switching from - to +) you would need to flip those two ((to the left) - (to the right)).