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

GameMaker Move Camera Over Time

G

Gregory Tapper

Guest
Still getting used to the new (awesome) camera system in GameMaker 2!

In a step event, I have my camera moving to camtarget_x and camtarget_y.
Code:
camera = camera_create_view(0, 0, 256, 176, 0, -1, -1, -1, 32, 32);
view_set_camera(0, camera);
camera_set_view_pos(camera,camtarget_x,camtarget_y);
Is there a new function I'm missing that will let me input a transition time to pan the camera? I know I can create a script that takes in the new position, then calculates the new position per frame, but it seems like something Yoyo would've included in a camera function :)

Thanks!
 

TheouAegis

Member
You can use camera_set_view_speed and set an alarm to stop the camera after it has moved far enough or recalculate when it has moved far enough. But this only works if the camera has a target to follow.
 
G

Gregory Tapper

Guest
You can use camera_set_view_speed and set an alarm to stop the camera after it has moved far enough or recalculate when it has moved far enough. But this only works if the camera has a target to follow.
Not a bad start :D I'm doing an NES Zelda screen transition, but this isn't working. And seems super overkill. Doing the X for now.

Code:
//Create Event
camera = camera_create_view(0, 0, 256, 176, 0, -1, -1, -1, 32, 32);
view_set_camera(0, camera);

target_xview = (obj_player.x div 256) * 256;
target_yview = (obj_player.y div 176) * 176;

camera_set_view_pos(camera,target_xview,target_yview);

last_xview = target_xview;
last_yview = target_yview;

//Alarm 0

//Step Event
current_xview = (obj_player.x div 256) * 256;
current_yview = (obj_player.y div 176) * 176;

if (current_xview != last_xview) {
    alarm[0] = 60;
    while (alarm[0] > 0) {
        if(current_xview > last_xview) {
            camera_set_view_speed(camera, 4, 0);
        } else {
            camera_set_view_speed(camera, -4, 0);
        }
    }
    camera_set_view_speed(camera,0,0);
    //setting the pos after because 4 per frame will be just short of where the camera needs to be
    camera_set_view_pos(camera,current_xview,current_yview);
}

last_xview = current_xview;
last_yview = current_yview;
See anything fundamentally wrong with this?
 
G

Gregory Tapper

Guest
OHHH IT NEEDS A TARGET.

reading, english, not so good. attempt #2
 
G

Gregory Tapper

Guest
Alright, nevermind the target. Some really weird things happen. Here was my work around without set_speed. Still freezes my character when trying to change screens in room... :(
I'm setting a new var, newx per frame, then setting the camera pos to this new value.

Code:
//Create Event
camera = camera_create_view(0, 0, 256, 176, 0, -1, -1, -1, 32, 32);
view_set_camera(0, camera);

target_xview = (obj_player.x div 256) * 256;
target_yview = (obj_player.y div 176) * 176;

camera_set_view_pos(camera,target_xview,target_yview);

last_xview = target_xview;
last_yview = target_yview;

//Alarm 0

//Step Event
current_xview = (obj_player.x div 256) * 256;
current_yview = (obj_player.y div 176) * 176;

var newx = 0;
var newy = 0;

if (current_xview != last_xview) {
    alarm[0] = room_speed;
    while (alarm[0] > 0) {
        if(current_xview > last_xview) {
            newx += 4;
        } else {
            newx -= 4;
        }
        camera_set_view_pos(camera,newx,current_yview);
    }
    //camera_set_view_speed(camera,0,0);
    camera_set_view_pos(camera,current_xview,current_yview);
}

last_xview = current_xview;
last_yview = current_yview;
Any idea? :eek:
 
Last edited by a moderator:
Top