Jump to content


Photo
- - - - -

Two Objects In One View Example


  • Please log in to reply
27 replies to this topic

#21 Rudey

Rudey

    GMC Member

  • New Member
  • 1 posts

Posted 01 September 2010 - 07:23 PM

This might be an old topic, but it's the only one about 'two object views'.

I didn't like the current one so I editted it a lot.
And now I cannot help myself posting my version up here...

I made my script compatible with every kind of aspect ratio.
It doesn't matter what the room width and height are, this will work.

I've also declared a couple of new variables so the script doesn't look difficult.
Don't pay attention to them. And don't pay attention to anything beneath it.
Just pay attention to the variables minzoom and maxzoom.
Oh, and change objects player1 and player2 to what you like.

minzoom=1                           // sets the minimal zoom
maxzoom=2.5                         // sets the maximal zoom

min_wview=room_width/maxzoom        // sets the minimal width of the view
min_hview=room_height/maxzoom       // sets the minimal height of the view
max_wview=room_width/minzoom        // sets the maximal width of the view
max_hview=room_height/minzoom       // sets the maximal height of the view

// calculates the size and position of the view

xdistance=point_distance(player1.x,0,player2.x,0)
ydistance=point_distance(0,player1.y,0,player2.y)

if xdistance/room_width>ydistance/room_height {
    view_wview[0]=xdistance+room_width/4
    if view_wview[0]<min_wview {view_wview[0]=min_wview}
    if view_wview[0]>max_wview {view_wview[0]=max_wview}
    view_hview[0]=view_wview[0]/room_width*room_height
}
else {
    view_hview[0]=ydistance+room_height/4
    if view_hview[0]<min_hview {view_hview[0]=min_hview}
    if view_hview[0]>max_hview {view_hview[0]=max_hview}
    view_wview[0]=view_hview[0]/room_height*room_width
}

view_xview[0]=(player1.x+player2.x)/2-view_wview[0]/2
view_yview[0]=(player1.y+player2.y)/2-view_hview[0]/2

// keeps the view inside the room

if view_xview[0]+view_wview[0]>room_width {
    view_xview[0]=room_width-view_wview[0]
}

if view_yview[0]+view_hview[0]>room_height {
    view_yview[0]=room_height-view_hview[0]
}

if view_xview[0]<0 {
    view_xview[0]=0
}

if view_yview[0]<0 {
    view_yview[0]=0
}

  • 0

#22 _191723

_191723

    GMC Member

  • New Member
  • 16 posts

Posted 20 March 2011 - 04:22 PM

You are a genius, thank you!
  • 0

#23 Tobias(NL)

Tobias(NL)

    GMC Member

  • GMC Member
  • 851 posts
  • Version:Unknown

Posted 14 February 2012 - 06:21 PM

Pretty flashy, but it zooms in way too much. It needs a limiter or something of the kind.
Overall the example was smooth and worked well!
TobiasNL
  • 0

#24 _206203

_206203

    GMC Member

  • New Member
  • 4 posts

Posted 20 April 2012 - 04:20 AM

why like this?

Posted Image
  • 0

#25 ironmaneleven

ironmaneleven

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 09 December 2012 - 06:56 AM

I am making a 2D multiplayer game with 2 players and I want it to zoom out when they get further away from each other, but I also don't
want it to zoom in too far when they are close to each other. How should I alter this script to function this way? Please help
  • 0

#26 ironmaneleven

ironmaneleven

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 09 December 2012 - 07:17 AM

[quote name='Rudey' date='02 September 2010 - 05:23 AM' timestamp='1283368984' post='3595109']
This might be an old topic, but it's the only one about 'two object views'.

I didn't like the current one so I editted it a lot.
And now I cannot help myself posting my version up here...

I made my script compatible with every kind of aspect ratio.
It doesn't matter what the room width and height are, this will work.

I've also declared a couple of new variables so the script doesn't look difficult.
Don't pay attention to them. And don't pay attention to anything beneath it.
Just pay attention to the variables minzoom and maxzoom.
Oh, and change objects player1 and player2 to what you like.

minzoom=1                           // sets the minimal zoom
maxzoom=2.5                         // sets the maximal zoom

min_wview=room_width/maxzoom        // sets the minimal width of the view
min_hview=room_height/maxzoom       // sets the minimal height of the view
max_wview=room_width/minzoom        // sets the maximal width of the view
max_hview=room_height/minzoom       // sets the maximal height of the view

// calculates the size and position of the view

xdistance=point_distance(player1.x,0,player2.x,0)
ydistance=point_distance(0,player1.y,0,player2.y)

if xdistance/room_width>ydistance/room_height {
    view_wview[0]=xdistance+room_width/4
    if view_wview[0]<min_wview {view_wview[0]=min_wview}
    if view_wview[0]>max_wview {view_wview[0]=max_wview}
    view_hview[0]=view_wview[0]/room_width*room_height
}
else {
    view_hview[0]=ydistance+room_height/4
    if view_hview[0]<min_hview {view_hview[0]=min_hview}
    if view_hview[0]>max_hview {view_hview[0]=max_hview}
    view_wview[0]=view_hview[0]/room_height*room_width
}

view_xview[0]=(player1.x+player2.x)/2-view_wview[0]/2
view_yview[0]=(player1.y+player2.y)/2-view_hview[0]/2

// keeps the view inside the room

if view_xview[0]+view_wview[0]>room_width {
    view_xview[0]=room_width-view_wview[0]
}

if view_yview[0]+view_hview[0]>room_height {
    view_yview[0]=room_height-view_hview[0]
}

if view_xview[0]<0 {
    view_xview[0]=0
}

if view_yview[0]<0 {
    view_yview[0]=0
}

Thankyou for this code, but how do I apply to my code. sorry I am very new to adding scripts into my game.
  • 0

#27 ironmaneleven

ironmaneleven

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 09 December 2012 - 07:18 AM

Thankyou for this code, but how do I apply to my code. sorry I am very new to adding scripts into my game.

Edited by ironmaneleven, 09 December 2012 - 07:19 AM.

  • 0

#28 AlienJordanwolf

AlienJordanwolf

    GMC Member

  • New Member
  • 1 posts
  • Version:GM8

Posted 03 February 2013 - 07:39 AM

Thank You SOOOO MUCH! I've been needing this for a long time, and i finally found it ::lmao:: ! I might actually even give credit just because you deserve it A LOT :D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users