• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Rotating multiple Instances

Alphy

Member
Hi, is there a way to rotate more than one object with a center x and center y values? Something like this.

ezgif.com-gif-maker (2).gif
 

gnysek

Member
Yes, it possible, bug origin need to be set in center of image for them to make it easily, otherwise you may need to write more complex code.

It will be something like this (wrote from memory):
GML:
function rotate_against_point(xx, yy, angle) {
    var len = point_distance(xx, yy, xstart, ystart);
    var ang = point_direction(xx, yy, xstart, ystart);
    
    x = xx+ lengthdir_x(len, angle);
    y = yy + lengthdir_x(len, angle);
    image_angle = angle - ang;
}
 

hogwater

Member
This is a script for rotating a DS Grid I found on gmlscripts at some point (doesn't seem to be there now), and it works quite well.

Code:
/// @description ds_grid_rotate(Grid id, Clockwise, Rotation)
/// @function ds_grid_rotate
/// @param Grid id
/// @param  Clockwise
/// @param  Rotation
function ds_grid_rotate(argument0, argument1, argument2) {
    //Rotate the value on a grid Clockwise or Counterclockwise
    //Set Clockwise to true. If false it's Counterclockwise.
    //Rotation: Number of rotations: 1-2-3 (You can crank that number if you want, it will be 'moded'.)

    /*
    Examples:
    CW, 1 rotation:
    012
    345
    678
    becomes:
    630
    741
    852

    CCW, 1 rotation:
    0123
    4567
    becomes:
    40
    51
    62
    73

    CW, 2 rotation:
    012
    345
    becomes:
    543
    210
    */

    var grid = argument0;
    var clockwise = argument1;
    var nmb_rot = argument2;

    nmb_rot = nmb_rot mod 4; //To prevent a stack overflow error.

    if nmb_rot == 0
    {
    exit;
    }

    var gw = ds_grid_width(grid);
    var gh = ds_grid_height(grid);

    var tmp_grid = ds_grid_create(gh,gw);
    var xx, yy, txx, tyy;

    if (clockwise)
    {
    txx = gh-1;
    tyy = 0;

        for(yy=0; yy<gh; yy++)
        {
            for (xx=0; xx<gw; xx++)
            {
            ds_grid_set(tmp_grid, txx, tyy, ds_grid_get(grid, xx, yy));
            tyy++;
            }
       
        tyy=0; 
        txx--;
        }
    }
    else
    {
    txx = 0;
    tyy = gw-1;

        for(yy=0; yy<gh; yy++)
        {
            for (xx=0; xx<gw; xx++)
            {
            ds_grid_set(tmp_grid, txx, tyy, ds_grid_get(grid, xx, yy));
            tyy--;
            }
       
        tyy=gw-1; 
        txx++;
        }
    }

    ds_grid_copy(grid, tmp_grid);
    ds_grid_destroy(tmp_grid);


    nmb_rot--;

    if (nmb_rot > 0)
    {
    ds_grid_rotate(clockwise, grid, nmb_rot); //This is where a stack over flow could occurs. ie: Asking to rotate 1000 times. But we've mod nmb_rot so it won't happen.
    }















}
I didn't write this, so I've posted it verbatim as written.
 

Alphy

Member
Yes, it possible, bug origin need to be set in center of image for them to make it easily, otherwise you may need to write more complex code.

It will be something like this (wrote from memory):
GML:
function rotate_against_point(xx, yy, angle) {
    var len = point_distance(xx, yy, xstart, ystart);
    var ang = point_direction(xx, yy, xstart, ystart);
   
    x = xx+ lengthdir_x(len, angle);
    y = yy + lengthdir_x(len, angle);
    image_angle = angle - ang;
}
Looks good, but i think instead of y = yy + lengthdir_x(len, angle); it should be y = yy + lengthdir_y(len, angle);, also, it doesn't seems to work well, the objects with the script doesn't start at their initial position.
 
Top