GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2012-09-04 10:04:46

neil_v
Member
Registered: 2010-05-28
Posts: 6

scr_scrollView & scr_scrollViewKey

-EDIT-
Last submission 2011? wow, I must be missing something here.
---

I should have posted here first before attempting to submit these, but I didn't even know there WAS a forum.
I am an intermediate gml'er, so please rip this apart if you so desire (I like to learn to do things better)

these scripts involve moving the view via the mouse, and without following objects:
(I've attempted to put the codes in spoiler buttons, but it the spoiler does not seem to be working)
scr_scrollView:

Expand/* Scroll the current view with the mouse
** If the mouse moves outside the view, the scrolling will stop.
**
**  Usage:
**      scr_scrollView (borderSize,scrollSpd,accel)
**      scr_scrollView(64,2,0.5); is a good example
**      
**  Arguments:
**      borderSize     -How far from the edge of the view activates movement.
**      scrollSpd      -How fast the screen scrolls 2-4 is normal
**      accel          -0 to 1 (0.5 is normal) as you get closer to the edge of the view
**                      the speed will increase by a percentage of the distance to the edge 
**      
**  Returns:
**      nothing
**
**
**  Notes:
**      As you increase the border size, you should decrease the accel fraction size.
**      For example: scr_scrollViewKey(256,2,0.1);
**
**  GMLscripts.com
*/

{
    var borderSize,scrollSpd,accel;
    borderSize=argument0;
    scrollSpd=argument1;
    accel=argument2;
    
    if (mouse_x<view_xview[view_current]+borderSize&&mouse_x>view_xview[view_current]
     ||(keyboard_check(vk_left))&&(view_xview[view_current]>0)){
        view_xview[view_current]-=scrollSpd+point_distance(view_xview[view_current]+
         borderSize,mouse_y,mouse_x,mouse_y)*accel;
        if (view_xview[view_current]<0){
            view_xview[view_current]=0;
            };
        };
    else if (mouse_x>view_xview[view_current]+view_wview[view_current]
     -borderSize&&mouse_x<view_xview[view_current]+view_wview[view_current]
     ||(keyboard_check(vk_right))&&(view_xview[view_current]+view_wview[view_current]<room_width)){
        view_xview[view_current]+=scrollSpd+point_distance(view_xview[view_current]+
         view_wview[view_current]-borderSize,mouse_y,mouse_x,mouse_y)*accel;
        if (view_xview[view_current]+view_wview[view_current]>room_width){
            view_xview[view_current]=room_width-view_wview[view_current];
            };
        };
    
    if (mouse_y<view_yview[view_current]+borderSize&&mouse_y>view_yview[view_current]
     ||(keyboard_check(vk_up))&&(view_yview[view_current]>0)){
        view_yview[view_current]-=scrollSpd+point_distance(mouse_x,view_yview[view_current]+
         borderSize,mouse_x,mouse_y)*accel;
        if (view_yview[view_current]<0){
            view_yview[view_current]=0;
            };
        };
    else if (mouse_y>view_yview[view_current]+view_hview[view_current]
     -borderSize&&mouse_y<view_yview[view_current]+view_hview[view_current]
     ||(keyboard_check(vk_down))&&(view_yview[view_current]+view_hview[view_current]<room_height)){
        view_yview[view_current]+=scrollSpd+point_distance(mouse_x,view_yview[view_current]+
         view_hview[view_current]-borderSize,mouse_x,mouse_y)*accel;
        if (view_yview[view_current]+view_hview[view_current]>room_height){
                view_yview[view_current]=room_height-view_hview[view_current];
            };
        };
}

scr_scrollViewKey:

Expand/* Scroll the current view with the mouse, and optionally; the keyboard directional keys.
** If the mouse moves outside the view, the scrolling will stop.
**
**  Usage:
**      scr_scrollViewKey (borderSize,scrollSpd,keyCtrl,accel)
**      scr_scrollViewKey(64,2,true,0.5); is a good example
**      
**  Arguments:
**      borderSize     -How far from the edge of the view activates movement.
**      scrollSpd      -How fast the screen scrolls 2-4 is normal
**      keyCtrl        -True/False, Allow/Disallow use of keyboard directional keys.
**      accel          -0 to 1 (0.5 is normal) as you get closer to the edge of the view
**                      the speed will increase by a percentage of the distance to the edge 
**      
**  Returns:
**      nothing
**
**
**  Notes:
**      As you increase the border size, you should decrease the accel fraction size.
**      For example: scr_scrollViewKey(256,2,true,0.1);
**
**  GMLscripts.com
*/

{
    var borderSize,scrollSpd,keyCtrl,accel,keybScroll;
    borderSize=argument0;
    scrollSpd=argument1;
    keyCtrl=argument2;
    accel=argument3;
    keybScroll=scrollSpd*(scrollSpd*1.5)
    if (mouse_x<view_xview[view_current]+borderSize&&mouse_x>view_xview[view_current]
        ||(keyboard_check(vk_left)&&keyCtrl)&&(view_xview[view_current]>0)){
        if (!keyboard_check(vk_anykey)){
            view_xview[view_current]-=scrollSpd+point_distance(view_xview[view_current]+
             borderSize,mouse_y,mouse_x,mouse_y)*accel;
            };
        else{
            view_xview[view_current]-=keybScroll;
            };
        if (view_xview[view_current]<0){
            view_xview[view_current]=0;
            };
        };
    else if (mouse_x>view_xview[view_current]+view_wview[view_current]
        -borderSize&&mouse_x<view_xview[view_current]+view_wview[view_current]
         ||(keyboard_check(vk_right)&&keyCtrl)&&(view_xview[view_current]+view_wview[view_current]<room_width)){
        if (!keyboard_check(vk_anykey)){
            view_xview[view_current]+=scrollSpd+point_distance(view_xview[view_current]+
             view_wview[view_current]-borderSize,mouse_y,mouse_x,mouse_y)*accel;
            };
        else{
            view_xview[view_current]+=keybScroll;
            };
        if (view_xview[view_current]+view_wview[view_current]>room_width){
            view_xview[view_current]=room_width-view_wview[view_current];
            };
        };
    
    if (mouse_y<view_yview[view_current]+borderSize&&mouse_y>view_yview[view_current]
        ||(keyboard_check(vk_up)&&keyCtrl)&&(view_yview[view_current]>0)){
        if (!keyboard_check(vk_anykey)){
            view_yview[view_current]-=scrollSpd+point_distance(mouse_x,view_yview[view_current]+
             borderSize,mouse_x,mouse_y)*accel;
             };
        else{
            view_yview[view_current]-=keybScroll;
            };
        if (view_yview[view_current]<0){
            view_yview[view_current]=0;
            };
        };
    else if (mouse_y>view_yview[view_current]+view_hview[view_current]
        -borderSize&&mouse_y<view_yview[view_current]+view_hview[view_current]
         ||(keyboard_check(vk_down)&&keyCtrl)&&(view_yview[view_current]+view_hview[view_current]<room_height)){
            if (!keyboard_check(vk_anykey)){
                view_yview[view_current]+=scrollSpd+point_distance(mouse_x,view_yview[view_current]+
                 view_hview[view_current]-borderSize,mouse_x,mouse_y)*accel;
                 };
            else{
                view_yview[view_current]+=keybScroll;
                };
            if (view_yview[view_current]+view_hview[view_current]>room_height){
                view_yview[view_current]=room_height-view_hview[view_current];
                };
            };
}

Last edited by neil_v (2012-10-12 06:36:45)

Offline

#2 2012-09-08 18:44:01

xot
Administrator
Registered: 2007-08-18
Posts: 1,240

Re: scr_scrollView & scr_scrollViewKey

Hi Neil. I don't think many people are aware of the script submission forum.

These are great script ideas, thanks for submitting them. I haven't tested them yet, but they look like they should work well.

There are a few unnecessary (but benign) semicolons following curly braces, which is minor. The only really strange thing I see is here:

Expandview_yview[view_current]+=scrollSpd*(16/scrollSpd);

"scrollSpd*(16/scrollSpd)" reduces to simply "16". I presume the original intent was to adjust the rate of keyboard scrolling with the scrollSpd argument.


Abusing forum power since 1986.

Offline

#3 2012-09-15 10:57:35

neil_v
Member
Registered: 2010-05-28
Posts: 6

Re: scr_scrollView & scr_scrollViewKey

Yes, 16... wow. I guess I was playing with what felt natural across a broad spectrum of viable scrollSpeeds, and ended up with something redundant.

Lets go with:

Expandview_yview[view_current]+=scrollSpd*8;

Or something better if anyone has suggestions.

Offline

#4 2012-10-12 06:38:05

neil_v
Member
Registered: 2010-05-28
Posts: 6

Re: scr_scrollView & scr_scrollViewKey

I fixed the redundancy and re-posted the script above.

Offline

Board footer

Powered by FluxBB