Таким образом, мой персонаж движется по экрану, управляемому левой ручкой контроллера Xbox One, но всякий раз, когда я наклоняю левую ручку под определенным углом, sdl_pollevent
не обнаруживает никаких событий, хотя на самом деле я все еще наклоняю левую палку.путь к его краю.Я подтвердил это, вставив writeln(random(10))
после оператора if sdl_pollevent(sdlevent)=1 then
, и случайное число не отображалось, а sdl_pollevent(sdlevent)
осталось равным нулю.
Часть моего кода, получающего события для контроллера, - это (пожалуйста, обратите внимание, что внутри условных операторов также есть дополнительный код для обслуживания клавиатуры и мыши, а также кнопок и триггеров контроллера, но которые я здесь не включил):
if sdl_pollevent(sdlevent)=1 then
begin
if joystickuse=true then
begin
if sdlevent^.type_=sdl_joyaxismotion then
begin
joystickactive:=true;
if sdlevent^.jaxis.which=0 then
begin
{ writeln(sdlevent^.jaxis.axis,' ',sdlevent^.jaxis.value); }
if sdlevent^.jaxis.axis=0 then
begin
{ writeln('y ',sdlevent^.jaxis.value); }
joystickxy[2]:=sdlevent^.jaxis.value;
if sdlevent^.jaxis.value<-joystickdeadzone then joystickaxis[1,4]:=true; { left }
if sdlevent^.jaxis.value>joystickdeadzone then joystickaxis[1,3]:=true; { right }
if (sdlevent^.jaxis.value>=-joystickdeadzone) and (sdlevent^.jaxis.value<=joystickdeadzone) then
begin
joystickaxis[1,3]:=false;
joystickaxis[1,4]:=false;
joystickmenuscrollticks1[1]:=0;
joystickmenuscrollbool1:=false;
end
else
begin
if joystickmenuscrollticks1[1]=0 then joystickmenuscrollticks1[1]:=sdl_getticks;
end;
{ left stick y (- left, + right) }
end;
if sdlevent^.jaxis.axis=1 then
begin
{ writeln('x ',sdlevent^.jaxis.value); }
joystickxy[1]:=sdlevent^.jaxis.value;
if sdlevent^.jaxis.value<-joystickdeadzone then joystickaxis[1,2]:=true; { up }
if sdlevent^.jaxis.value>joystickdeadzone then joystickaxis[1,1]:=true; { down }
if (sdlevent^.jaxis.value>=-joystickdeadzone) and (sdlevent^.jaxis.value<=joystickdeadzone) then
begin
joystickaxis[1,1]:=false;
joystickaxis[1,2]:=false;
joystickmenuscrollticks[1]:=0;
joystickmenuscrollbool:=false;
end
else
begin
if joystickmenuscrollticks[1]=0 then joystickmenuscrollticks[1]:=sdl_getticks;
end;
{ left stick x (- up, + down) }
end;
if sdlevent^.jaxis.axis=2 then
begin
if sdlevent^.jaxis.value<-joystickdeadzone then joystickaxis[2,4]:=true; { left }
if sdlevent^.jaxis.value>joystickdeadzone then joystickaxis[2,3]:=true; { right }
if (sdlevent^.jaxis.value>=-joystickdeadzone) and (sdlevent^.jaxis.value<=joystickdeadzone) then
begin
joystickaxis[2,3]:=false;
joystickaxis[2,4]:=false;
joystickmenuscrollticks1[1]:=0;
joystickmenuscrollbool1:=false;
end
else
begin
if joystickmenuscrollticks1[1]=0 then joystickmenuscrollticks1[1]:=sdl_getticks;
end;
{ right stick y }
end;
if sdlevent^.jaxis.axis=3 then
begin
if sdlevent^.jaxis.value<-joystickdeadzone then joystickaxis[2,2]:=true; { up }
if sdlevent^.jaxis.value>joystickdeadzone then joystickaxis[2,1]:=true; { down }
if (sdlevent^.jaxis.value>=-joystickdeadzone) and (sdlevent^.jaxis.value<=joystickdeadzone) then
begin
joystickaxis[2,1]:=false;
joystickaxis[2,2]:=false;
joystickmenuscrollticks[1]:=0;
joystickmenuscrollbool:=false;
end
else
begin
if joystickmenuscrollticks[1]=0 then joystickmenuscrollticks[1]:=sdl_getticks;
end;
{ right stick x }
end;
if sdlevent^.jaxis.axis=4 then
begin
{ writeln(sdlevent^.jaxis.value); }
if (activemenum[1]=false) and (activemenum[2]=false) then
begin
if sdlevent^.jaxis.value>joysticktriggersdeadzone then
begin
joysticktriggers[1]:=true;
end
else
begin
joysticktriggers[1]:=false;
end;
end;
{ left trigger }
end;
if sdlevent^.jaxis.axis=5 then
begin
{ writeln(sdlevent^.jaxis.value); }
if sdlevent^.jaxis.value>joysticktriggersdeadzone then
begin
joysticktriggers[2]:=true;
end
else
begin
joysticktriggers[2]:=false;
end;
{ right trigger }
end;
joystickangle:=round(arctan2(joystickxy[2],joystickxy[1])*(180/pi)); { used for getting joystick angle: left stick bottom 0, right 90, top 180, left -90, top -180}
if (joystickxy[1]=0) and (joystickxy[2]=0) then joystickangle:=0;
{ writeln(joystickangle); }
o[1]:=0;
repeat
o[1]:=o[1]+1;
joystick8dirstate[1,o[1]]:=false;
joystick8dirstate[2,o[1]]:=false;
until o[1]=8;
if joystickaxis[1,1]=true then
begin
if (joystickangle>=-round(joystick8dirtolangle/2)) and (joystickangle<=0) or (joystickangle>=0) and (joystickangle<=round(joystick8dirtolangle/2)) then joystick8dirstate[1,1]:=true; { down }
end;
if joystickaxis[1,2]=true then
begin
if (joystickangle>=-180) and (joystickangle<=-180+round(joystick8dirtolangle/2)) or (joystickangle>=180-round(joystick8dirtolangle/2)) and (joystickangle<=180) then joystick8dirstate[1,2]:=true; { up }
end;
if (joystickaxis[1,3]=true) and (joystickangle>=90-joystick8dirtolangle) and (joystickangle<=90+joystick8dirtolangle) then joystick8dirstate[1,3]:=true; { right }
if (joystickaxis[1,4]=true) and (joystickangle>=-90-joystick8dirtolangle) and (joystickangle<=-90+joystick8dirtolangle) then joystick8dirstate[1,4]:=true; { left }
if (joystickaxis[1,2]=true) and (joystickaxis[1,3]=true) and (joystickangle>=90+45-joystick8dirtolangle) and (joystickangle<=90+45+joystick8dirtolangle) then
begin
joystick8dirstate[1,5]:=true; { up+right }
joystick8dirstate[1,2]:=false;
joystick8dirstate[1,3]:=false;
end;
if (joystickaxis[1,1]=true) and (joystickaxis[1,3]=true) and (joystickangle>=90-45-joystick8dirtolangle) and (joystickangle<=90-45+joystick8dirtolangle) then
begin
joystick8dirstate[1,6]:=true; { down+right }
joystick8dirstate[1,1]:=false;
joystick8dirstate[1,3]:=false;
end;
if (joystickaxis[1,2]=true) and (joystickaxis[1,4]=true) and (joystickangle>=-90-45-joystick8dirtolangle) and (joystickangle<=-90-45+joystick8dirtolangle) then
begin
joystick8dirstate[1,7]:=true; { up+left }
joystick8dirstate[1,2]:=false;
joystick8dirstate[1,4]:=false;
end;
if (joystickaxis[1,1]=true) and (joystickaxis[1,4]=true) and (joystickangle>=-90+45-joystick8dirtolangle) and (joystickangle<=-90+45+joystick8dirtolangle) then
begin
joystick8dirstate[1,8]:=true; { down+left }
joystick8dirstate[1,1]:=false;
joystick8dirstate[1,4]:=false;
end;
{ joystick8dirstate:array[1..2,1..8] of boolean; left/right joystick, down/up/right/left/up+right/down+right/up+left/down+left }
end;
end;
end;
end;
Поэтому я перекодировал это, чтобы персонаж двигался всякий раз, когда значение джойстика находится за пределами мертвой зоны, используя только: if sdlevent ^ .jaxis.value <-joystickdeadzone затем joystickaxis [1,2]: =правда;{вверх} если sdlevent ^ .jaxis.value> зона джойстика, то джойстик ось [1,1]: = true;{down}
То, что я пытался сделать раньше, это имитировать движение в 8 направлениях с помощью палки.Я сделал это, потому что, когда персонаж движется вправо, например, слегка сдвинув палку вверх или вниз, он тоже будет двигаться в этом направлении.Я хотел избавиться от того, насколько чувствительным это было.Но по какой-то причине события перестают опрашиваться.