Jump to content


Photo

Handy view scripts


  • Please log in to reply
7 replies to this topic

#1 HelpMyFellowPeople

HelpMyFellowPeople

    GMC Member

  • GMC Member
  • 239 posts

Posted 24 June 2012 - 01:06 AM

Hello. First of all, I just want to say for this to work, you must enable the views in the room but dont assign an object. Right so this first script centers the view to the object you place in its "END STEP" event. It goes in the "END STEP" event so there is no lagging with the view.
    view_xview[0] = x-view_xview[0]/2
    view_yview[0] = y-view_yview[0]/2

Right, this next script goes on the idea that if the player enters the boundrys of the view, it will switch the view. For example, those classic oddworld games or the old prince of persia or even heart of darkness style views. Pretty much screen to screen. Very simple but very effective. Place also in the "END STEP" event.

    if(x > view_xview+view_wview){view_xview += view_wview;}
    if(y > view_yview+view_hview){view_yview += view_hview;}
    if(x < view_xview){view_xview -= view_wview;}
    if(y < view_yview){view_yview -= view_hview;}  

Hope you all like :)

Edited by HelpMyFellowPeople, 15 July 2012 - 04:12 AM.

  • 0

#2 filulilus

filulilus

    GMC Member

  • GMC Member
  • 936 posts
  • Version:GM:Studio

Posted 09 July 2012 - 08:40 AM

if(x > view_xview+view_wview){view_xview += view_wview;} 
if(y > view_yview+view_hview){view_yview += view_hview;} 
if(x < view_xview){view_xview -= view_wview;} 
if(y < view_yview){view_yview -= view_hview;}
Has the same effect as:
view_xview = floor(x / view_wview)
view_yview = floor(y / view_hview)

These are greate codes for people who are not that familier with GML, good job :thumbsup:

Edited by filulilus, 09 July 2012 - 08:40 AM.

  • 0

#3 ultrav33

ultrav33

    GMC Member

  • GMC Member
  • 273 posts
  • Version:GM:Studio

Posted 11 July 2012 - 09:31 PM

I used this script but it only changes the view once. What i mean is when i leave the screen, it changes but when i leave the screen again in the same direction it doesnt change. My room size is more then big enough.
Tell me if I am doing something wrong?
  • 0

#4 filulilus

filulilus

    GMC Member

  • GMC Member
  • 936 posts
  • Version:GM:Studio

Posted 12 July 2012 - 08:12 AM

You put the code in some kind of repeating event? (step/end step/draw)

And which code did you try?
  • 0

#5 ultrav33

ultrav33

    GMC Member

  • GMC Member
  • 273 posts
  • Version:GM:Studio

Posted 12 July 2012 - 08:39 PM

yea and i put both. Am I only supposed to put one. I put it in the end step event.
  • 0

#6 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 13 July 2012 - 02:29 AM

If you're using his second code, there was a small mistake.
view_xview = floor(x / view_wview) * view_wview;
view_yview = floor(y / view_hview) * view_hview;

Just for the future reference, there also seemed to be a mistake in OP's first code. To comply with the description "this first script centers the view to the object", I believe it should be the following.
view_xview[0] = x - view_wview[0] / 2;
view_yview[0] = y - view_hview[0] / 2;
By the way, it would be nice if the script takes account of the sprite size and offset in case the origin isn't centered. That will make the script more useful than the in-built automatic following system.
  • 0

#7 filulilus

filulilus

    GMC Member

  • GMC Member
  • 936 posts
  • Version:GM:Studio

Posted 13 July 2012 - 06:06 AM

If you're using his second code, there was a small mistake.

Hehe thanks! silly misstake :tongue:
  • 0

#8 HelpMyFellowPeople

HelpMyFellowPeople

    GMC Member

  • GMC Member
  • 239 posts

Posted 15 July 2012 - 04:12 AM

If you're using his second code, there was a small mistake.

view_xview = floor(x / view_wview) * view_wview;
view_yview = floor(y / view_hview) * view_hview;

Just for the future reference, there also seemed to be a mistake in OP's first code. To comply with the description "this first script centers the view to the object", I believe it should be the following.
view_xview[0] = x - view_wview[0] / 2;
view_yview[0] = y - view_hview[0] / 2;
By the way, it would be nice if the script takes account of the sprite size and offset in case the origin isn't centered. That will make the script more useful than the in-built automatic following system.

Ah yes. Ill change that lol. Thanks.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users