Hi All
Im very new to this forum and im writing, because i couldnd figure out how to do this, and the google search didnt help.
I d'like to make the camera following multiple players with moving and zooming (no splitscreen). The aspect ratio should always be 16:9. Look at the sketch:
In my code I calculate the min and max coordinates of all players and then i slowly change the view width until it fits in the desired boarders.
create event:
-----------------------------
draw event:
---------------------
this code almost work, but the camera is always shaking (4 pixels like the step-variable), when the view reaches the final view size.
can you help me?
thanks a lot!
Im very new to this forum and im writing, because i couldnd figure out how to do this, and the google search didnt help.
I d'like to make the camera following multiple players with moving and zooming (no splitscreen). The aspect ratio should always be 16:9. Look at the sketch:
In my code I calculate the min and max coordinates of all players and then i slowly change the view width until it fits in the desired boarders.
create event:
-----------------------------
Code:
viewX = 0
viewY = 0
width = 640
height = 360
draw event:
---------------------
Code:
var minX = room_width // to find the minimum, set to maximum first
var maxX = 0
var minY = room_height // to find the minimum, set to maximum first
var maxY = 0
with(obj_player) // find min und max coordinates of all players
{
if (x > maxX) maxX = x
if (x < minX) minX = x
if (y > maxY) maxY = y
if (y < minY) minY = y
}
var viewBorderX = 96
var viewBorderY = 32
viewX = minX-viewBorderX
viewY = minY-viewBorderY
var step = 4
if ( maxX + viewBorderX > viewX + width ) // the right most player leaves the right boarder --> extend the camera view size slowly
{
width += step // increase camera_view_width
}
else if ( maxX + viewBorderX < viewX + width) // the right most player is within the right boarder --> make the camera view size slowly smaller until it exactliy matches the boarder
{
width -= step // decrease camera_view_width
}
else if ( maxY + viewBorderY > viewY + height)
{
width += step // increase camera_view_width
}
else if ( maxY + viewBorderY < viewY + height)
{
width -= step // decrease camera_view_width
}
height = width/16*9 // calculate the height and keep aspect ratio 16:9
camera_set_view_pos(view_camera[0], viewX, viewY)
camera_set_view_size(view_camera[0],width, height)
can you help me?
thanks a lot!