• 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 Camera_get_view_x / y only returning 0

L

LanderMiskolczi

Guest
So i've been trying to get my buttons to follow the camera, and to do this, I need to get the camera x and y, but using the object it makes it lag behind. But when I use this function it only ever returns me a 0. Here's a gif to show you what I mean.
If you look to the left, that is printing out what the function is getting for the camera x and y. and I don't think it should be (0, 0) heres my camera code:
CREATE:
GML:
view_visible[0] = true;
view_enabled = true;

camera = camera_create();

var vm = matrix_build_lookat(x, y, -10, x, y, 0, 0, 1, 0);
var pm = matrix_build_projection_ortho(1024, 768, -1, 10000);

camera_set_view_mat(camera, vm);
camera_set_proj_mat(camera, pm);

view_camera[0] = camera;

follow = noone;
xTo = x;
yTo = y;

show_debug_message("(" + string(x) + " , " + string(y) + ")");
show_debug_message("(" + string(view_wport[0]) + " , " + string(view_hport[0]) + ")");
STEP:
GML:
x += (xTo - x) / 25;
y += (yTo - y) / 25;

if follow != noone
{
    xTo = follow.x;
    yTo = follow.y;
}


x = clamp(x, 512, room_width-512);
y = clamp(y, 384, room_height-384);

var vm = matrix_build_lookat(x, y, -10, x, y, 0, 0, 1, 0);
camera_set_view_mat(camera, vm);

show_debug_message("(" + string(camera_get_view_x(view_camera[0])) + " , " + string(camera_get_view_y(view_camera[0])) + ")");
The only reason the buttons are slightly following the camera, is because im having them follow the x and y of the object, but I know thats not optimal. Here is the button code:
CREATE:

GML:
title = "ERROR";
text = "Button has received no information";
hotkey = "ERROR";
spell = false
spellSlot = "0";

xDiff = x - oGameController.cam.x;
yDiff = y - oGameController.cam.y;


show_debug_message("(" + string(x) + " , " + string(y) + ")");
show_debug_message("(" + string(camera_get_view_x(view_camera[0])) + " , " + string(camera_get_view_y(view_camera[0])) + ")");
show_debug_message("(" + string(xDiff) + " , " + string(yDiff) + ")");
STEP:
GML:
cx = oGameController.cam.x;
cy = oGameController.cam.y;

x = cx + xDiff;
y = cy + yDiff;
This is all I got. If you see anything wrong, please tell me, and if anyone knows whats going on with the function I would love to know. Thank you for reading this!
 

samspade

Member
I don't think that view_camera works with the matrix camera or maybe it is with a camera you create, I can't remember. You shouldn't need it though as you are presumably saving the x and y you want as is.
 
L

LanderMiskolczi

Guest
I don't think that view_camera works with the matrix camera or maybe it is with a camera you create, I can't remember. You shouldn't need it though as you are presumably saving the x and y you want as is.
I don't think I am? I have it setup to follow the camera, but it's always in a weird position.....

which I just thought of an idea that could work! but thank you, good to know that it doesn't work with the kind of camera I set up
 
Top