GameMaker How do I change the camera start position in a different room with scripting?

Hi, I'm trying to figure out how to make a camera change from its default position when warping to another room, in the destination room, but after a glance at the documentation, I must be misunderstanding something, because my code isn't working as I intend. Here is my code:

Code:
var vals = room_get_viewport(warpTo, 0);
room_set_camera(warpTo, 0, 0);
room_set_viewport(warpTo, 0, vals[0], (warpX div 304) * 304, (warpY div 304) * 304, vals[3], vals[4]);
var pl = room_instance_add(warpTo, warpX, warpY, obj_player);
room_goto(warpTo);
It's a Zelda-style game with 'screens' that are all on a single room, 304x304 in size, so I lock it to those dimensions and positions. Yet for some reason, when those code runs... Nothing is changed. The player starts again at the destination's default camera location, every single time. I don't understand what I am doing wrong; the only thing I've learned is that viewport 0 in this code......does not appear to be THE viewport 0 for the room, which baffles me. If I check the value of the view's X and Y after setting it in that code....it's still 0, 0 instead of the intended 0, 304 (I have the test warp warp me to the next "room" to the south, which will put the camera at 304y). What am I doing wrong? Am I completely misunderstanding how these functions work? Do these not work with the default cameras? Are these solely for creating cameras and viewports from scratch, not meant to be used in conjunction with editor-made viewports and cameras? Please, I'd like some help understanding this!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
The usual solution would be not to modify the target room's viewport, but instead have a persistent object that would have target coordinates written into it's variables (or global variables - your choice) and then apply them on Room Start upon transition.
 
The usual solution would be not to modify the target room's viewport, but instead have a persistent object that would have target coordinates written into it's variables (or global variables - your choice) and then apply them on Room Start upon transition.
Ahhhhhhhhhhh, good idea! The object that's modifying these on a new room is ALREADY persistent, so that's a good idea there. I'll give that a try, thank you! (I have no idea how I never thought to use the "Room Start" event... I feel silly now!)

EDIT: So after doing that, it APPEARS to work, but...................something has made the camera always want to lock to 0,0 and be 360 pixels tall, despite being set at 304, thus making the view squished. When I walk through it step by step, it looks correct for all of one frame- then suddenly shoots to 0,0 and becomes 360 pixels tall, squished into 304. I did no changes except for adding in the Room Start event- disabling that or the Step event does nothing. I do not understand what is going on with my game now. What's even odder is that when I check the size of the camera and view, they both say a height of 304, even though the camera is clearly 360...

What would be more helpful in this situation for you to check into, the code for each part of the camera object, or the whole game file? :/
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
the code for each part of the camera object
That would certainly be a start. You can also try copying your camera object to a blank project (with a couple of rooms and a keyboard event to move between them) to see if the issue is in it's code or somewhere else.
 
Top