• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Finding an x position in relation to the view

D

DjchunKfunK

Guest
So in GM1 in order to draw something in relation to the view, so in this case a dialogue box at the bottom of the screen, I would just use view_xview and view_yview. These are obviously gone now and I can't work out what the equivalent is in GM2.

I've tried setting a variable with camera_get_view_x, but that draws the box off screen to the left where the view is originally drawn in the game before it moves to where the player is.I've also tried view_xport and that doesn't work either.

Can anyone help?
 
A

Aura

Guest
Won't it be easier to simply use the Draw GUI event?

Anyways, the camera_get_view_*() functions should return the current view position, that's what the Manual suggests. There's an example in the Manual entries of both of these functions that show how you can draw the score relative to the view. Perhaps give it a read?
 
D

DjchunKfunK

Guest
Yeah that's what the manual suggests but when I do that I get the following.

 

mMcFab

Member
Here's a couple of questions to try and pinpoint the issue:
-Have you actually created a camera?
-Have you bound the camera to the desired view?
-Do you have an example of the code you are using that you can share with us?

I am working on getting a guide out for using the cameras within the next couple of hours, it may help you as well as others that are having issues
 
D

DjchunKfunK

Guest
Ah so you have to bind the camera to a view? I didn't know that. I see that you can create a camera in code, but then it appears you have to input all the variables to match the view you want. Is there no way to just easily bind it to a view you set in the room settings?

EDIT: OK I think I've set the camera correctly now, but the box is still drawn to the left.

Here is the camera creation code and then the draw code.

view_camera[0] = camera_create_view(0,0,300,250,0,oPlayer,-1,-1,100,100)


Draw Event

var xx = camera_get_view_x(view_camera[0])
var yy = camera_get_view_y(view_camera[0])
draw_sprite(sDialogueBox,0,xx,yy+175);
draw_text(xx+16,yy+190,out);
 
Last edited by a moderator:

mMcFab

Member
These cameras seem to have made what was once a very simple system into a cumbersome mess.
They certainly seem cumbersome now, but with the messing about I've done with them already, I already feel that they are much better than they used to be - maybe that's just the camera scripts speaking though

Ah so you have to bind the camera to a view? I didn't know that. I see that you can create a camera in code, but then it appears you have to input all the variables to match the view you want. Is there no way to just easily bind it to a view you set in the room settings?

EDIT: OK I think I've set the camera correctly now, but the box is still drawn to the left.

Here is the camera creation code and then the draw code.

view_camera[0] = camera_create_view(0,0,300,250,0,oPlayer,-1,-1,100,100)


Draw Event

var xx = camera_get_view_x(view_camera[0])
var yy = camera_get_view_y(view_camera[0])
draw_sprite(sDialogueBox,0,xx,yy+175);
draw_text(xx+16,yy+190,out);
Okay, your draw code seems absolutely fine. camera_create_view is fine too.
However, the way the manual suggests to create+bind a camera (and the way I have tested) is to use "view_set_camera(view_id, camera)" to bind the view - it's possible that using "view_camera[X} = camera" doesn't perform the bind properly - I'd need to test that out, otherwise, your code seems fine

EDIT: Nope, view_camera[X] = camera works fine for me too. I'll try a fresh project and mimic the exact code you've given to see if I can replicate it

(MORE EDIT): I don't suppose the origin on the text box sprite is in the center instead of the top-left? Just working through possibilities here - and this seems plausible as it looks like if the textbox moved down by half its height it would be correct, and only half to box is showing horizontally (though I edited the image manually, and it doesn't quite fill the space, so I'm not super sure this is the problem.

Another question - does the box at least follow your view?
 
Last edited:
D

DjchunKfunK

Guest
(MORE EDIT): I don't suppose the origin on the text box sprite is in the center instead of the top-left? Just working through possibilities here - and this seems plausible as it looks like if the textbox moved down by half its height it would be correct, and only half to box is showing horizontally (though I edited the image manually, and it doesn't quite fill the space, so I'm not super sure this is the problem.
I can't believe I missed that, yes it does. Works now thanks for your help. :)
 
Top