简体   繁体   中英

How do I make it so the background “switches” when the player moves to the edge of the screen, and teleports them back, as if moving through a world

I'm making a tile-based top-down RPG in Java, and I want the background(and all other objects) to change when the Player gets to the edge of the screen. Then the Player will be teleported to the opposite side of the screen, giving the illusion of movement.

Like this - Example From "Warriors Untold Tales"

So far I've tried everything that has made sense to me, I put in code that when the player's x coordinate gets below 10, they get teleported to the other side, and the background shifts one screen over.

       int Screen = 1;
    //Player Screen Change
    if(Player.x < 10 && Screen == 1) {
        Player.x = 590;
        Screen = 2;
    }

The result of this is the player teleporting over, but the background either not changing, or just quickly flashing for less than a second.

Aha, I figured it out, I had to move the int Screen out of the method, and change it to a static variable. Thanks for having me go back and look at it:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM