Jump to content


Photo
- - - - -

Two Objects In One View Example


  • Please log in to reply
27 replies to this topic

#1 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 16 January 2009 - 07:33 AM

  • Title: Two Objects in View Example
  • Description: This simple example will teach you how to put two objects in a view.
  • GM Version: GM7
  • Registered: No
  • File Type: .ZIP
  • File Size: 39.09 KB
  • File Link: http://www.mediafire.com/?wa9twaolago
Additional Info:
This example shows how two objects are put into one view. It was made in simple GML, but with comments to make sure you know what is going on. It requires no credit whatsoever. Also, you can use the graphics without giving credit, which were made in seconds.
Here is the simple script to use when you want two objects in a view:
/*
TWO OBJECTS IN VIEW SCRIPT

No credit is required to use this simple script!
How to use: two_object_view(otherobject,viewnumber)

By: daman123125*/

view_hview[argument1]=(distance_to_object(argument
0)*1.5)+150 //sets the height of the view to the distance to the second object times 1.5 plus 150
view_wview[argument1]=(distance_to_object(argument
0)*2)+180 //sets the width of the view to the distance to the second object times 2 plus 180
view_xview[argument1]=((x+argument0.x)/2)-(view_wview[argument1]/2)//sets the x position of the view
view_yview[argument1]=((y+argument0.y)/2)-(view_hview[argument1]/2)// sets the y position of the view

Edited by daman123125, 16 April 2013 - 02:23 AM.

  • 2

#2 Snotrocket

Snotrocket

    GMC Member

  • New Member
  • 121 posts

Posted 17 January 2009 - 12:45 AM

hey thats a very nice example! I never hought it would be that easy to change the view like that. Everything is very well documkented except the script, which i think would need the most. I don't understand which parts of the script do what and why you chose those numbers :s
But it might just be me because I'm already busy making a game and trying to learn a thousand things at once so I don't have too much time to be tweaking code I wont need.

but i'll definetly find this usefull in the future! thanks alot!
  • 0

#3 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 17 January 2009 - 03:02 AM

Ok. I've edited the first post to show the script, with comments.
Thanks for the comment. :)
  • 0

#4 Snotrocket

Snotrocket

    GMC Member

  • New Member
  • 121 posts

Posted 17 January 2009 - 03:12 AM

:)
i totally get it now! thanks alot that was really helpfull!
  • 0

#5 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 17 January 2009 - 08:59 PM

No problem.

I've been seeing a lot of people trying to get 2 objects in a view. Anyone else want to comment?
  • 0

#6 Mocgames998

Mocgames998

    GMC Member

  • GMC Member
  • 76 posts

Posted 18 January 2009 - 12:55 AM

Congratulations, you perfectly emulated the SSB camera system without much GML! :)
  • 0

#7 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 18 January 2009 - 01:28 AM

Well, this tutorial only has two objects, and in SSB, there's 4 players...
But, anyways, thanks for the comment! :)
  • 0

#8 deric007

deric007

    GMC Member

  • GMC Member
  • 165 posts

Posted 04 February 2009 - 08:30 PM

Very ce example!! ^_^ :)
  • 0

#9 appledave42

appledave42

    GMC Member

  • New Member
  • 1 posts

Posted 11 March 2009 - 04:20 PM

Dude, ty. This is v. easy way but it works well. You could make it so the camera stays on screen, but I'll add that myself 4 my game. :)
  • 0

#10 digidog08

digidog08

    GMC Member

  • New Member
  • 69 posts

Posted 30 May 2009 - 06:55 PM

SSB Camera Lite!


A few request:
I am making an action battle sidescroller. I want the camera to focus on the closet object parented with par_enemy and the main player's object. And when it destroyed, set the view back to normal until another object parented with par_enemy is close.

I also want it to set the view back to normal if the distance_to_object(hero) and any instance with the parent "par_enemy" is out of view (or 400 pixels away).

I'm decent in GML, so i should be able to follow any reply given.

Edited by digidog08, 31 May 2009 - 01:17 AM.

  • 0

#11 piedude04

piedude04

    GMC Member

  • New Member
  • 330 posts

Posted 31 May 2009 - 06:15 AM

Hmm...how would you do this with one object and the mouse? Since the cursor pretty much moves along when the view changes, so it goes crazy.
  • 0

#12 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 31 May 2009 - 09:57 PM

You can just edit the script:
view_hview[argument1]=(distance_to_object(argument0)*1.5)+150
view_wview[argument1]=(distance_to_object(argument0)*2)+180
view_xview[argument1]=((x+argument0.x)/2)-(view_wview[0]/2)
view_yview[argument1]=((y+argument0.y)/2)-(view_hview[0]/2)
To this:
view_hview[argument1]=(distance_to_point(mouse_x,mouse_y)*1.5)+150
view_wview[argument1]=(distance_to_point(mouse_x,mouse_y)*2)+180
view_xview[argument1]=((x+mouse_x)/2)-(view_wview[0]/2)
view_yview[argument1]=((y+mouse_y)/2)-(view_hview[0]/2)

  • 0

#13 piedude04

piedude04

    GMC Member

  • New Member
  • 330 posts

Posted 01 June 2009 - 06:47 AM

I still get the problem: it still goes crazy. Since the cursor changes position in the room as the view changes size, the view would keep getting bigger or smaller even when the user isn't moving the mouse.
  • 0

#14 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 01 June 2009 - 02:45 PM

Try using window_set_mouse to change the position.
I'm not sure how you would do it though.
  • 0

#15 chocoblock

chocoblock

    GMC Member

  • New Member
  • 35 posts

Posted 01 June 2009 - 08:11 PM

I really like how this works its a very nice and easy to implement. :)
  • 0

#16 digidog08

digidog08

    GMC Member

  • New Member
  • 69 posts

Posted 02 June 2009 - 01:37 AM

I solved my problem. I edited to where i created an invisible object that turns into a "zoom in object"
SO like, if you are moving towards an area (such as a hill) It will zoom in as you approach it, and zoom out as you leave it.
  • 0

#17 capitankl

capitankl

    GMC Member

  • New Member
  • 1 posts

Posted 20 July 2009 - 10:13 PM

thanks so much I have made a 4 players race but I hope this can work very googd your example, I understand everything Thanks!!!
  • 0

#18 Strickendead

Strickendead

    GMC Member

  • New Member
  • 1 posts

Posted 20 January 2010 - 09:50 PM

view_xview[argument1]=((x+argument0.x)/2)-(view_wview[0]/2)//sets the x position of the view
view_yview[argument1]=((y+argument0.y)/2)-(view_hview[0]/2)// sets the y position of the view



In the last part of these two lines "(view_hview[0]/2)", is there a reason you used 0 on this one or should it be argument1? "(view_hview[argument1]/2)"

Edited by Strickendead, 20 January 2010 - 09:51 PM.

  • 0

#19 daman123125

daman123125

    AZN Game Programmer

  • GMC Member
  • 1955 posts
  • Version:GM8

Posted 21 January 2010 - 12:24 AM

It doesn't exactly matter, since there is only one view.
You probably wouldn't need multiple views, unless in the rare case you do, argument1 is there.
argument1 is just what view you are using, and goes from 0 to 7.
  • 0

#20 Braden

Braden

    GMC Member

  • New Member
  • 12 posts

Posted 16 February 2010 - 10:15 AM

if anyones interested im in the process of making one that uses a ds list for the objects to follow
so you can add an object to the list and the camera will adjust to follow more then 2 objects

for now heres a mod to the script to keep it within the bounds of the room size, enjoy


view_wview[argument1]=min(view_wport[argument1],max(distance_to_object(argument0)*2,view_wport[argument1]/2)); // sets the width of the view
view_hview[argument1]=min(view_hport[argument1],max(distance_to_object(argument0)*2,view_hport[argument1]/2)); // sets the height of the view
view_xview[argument1]=((x+argument0.x)/2)-(view_wview[argument1]/2) // sets the x position of the view
view_yview[argument1]=((y+argument0.y)/2)-(view_hview[argument1]/2) // sets the y position of the view

// keep view within bounds of room
if view_xview[argument1]+view_wview[argument1]>room_width {view_xview[argument1]=room_width-view_wview[argument1];}
if view_yview[argument1]+view_hview[argument1]>room_height {view_yview[argument1]=room_height-view_hview[argument1];}
if view_xview[argument1]<0 {view_xview[argument1]=0;}
if view_yview[argument1]<0 {view_yview[argument1]=0;}

<shameless plug> when i get the new camera script working it will be in my TDS [see sig] </ shamless plug>
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users