Does anyone know how i draw points only that are within the area displayed by viewport[0] ?

Hello everyone ! I'm studying game maker studio 2.3+ and I would like to draw a starry sky to make a simple spaceship game, but I would like to randomly generate them in random X and Y positions, as the map is 3000x3000 in size, so why not despite the game, I would like you to draw points only the stars that are inside the area displayed by the ViewPort[0] . if you can draw on a layer directly, that's even better.
Can someone help me ?
 
Last edited:

rIKmAN

Member
Some things like Width of the view in the room and Height of the view in the room may be a good place to start.

If you want to draw to a specific layer, just create the layer in the "Layers" portion of your "Room Editor" tab and add an object to that layer that handles the drawing of your starry sky.
Sorry to be that guy, but you've linked to the GMS 1.4 manual when OP is using GMS 2.3.

The Camera and Viewports section of the GMS2.3 manual will be what they want, all the function are listed at the bottom.
Likely camera_get_view_width() / camera_get_view_height() if using a camera, or view_wport[] / view_hport[] for the equivalents of the v1.4 functions you linked to.
 
Some things like Width of the view in the room and Height of the view in the room may be a good place to start.

If you want to draw to a specific layer, just create the layer in the "Layers" portion of your "Room Editor" tab and add an object to that layer that handles the drawing of your starry sky.
my fear is that I can't create layers that move independently of each other, with layers of type instances is it possible to move them in the same way as a layer of type background?
 
Sorry to be that guy, but you've linked to the GMS 1.4 manual when OP is using GMS 2.3.

The Camera and Viewports section of the GMS2.3 manual will be what they want, all the function are listed at the bottom.
Likely camera_get_view_width() / camera_get_view_height() if using a camera, or view_wport[] / view_hport[] for the equivalents of the v1.4 functions you linked to.
The commands are not working,
I created an object called :> oCamera and inside that object I created 2 functions : Create and Step Events

Create Event Code :
GML:
camera = camera_create();

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

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


view_camera[0] = camera;

follow = oPlayer;

global.xTo = x;
global.yTo = y;
Step Event Code :
GML:
x += (global.xTo - x)/20;
y += (global.yTo - y)/20;


if (follow != noone){

    global.xTo = follow.x;
    global.yTo = follow.y;
    
}   

var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
camera_set_view_mat(camera,vm);
camera follows oPlayer with smooth movement .
as much as I use camera and viewport commands to get their X and Y position, all the commands in question return 0. the only commands I'm trying to get the "position" of the camera are through global variables > global.xTo and
global.yTo , but I'm just getting the "center" of the camera position...

I'm too new to know what to do in this situation xD . can anyone help me ?
 

curato

Member
Some things like Width of the view in the room and Height of the view in the room may be a good place to start.

If you want to draw to a specific layer, just create the layer in the "Layers" portion of your "Room Editor" tab and add an object to that layer that handles the drawing of your starry sky.
I was actually going to say this as well. Not that you can't do what you are suggesting, but this would be much simpler to create objects that move across the screen and destroy them when they are done. You could add a lot of details not just stars that way. Basically anything you want to drop the art in for could move across the screen.
 
well, I redid the camera by setting its position by the commands ( now working ) :
GML:
 x = lerp(x,target_.x,0.1);
y = lerp(y,target_.y,0.1);
camera_set_view_pos(view_camera[0],x-width_/2,y-height_/2);
previously I was setting the camera position using the commands:
GML:
var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
camera_set_view_mat(camera,vm);
I don't know if this was influencing getting the camera's x and y...

thank you all so much for the support and help!! I'm very grateful to you šŸ˜
 
I believe this game maker studio tutorial covers what you are trying to achieve.
Space Mods: Continue Your Space Rocks Game (yoyogames.com)

"The "Space Mods" series covers Cameras for expanding the playing field and following the action. Parallax Backgrounds for adding movement and depth to the look of space"

You could create a boundary check to say only create a sprite within the camera using the built in "point_in_rectangle"

Screenshot 2022-01-19 154058.png
 
Last edited:
Top