GameMaker Camera get view x get view height dont work...

E

Eliran Vegh

Guest
Hi, I am using the camera system in GM2, and I am trying to get the view proprieties however they all return 0...



Code:
ch = camera_get_view_height(camera)
cw = camera_get_view_width(camera)
xc = camera_get_view_x(camera);
yc =  camera_get_view_y(camera)
show_debug_message(string(cw) + " " + string(ch));
x = xTo ;
y = yTo ;
actualOffSet = smooth_approach(actualOffSet,offSetTo,0.05);
if(shake){
    shakeDur --;
    x += choose(-shakeForce,shakeForce);
    y += choose(-shakeForce,shakeForce);
    if(shakeDur <= 0){
        shake = false;
        shakeDur = 5;
    }
}
if o_Player.dir == 0
{
    offSetTo = offSet * -1;
}else
{
    offSetTo = offSet;
}

if (follow != noone)
{
    xTo = follow.x+(actualOffSet);
    if(follow.y  <= 230 && follow.y >= 90)
    {
        yTo = follow.y;
    }
    
}

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

Code:
camera = camera_create();
var viewmat = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var projmat = matrix_build_projection_ortho(640,360,1,3200);

camera_set_view_mat(camera,viewmat);
camera_set_proj_mat(camera,projmat);

view_camera[0] = camera;

offSet = -150;
actualOffSet = offSet;

offSetTo = offSet;

follow = o_Player;
xTo = x;
yTo = y;

shake = false;
shakeDur = 20;
shakeForce = 1;
The camera works find and dany like it should, however I want to be able to get these numbers as well so i can figure out if an enemy is on screen or out of screen....

am I doing something wrong?

Thanks Eliran.

This is how the game works right now
 
E

Eliran Vegh

Guest
Yeah I tried them all! :( camera_get_active() also for some reason only get the width and height but not the x,y -_-
 
x and y will be 0 of course at the start of the game if you haven't moved the view.

Have you tried moving the camera and check the x and y values.

Have you set view_enabled = true (if you didn't already check the box in the room editor) and view_visible [0] = true.
 
E

Eliran Vegh

Guest
The camera is definitely moving check out the vid and you can see it set to follow the player
 
Ah, I can't view videos by default, need to use VPN.

Alright, well I can't see anything else wrong with your code. I use those functions a lot and they seem to work fine for me.

The only difference is that I setup my camera for View 0 in the Room Editor itself, not in code. Then in GML I just refer to it as view_camera[0] whenever I need to use those functions.
 
Top