Legacy GM Making a seamless room wrap

S

Sanlo

Guest
Hello,

I'm currently trying to create a simple space game where you are able to land on planets.
I want to simulate the ship going around the world without hitting any sort of border or anything, much like how older Final Fantasy games and Chrono Trigger handled going around the map.

Currently what i have is this, which is the default screen wrap effect:


Thanks for the help.
 

PNelly

Member
Tricky.

I believe the behavior of the views in GM is to lock up when they contact the edge of the room, and they won't allow you to view anything that's outside of the room boundary.

I think you'll need to develop a workaround but if someone knows more than I do about the limitations of views please correct me.

I can think of two approaches

(1) Make the motion of scenery in the game relative to the player, instead of what you have now (static scenery and moving player). Similar to how a scrolling shooter works. Since your view will be (more or less) stationary around the player you'll be able to wrap the scenery smoothly and achieve the desired effect.

(2) Use multiple (probably 4) views. They'd cluster around the player to give a complete image, and when the views encounter a room boundary, some of the views would wrap and they would change width/height in order to "scroll" at the appropriate speed while maintaining the complete image. To me this sounds super hacky (not to mention difficult) to implement and will come with a performance hit, and would definitely be a no-go for mobile.

There are probably other solutions but I'd suggest making your player more or less static and applying the motion to the other elements of the game.
 
C

Chris

Guest
Tricky.

I believe the behavior of the views in GM is to lock up when they contact the edge of the room, and they won't allow you to view anything that's outside of the room boundary.

I think you'll need to develop a workaround but if someone knows more than I do about the limitations of views please correct me.

I can think of two approaches

(1) Make the motion of scenery in the game relative to the player, instead of what you have now (static scenery and moving player). Similar to how a scrolling shooter works. Since your view will be (more or less) stationary around the player you'll be able to wrap the scenery smoothly and achieve the desired effect.

(2) Use multiple (probably 4) views. They'd cluster around the player to give a complete image, and when the views encounter a room boundary, some of the views would wrap and they would change width/height in order to "scroll" at the appropriate speed while maintaining the complete image. To me this sounds super hacky (not to mention difficult) to implement and will come with a performance hit, and would definitely be a no-go for mobile.

There are probably other solutions but I'd suggest making your player more or less static and applying the motion to the other elements of the game.
My first thought was something like your second option, but use surfaces instead. I think that either way, you would have to move the environment rather than the view as you mentioned, since I believe you're correct about the behavior of views: They won't move past the border of the room. Maybe there's an advanced post-draw script you could use to get around this.
 

PNelly

Member
My first thought was something like your second option, but use surfaces instead. I think that either way, you would have to move the environment rather than the view as you mentioned, since I believe you're correct about the behavior of views: They won't move past the border of the room. Maybe there's an advanced post-draw script you could use to get around this.
That would be a lot better than manipulating multiple views. I guess you'd disable the view functionality, then define a rectangular region (your new "view"), and depending on how that rectangular region overlapped boundaries you would allocate (up to 4) surfaces different regions of the room to have drawn to them, and then you would stitch them together to give your complete image.

Not bad.
 

Blaze

Member
Would it work by drawing a new sprite at x-room_width when you are near the edge of the room and vice-versa, then when it snaps the extra sprite stops being drawn and you are exactly where it was?
 

TheouAegis

Member
There have been many ways of tackling this.

1) Don't even use views. You have all the background/tile data stored somewhere and you read which tiles should be in the "room" based on the player's "position". So the player never moves, just the world around him.

2) Manually control the view (set view_object to noone and manually change view_xview and view_yview every End Step). Duplicate half the view's width of the tiles and whatnot from the left side of the room on the right side, and vice-versa. Do the same with the top and bottom tiles. This way when the player reaches the edge of the room and wraps around, you won't see the tiles change.

3) Constantly move tiles around based on the player's position in the room. I guess this is slower than (2) but it was the first way I tackled it. :D

Now the issue with (2) and (3) which isn't an issue with (1) is handling NPCs, projectiles, and other stuff. You can either

A) "Clone" the instances with a dummy opposite of it and have collisions with the clone affect the primary NPCs.

B) Simply draw a copy of the instance on the opposite side of the room and code illusory collisions.
 
S

Sanlo

Guest
Thanks everyone for your suggestions.

Since i´m still learning about gamemaker, I don't know how to apply those suggestions.
I´m going to do some research about the level instead of the player, since it seems the best solution.

When i was looking about this issue, i did find a lot of code about mirroring the edge of the map and teleportation the player, but those codes looked really confusing.

I will try to post updates as I progress.
Thanks again!
 

Warspite2

Member
I've experimented with this stuff off and on in the past. One problem I ran into was getting all the objects and enemies on the game map to move appropriately. Another problem was getting the background to move seamlessly in any direction.

@TheouAegis the 2 method you mention above is how I thought about doing it. That will work for background. As for npc's and other stuff I thought about one parent object. Somehow having that add/subtract the x and y of the npc's to simulate proper position as the player moves.
 
Top