GM:S 1.4 Rotate bone relative to the angle of the click on the touch button (Spine 2D)

Discussion in 'Programming' started by wilmer, Oct 8, 2019.

  1. wilmer

    wilmer Member

    Joined:
    Jul 27, 2018
    Posts:
    15
    Greetings to all:
    Is this possible and can you pass me the code?, my character is animated in Spine and he shoots arrows when he releases a touch button, what I want is to see if I can use that button and not the same touch screen as in other games, for example if I have it pressed and my finger on the button I lower it or climb it a bit, rotate the arm bone like this:
    [​IMG]

    This is the code I have:
    Player Object / Create
    :
    Code:
    globalvar xx;
    globalvar bullet;
    globalvar yy;
    globalvar l_shoot;
    globalvar shoot_angle;
    Step event:
    // The following code must find x / y of gun bone.

    Code:
    l_shoot = ds_map_create ();
    skeleton_bone_state_get ("left_pistol", l_shoot); // left_pistol - points the bone where the bullets will be created
    shoot_angle = l_shoot [? "angle"];
    xx = x + l_shoot [? "worldX"]; // x and y of object
    yy = y + l_shoot [? "worldY"];
    ds_map_destroy (l_shoot);
    // When releasing the button, launch arrow
    Code:
    if keyboard_check_released(ord("Z")){
        bullet = instance_create(xx,yy,obj_Arrow);
        bullet.gravity = .5;
        bullet.friction = .1;
        bullet.direction = 0;
        bullet.speed = 25 + random(3);
    
    }
    obj_Arrow / Event Step: // Object of the arrow
    Code:
    image_angle = direction
    obj_btnArrow / Create Event: // Touch button to shoot the arrow
    Code:
    AddKey (ord ("Z"));// This is a simple Script for Virtual Keys
    
     
    Last edited: Oct 8, 2019
  2. johnwo

    johnwo Member

    Joined:
    Jun 20, 2016
    Posts:
    239
    You're nearly there:
    Get the current angle of the bone(s) with skeleton_bone_state_get, modify the variables in the map(s), then apply the changes with skeleton_bone_state_set.
    Do this in the animation update event.
     
  3. wilmer

    wilmer Member

    Joined:
    Jul 27, 2018
    Posts:
    15
    Thanks johnwo, the problem is that codes like that I look for in forums and I adapt them to my game, but I still need to know a lot and I don't have the head right now to write what you told me, I'm a graphic designer and I don't understand GML In its whole.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice