GameMaker [SOLVED] custom camera

Z

zendraw

Guest
im not sure if im doing somthing wrong, but camera/view functions dont seem to work. i have this code that runs in the first room, then we go to 2nd room in the project with 0 effect.

GML:
/// @desc scrstart();

camera_destroy(view_camera[0]);

show_debug_message(111111111111111111);
if (view_camera[0]==-1) {show_debug_message("camera deleted!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")};

var nc=camera_create();
show_debug_message(nc);
view_camera[0]=nc;
show_debug_message(view_get_camera(view_camera[0]));
var vm = matrix_build_lookat(0, 0, -10, 0, 0, 0, 0, 1, 0);
var pm = matrix_build_projection_ortho(480, 270, 1.0, 32000.0);
camera_set_view_mat(view_camera[0], vm);
camera_set_proj_mat(view_camera[0], pm);

camera_set_view_size(view_camera[0], 480, 270);

var i=0;
repeat (room_last+1)
{
    if (room_exists(i))
    {
        room_set_viewport(i, view_camera[0], true, 0, 0, 480, 270);
        room_set_view_enabled(i, true);
    } else {break;};
    i++;
}

with (ocamera) {instance_destroy()};
instance_create_depth(0, 0, 0, ocamera);

room_goto_next();
-camera shuld be destroyed, it is not
-matrices nor camera resizing works
-setting viewport and enabling view in rooms does nothing and i also set them in room start event

GML:
view_enabled=true;
view_set_visible(view_camera[0], true);
how is it so hard to:
1-create a custom camera and set it to a view
2-set that view`s size
3-enable views

i mean nothing really works atall. in the room settings i havent touched anything, its all default.
 
Z

zendraw

Guest
i will read it, but does it answer why is nothing working in my code? i even put view enable stuff in step event without any effect.
 

Tyg

Member
Try

camera_destroy view_camera[0] ;
view_camera[0] = camera_create() ;
nc = view_camera[0];

you have to create the camera before assigning it to a variable then use nc
camera_set_view_mat(nc, vm);

but there is no need to create and destoy camera[0]

nc = view_Camera[0];

Hope that helps :)
 
Z

zendraw

Guest
i see now what the whole deal is, you have to set the camera for every room when your are IN the room, otherwise it doesnt work. i basically run this code in room start event and now things work as intended.


GML:
/// @desc scrsetcamera();

//vars
var dw=display_get_width();
var dh=display_get_height();
var ve=0;
var w=480;
var h=270;
var m=floor(display_get_width()/(w+10));
var ww=w*m;
var hh=h*m;

view_enabled=true;
view_set_visible(view_current, true);

view_set_wport(ve, w);
view_set_hport(ve, h);

window_set_rectangle(floor((dw-ww)*.5), floor((dh-hh)*.5), ww, hh);
surface_resize(application_surface, view_wport[ve], view_hport[ve]);

camera_set_view_size(view_camera[ve], view_wport[ve], view_hport[ve]);
nothing is global or carries over to new rooms, i dont know why the manual is so misleading. all it shuld say that you have to set the camera in every room and that will clear so much confusion and make working with views understandable... THIS is why people dont read the manual.

@Klardonics that works becouse you dont change rooms and set camera size in setep event. if you dont run code in step event and change rooms, that code wont work, it will keep window size but the application surface will be stretched. becouse it takes the room editor values.

just set view[0] in room start event and that is pretty much it for setting the camera. having global settings that you set once and forget about it just doesnt work.

really i cant stretch enough how USELES the manual is explaining essential things that makes working with game maker obvious and CLEAR. Nowhere did i read you have to set views for every room when you are in them, and this causes so much garbage tutorials and headaches. @FrostyCat and other manual fanatics, think twice next time you write, read the manual to anyone.
 
O

OwainHorton

Guest
So im having an issue like this one too. I use Game Maker since 2010, and was SO EASY to do this back then. Now i don't know why it doesnt work.

I got 2 rooms. First is 512x256 and second is the size you wanna (You write it). I don't know whats going wrong but when it goes to the second room, size of the window and the view is the same of the first room. So you only see like the 10% of the actual room.

I've been googling for days and reading manuals and i haven't found anything that makes sense...
 
Z

zendraw

Guest
So im having an issue like this one too. I use Game Maker since 2010, and was SO EASY to do this back then. Now i don't know why it doesnt work.

I got 2 rooms. First is 512x256 and second is the size you wanna (You write it). I don't know whats going wrong but when it goes to the second room, size of the window and the view is the same of the first room. So you only see like the 10% of the actual room.

I've been googling for days and reading manuals and i haven't found anything that makes sense...
read my last comment
 
O

OwainHorton

Guest
read my last comment
Doing that literally broke all my game. Its a 3D one. My original post is this one... Its silly. In GMS1 this would be done in 2 minutes at max.

 
Z

zendraw

Guest
Doing that literally broke all my game. Its a 3D one. My original post is this one... Its silly. In GMS1 this would be done in 2 minutes at max.

well my issue is with 2D, for 3d its diffrent and you have to setup a camera with matrices. i havent dealt with that so cant help you much.
 
O

OwainHorton

Guest
well my issue is with 2D, for 3d its diffrent and you have to setup a camera with matrices. i havent dealt with that so cant help you much.
The 3D Camera works fine. The issue isn't coming from there. The issue is the window size doesn't changes at all and you only see the 10% of the screen.
 
Top