본문 바로가기
개발 일지

GMS2로 RPG 만들기1 - 2019. 09. 08

by PrintedLove 2019. 9. 8.

 

 

 

계발 약 3일차 인게임 영상입니다.

 

물리엔진 밑 모션의 틀 정도만 잡아두고 스탯 설정 중입니다.

 

사용된 조이스틱 코드-

 

스탭:

 

m_x = device_mouse_x_to_gui(0); m_y = device_mouse_y_to_gui(0);
if device_mouse_check_button(0, mb_left) && device_mouse_x_to_gui(0)>=0 && device_mouse_x_to_gui(0)<=160 && device_mouse_y_to_gui(0)<=180 && device_mouse_y_to_gui(0)>=36{
joystick_alpha=2
if (!joystick_active) && m_x<=90 && m_y>=90{
joystick_anchor_x = m_x; joystick_anchor_y = m_y;
joystick_active = true;
}
else{ joystick_angle = point_direction(joystick_anchor_x,joystick_anchor_y,m_x,m_y);
joystick_distance = point_distance(joystick_anchor_x,joystick_anchor_y,m_x,m_y);
joystick_movement_x = dcos(joystick_angle)*min(25, joystick_distance); joystick_movement_y = -dsin(joystick_angle)*min(25, joystick_distance);
}
}
else{ joystick_active = false;
joystick_movement_x=0; joystick_movement_y=0;
if joystick_alpha>0.2 joystick_alpha-=0.05;
}

 

 

드로우:

 

draw_sprite_ext(spr_Joystick, 0, joystick_anchor_x, joystick_anchor_y,1,1,0,image_blend,joystick_alpha);
draw_sprite_ext(spr_Joystick, 1, joystick_anchor_x+joystick_movement_x, joystick_anchor_y+joystick_movement_y,1,1,0,image_blend,joystick_alpha);

 

 

 

원리는 간단합니다.

처음 터치한 지점의 좌표와 드래그 해 이동하는 좌표를 구해 두 좌표의 각도와 거리를 계산하는게 다입니다.

 

 

 

 

https://youtu.be/qPXn8t8BNlg

 

 위 강좌를 참고했습니다.

댓글