Character exiting the screen

Non-platform specific questions.

Character exiting the screen

Postby envy06 » Thu Dec 15, 2011 9:02 pm

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
envy06
 
Posts: 5
Joined: Wed Nov 23, 2011 5:04 pm
Score: 0 Give a positive score

Re: Character exiting the screen

Postby skydereign » Thu Dec 15, 2011 9:11 pm

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

Re: Character exiting the screen

Postby envy06 » Fri Dec 16, 2011 4:23 am

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..
envy06
 
Posts: 5
Joined: Wed Nov 23, 2011 5:04 pm
Score: 0 Give a positive score

Re: Character exiting the screen

Postby Jagmaster » Fri Dec 16, 2011 4:42 am

Fixed:
Code: Select all
x-=(view.width+width) * ((x>view.x+view.width) - (x<view.x));


-= instead of +=.
User avatar
Jagmaster
 
Posts: 807
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 68 Give a positive score

Re: Character exiting the screen

Postby skydereign » Fri Dec 16, 2011 6:18 am

Oh yeah. I switched the sign, but forgot to switch the boolean bit to match. It should work with that switch.
User avatar
skydereign
 
Posts: 3443
Joined: Mon Jul 28, 2008 8:29 am
Score: 569 Give a positive score

Re: Character exiting the screen

Postby stemersni » Mon Mar 12, 2012 3:11 am

what do you mean of switch the bolean?
stemersni
 
Posts: 4
Joined: Fri Jan 06, 2012 3:59 pm
Score: 0 Give a positive score

Re: Character exiting the screen

Postby skydereign » Mon Mar 12, 2012 6:30 am

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


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest