How can i make an actor go to the opposite side of the screen when it hits the edge


1 2 3 4 5 6 7 8 | int a = 20 ; //adjust this to a value you like. It is the distance to the side when the actor is placed on the different side. int w = getWorld().getWidth(); int h = getWorld().getHeight(); int x = getX(); int y = getY(); if (x < a || x > w-a- 1 ) setLocation(w-x- 1 , y); if (y < a || y > h-a- 1 ) setLocation(x, w-y- 1 ); |
1 2 3 4 5 6 | int x = getX(); int y = getY(); int ww = getWorld().getWidth(); int wh = getWorld().getHeight(); if (x%(ww- 1 ) == 0 ) setLocation(( 1 -x/(ww- 1 ))*(ww- 3 )+ 1 , y); if (y%(wh- 1 ) == 0 ) setlocation(x, ( 1 -y/(wh- 1 ))*(wh- 3 )+ 1 ); |
1 2 3 | int ww = getWorld().getWidth(); int wh = getWorld().getHeight(); setLocation((getX()+ww)%ww, (getY()+wh)%wh); |
1 2 3 4 5 6 7 8 | int x = getX(); int y = getY(); int ww = getWorld().getWidth(); int wh = getWorld().getHeight(); if (x == 0 ) setLocation(ww- 2 , y); if (x == ww- 1 ) setLocation( 1 , y); if (y == 0 ) setLocation(x, wh- 2 ); if (y == wh- 1 ) setLocation(x, 1 ); |