• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

(Solved) Deleting/destroying room duplicates?

H

HanNic3197

Guest
Hello! I am using DND, but understand a bit a coding/gamemaker language.

I am making a game similar to Doodle jump. As the player sprite leaves the top of any room it moves to the next room and if it hits the bottom of any room it goes to the previous room - simulating an endless sky.

I originally tried doing this by just making a really large room and for now obvious reasons, that doesn't work. Next idea was to just make multiple rooms of the same size, but doing this by hand creates a limited number of rooms/levels the player can go into the sky.

It was suggested to me to use the room_duplicate(ind) function, which seems to work fine when increasing the rooms. However, I do not want it to actually spawn infinite rooms due to memory leak. Rather, I want it to do something like the following (I don't really know how to code as I use DND but the commands are similar I believe)

if object_player collides with obj_room_roof;
global.room_number = room_duplicate(room1)
go to room (global.room_number)

if object_player collides with obj_room_floor;
go to room (global.room_number -1)
destroy room_duplicate(global.room_number)

So when the player collides with the roof it duplicates the room and goes to the duplicate room index number. When the player collides with the floor, it goes back to the original room and destroys the duplicated room. Additionally I have added a global variable that is rooms_switched and it changes by 1 everytime the player leaves through the top of the room and -1 when the player goes back a room. This way when colliding with the floor it will only go back room until it's reached the original room.

I have a feeling that this way would still have potential for infinite rooms & memory leak. I'd like to delete the duplicate everytime is changes a new room and goes back a room. So there is always only the base room with a floor (room0) the middle room with roof and floor collision objects (room1) and the current duplicated room the player is in (room1.x). If the player has switched rooms 5 times, when the player leaves the current room it goes backwards to a new duplicate and deletes the current duplicate 3 times. When leaving the 3rd duplicate it goes back to room1, then room2 with an end rooms_switched of 0.

I have not been able to find a destroy room duplicate function anywhere, so I'm not even sure if this is possible with GMS2. If you have any other suggestions, it would be greatly appreciated!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It is impossible to delete a room that has been created dynamically in GameMaker. Rooms are such an integrated part of the engine, that if you create one in code it has to remain in the game until it is closed... there are just too many potential issues with being able to delete rooms.
 
In GMS, you are not limited by the room size. With a few exceptions ( for example, you wouldn't use the Outside Room event), you are free to move to any x and y position you want.

So you could just use one room, and place the new platforms into the game above the player as you scroll the camera up, or as the camera follows the player.
 
H

HanNic3197

Guest
In GMS, you are not limited by the room size. With a few exceptions ( for example, you wouldn't use the Outside Room event), you are free to move to any x and y position you want.

So you could just use one room, and place the new platforms into the game above the player as you scroll the camera up, or as the camera follows the player.
I thought this would work too, but if I were to make a room size with 20,000+ pixels in height it plummets the fps and crashes the game before it launches.
 
What I mean is ignore the room size. Just make it the same as your game window size for example, and just move the camera to follow your player. As long as you don't use the built in follow object setting in the room editor, you can move the player and camera anywhere you want.
 

NightFrost

Member
Another way how people build infinite-looking rooms is have the player position remain static and move everything around them. Or combine that with giving the player some modicum of movement. Scrolling shooters for example let player move around the screen and move the background downward to give the appearance of movement. The example you give has a little more considerations but you should be able to figure what it is doing when you keep in mind the platforms are just moved down whenever the world appears to scroll up.
 
H

HanNic3197

Guest
What I mean is ignore the room size. Just make it the same as your game window size for example, and just move the camera to follow your player. As long as you don't use the built in follow object setting in the room editor, you can move the player and camera anywhere you want.
I've been trying to get this to work for a while now, but I dont seem to get it correct.

Code:
if (camera_get_view_x(0) != obj_ball.x || camera_get_view_y(0) != obj_ball.y)
{
    show_debug_message("newX " + string(obj_ball.x) + ", newY " + string(obj_ball.y));
    camera_set_view_pos(0,obj_ball.x,obj_ball.y)
    show_debug_message("camX " + string(camera_get_view_x(0)) + ", camY " + string(camera_get_view_y(0)));
}
As you can see im trying to make sure my code is actually reached, and if so wether the camera position is being changed. It is, this gives a correct response in the console log. However, nothing is happening in my game. I've made sure there's no other view port active in the scene, so I have no idea whats going wrong here. Any suggestions?


Another way how people build infinite-looking rooms is have the player position remain static and move everything around them. Or combine that with giving the player some modicum of movement. Scrolling shooters for example let player move around the screen and move the background downward to give the appearance of movement. The example you give has a little more considerations but you should be able to figure what it is doing when you keep in mind the platforms are just moved down whenever the world appears to scroll up.
You're right, I learned about this after I had finished my " physics" part of the game though. I really dont want to redo all of that work, so I'm hoping I can get it to work this way.
 
I've been trying to get this to work for a while now, but I dont seem to get it correct.

Code:
if (camera_get_view_x(0) != obj_ball.x || camera_get_view_y(0) != obj_ball.y)
{
    show_debug_message("newX " + string(obj_ball.x) + ", newY " + string(obj_ball.y));
    camera_set_view_pos(0,obj_ball.x,obj_ball.y)
    show_debug_message("camX " + string(camera_get_view_x(0)) + ", camY " + string(camera_get_view_y(0)));
}
As you can see im trying to make sure my code is actually reached, and if so wether the camera position is being changed. It is, this gives a correct response in the console log. However, nothing is happening in my game. I've made sure there's no other view port active in the scene, so I have no idea whats going wrong here. Any suggestions?
Camera x and y is actually the top left corner of the screen. So you'll also want to get the view width and height, then divide those values by 2 in order to get the center of the screen.

And you want to be using a camera id rather than just 0 as the camera variable.

End Step Event
Code:
var vw = camera_get_view_width(view_camera[0]);
var vh = camera_get_view_height(view_camera[0]);

var cam_x = obj_ball.x - (vw * 0.5);
var cam_y = obj_ball.y - (vh * 0.5);

camera_set_view_pos(view_camera[0], cam_x, cam_y);
 

TheouAegis

Member
Doodle Jump makes you fall to a blank page (on all the videos I saw). It doesn't keep track of old platforms. That's kinda the point - he doesn't have infinite amounts of paper. When you hit the bottom of the room, set a timer and start scrolling everything up.
 
H

HanNic3197

Guest
Camera x and y is actually the top left corner of the screen. So you'll also want to get the view width and height, then divide those values by 2 in order to get the center of the screen.

And you want to be using a camera id rather than just 0 as the camera variable.

End Step Event
Code:
var vw = camera_get_view_width(view_camera[0]);
var vh = camera_get_view_height(view_camera[0]);

var cam_x = obj_ball.x - (vw * 0.5);
var cam_y = obj_ball.y - (vh * 0.5);

camera_set_view_pos(view_camera[0], cam_x, cam_y);
ah! Finally it works! Now there is the issue that when the ball leaves the room horizontally, I had it set to wrap around the room but now it moves out of the room and basically moves the room to match the position of the ball. This is great, except I need it to that vertically and not horizontally. I'm looking into how to do that now, but if you know what I can change to make that possible let me know! Thank you so much for all your help!
 
H

HanNic3197

Guest
Doodle Jump makes you fall to a blank page (on all the videos I saw). It doesn't keep track of old platforms. That's kinda the point - he doesn't have infinite amounts of paper. When you hit the bottom of the room, set a timer and start scrolling everything up.
Okay, good idea! I'll try this when I do another similar project without physics. Thanks.
 
H

HanNic3197

Guest
Nvm.. I figured out I just needed to change the wrap room to vertical and not horizontal. It works perfect now. Thanks so much!
 
Top