• 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!

Room/View/Camera created dynamically - doesn't work

Silverone

Member
Hello everyone,

I'm confused with the use of views and cameras.
I'm in the first room and I want to create another room (with view and camera) dynamically and then go to that room, so I used the code below :
GML:
myRoom = room_add(); //Creates the room
room_set_width(myRoom, myRoomWidth); //Sets the room width
room_set_height(myRoom, myRoomHeight); //Sets the room height
room_set_persistent(myRoom, false); //Sets the persistance to false
room_set_view_enabled(myRoom, true); //Enables the use of views in the new room
room_set_viewport(myRoom, 0, true, 0, 0, myViewWidth, myViewHeight); //Creates and sets the viewport 0 that will be displayed on screen
view_camera[0] = camera_create_view(0, 0, myViewWidth, myViewHeight); //Creates a camera and sets the view that will be displayed on the viewport 0
//Placing the tiles and objects in the room here...
room_goto(myRoom); //Goes to the room
Unfortunately it doesn't work : what is displayed on the newly created room seems to fit what is displayed when in the first room.
When I switch on and off the viewport 0 in the IDE of my first room, it appears the result changes in the room created dynamically
Screenshot_Issue_Viewport_01.png

Any suggestion?
Thanks for your help
 

samspade

Member
I don't think you can actually assign camera's to a room you aren't in. Have you tried putting your camera code in a room start event for the new room (e.g. in the room start event of some persistent object that will exist in the newly created room)?

Also, this is a side note, but unless you're doing something fancy, I wouldn't use custom cameras. They add a fair amount of unnecessary complexity if you're sticking with 2D. This is the basic version of the camera I use and I have found it to be very effective for everything I need (moving, zooming, rotating, etc. in 2D):


With this type of camera you would do roughly the same thing as I described in my first paragraph. Keep all the code that creates your custom room and sets the various settings, but don't do anything with the view or camera in it. Instead do those in a room start event some object has for that room.
 
Top