Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: petpan13 en Enero 31, 2016, 08:02:37 PM

Título: tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: petpan13 en Enero 31, 2016, 08:02:37 PM
tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayudarme?

valores del script

///vstick_init(stick_id,x,y,r,square_calculation,backsprite,frontsprite)
/*
WARNING!: The virtual joysticks use the globalvar vstick to hold the array.
Please do not use this variable elsewhere in your game, as it will cause conflicts.

This script adds a joystick with a given id.

stick_id:           The id to be given to the stick. This can be any integer value, but should be unique to each joystick.

x,y:                The x and y values are relative to the GUI layer, as the vstick_draw function is supposed
                    to be called in the GUI_draw event.

r:                  The radius of the joystick.

square_calculation: If enabled, it will map out the values on the dpad from -1 to 1 (follows GM's axis)
                    over the entire circle, instead of the actual x and y values (very much like on a gamepad).
                   
backsprite:         In case you want to use a background sprite for the thumbstick, instead of the default coded variant. The origin should be the center of the dpad.
                    If you don't have a sprite for this, set this value to noone.
                   
frontsprite:        The sprite for the actual stick itself. Works like the backsprite.
*/

globalvar vstick;
vstick[argument0,0]=0;//vstick xaxis
vstick[argument0,1]=0;//vstick yaxis
vstick[argument0,2]=argument3;//vstick radius
vstick[argument0,3]=argument1;//vstick x
vstick[argument0,4]=argument2;//vstick y
vstick[argument0,5]=1;//vstick active
vstick[argument0,6]=0;//vstick drag --> vstick_check
vstick[argument0,7]=-1;//vstick device id
vstick[argument0,8]=0;//vstick direction in radians
vstick[argument0,10]=argument4;//square calculation
vstick[argument0,11]=0;//draw_xaxis
vstick[argument0,12]=0;//draw_yaxis
vstick[argument0,13]=argument5;//vstick backsprite
vstick[argument0,14]=argument6;//vstick frontsprite
vstick[argument0,15]=0; //vstick_check_pressed
vstick[argument0,16]=0; //vstick_check_released






parte del scrip



   vstick[argument0,8]=degtorad(point_direction(vstick[argument0,3],vstick[argument0,4],device_mouse_x_to_gui(vstick[argument0,7]),device_mouse_y_to_gui(vstick[argument0,7])));
        vstick[argument0,0]=cos(vstick[argument0,8])*min(point_distance(vstick[argument0,3],vstick[argument0,4],device_mouse_x_to_gui(vstick[argument0,7]),device_mouse_y_to_gui(vstick[argument0,7])),vstick[argument0,2])/vstick[argument0,2];
        vstick[argument0,1]=-sin(vstick[argument0,8])*min(point_distance(vstick[argument0,3],vstick[argument0,4],device_mouse_x_to_gui(vstick[argument0,7]),device_mouse_y_to_gui(vstick[argument0,7])),vstick[argument0,2])/vstick[argument0,2];
        vstick[argument0,11]=vstick[argument0,0];
        vstick[argument0,12]=vstick[argument0,1];
 
        if vstick[argument0,10]{ //mapping
            var xunscaled,yunscaled;
           
           
             if (vstick[argument0,8]<=pi/4 or vstick[argument0,8]>=7*pi/4)
            {
                xunscaled=1;
                yunscaled=-tan(vstick[argument0,8]);direB=5
            }
            if (vstick[argument0,8]>=pi/4 and vstick[argument0,8]<=3*pi/4)
            {
                xunscaled=1/tan(vstick[argument0,8]);
                yunscaled=-1;direB=2
            }
            if (vstick[argument0,8]>=3*pi/4 and vstick[argument0,8]<=5*pi/4)
            {
                xunscaled=-1;direB=3
                yunscaled=tan(vstick[argument0,8]);
            }
            if (vstick[argument0,8]>=5*pi/4 and vstick[argument0,8]<=7*pi/4)
            {
                xunscaled=-1/tan(vstick[argument0,8]);
                yunscaled=1;direB=4
           }


y el enlace del marketplace del que he modificado
            https://marketplace.yoyogames.com/assets/258/virtual-joysticks
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: Clamud en Febrero 01, 2016, 05:05:47 PM
No se si sea obligatorio usar radianes, pero me parece que de esa forma está haciendo más operaciones de las necesarias. Esta es mi modificación borrando la función que convierte grados en radianes:
[gml]
vstick[argument0,8]=point_direction(vstick[argument0,3],vstick[argument0,4],device_mouse_x_to_gui(vstick[argument0,7]),device_mouse_y_to_gui(vstick[argument0,7]));
[/gml]
[gml]
if( vstick[argument0,8]>=337.5 or  vstick[argument0,8]<22.5  ) direB = //derecha
if( vstick[argument0,8]>=22.5  and vstick[argument0,8]<67.5  ) direB = //derecha arriba
if( vstick[argument0,8]>=67.5  and vstick[argument0,8]<112.5 ) direB = //arriba
if( vstick[argument0,8]>=112.5 and vstick[argument0,8]<157.5 ) direB = //izquierda arriba
if( vstick[argument0,8]>=157.5 and vstick[argument0,8]<202.5 ) direB = //izquierda
if( vstick[argument0,8]>=202.5 and vstick[argument0,8]<247.5 ) direB = //izquierda abajo
if( vstick[argument0,8]>=247.5 and vstick[argument0,8]<292.5 ) direB = //abajo
if( vstick[argument0,8]>=292.5 and vstick[argument0,8]<337.5 ) direB = //derecha abajo

xunscaled = lengthdir_x(1,vstick[argument0,8]);
yunscaled = lengthdir_y(1,vstick[argument0,8]);
[/gml]
asigna a direB el valor que se ajuste a tus necesidades
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: petpan13 en Febrero 01, 2016, 09:25:29 PM
muchísimas gracias funciona a la perfección RESUELTO
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: Tigerito019 en Febrero 03, 2016, 02:16:52 AM
Este Joystick me parece interesante, pero no entendí muy bien donde va cada función, me ayudarían a colocar esos códigos? o enviandome un ejemplo, seria de gran ayuda.
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: petpan13 en Febrero 03, 2016, 12:04:35 PM
Viene el enlace del scrip esta en el maeket palace de yoyo es gratis
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: Tigerito019 en Febrero 03, 2016, 12:11:59 PM
Ya sé amigo, pero es que no sé como hacer que el joystick funcione, hice el ejemplo que coloca el autor en el market pero solo muestra el joystick y cuando lo presiono no hace nada, podrías decirme cómo lo tienes tú?
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: Tigerito019 en Febrero 05, 2016, 01:52:19 AM
Cita de: petpan13 en Febrero 03, 2016, 12:04:35 PM
Viene el enlace del scrip esta en el maeket palace de yoyo es gratis

Hola de nuevo amigo, disculpa que moleste tanto pero necesito tu ayuda, ya logré que el Joystick funcionara y se moviera perfectamente, pero ahora no sé como hacer para mover al jugador, qué código se debe usar o qué debo hacer?
Título: Re:tengo un jostick en 4 direcciones con radianes y quiero ponerlo en 8 podian ayud
Publicado por: petpan13 en Febrero 05, 2016, 10:11:00 AM
Ves donde pone direb=
Es para determinar estado
Una variable global
En donde pone derecha pones 1
Despues crea objeto player
En el evento step pones
If direb=1 x=x+5
Y a si