I got issues about love joystick module. It seems i have connected joystick on pc but button-push checks doesn't work. Can you guys try this code out for me? Joystick works on other stuff but love.
joysticks=love.joystick.getJoysticks();
joystick=joysticks[1];
player={
x=100,
y=100,
speed=200,
};
function joystickCalistir(dt)
if joystick:isGamepadDown("dpleft") then
player.x=player.x-player.speed*dt;
elseif joystick:isGamepadDown("dpright") then
player.x=player.x+player.speed*dt;
end
if joystick:isGamepadDown("dpup") then
player.y=player.y-player.speed*dt;
elseif joystick:isGamepadDown("dpdown") then
player.y=player.y-player.speed*dt;
end
end
function love.update(dt)
joystickCalistir(dt);
connected=joystick:isConnected();
end
function love.draw()
love.graphics.setBackgroundColor(255, 255, 255);
love.graphics.setColor(255, 40, 40);
if connected==true then
love.graphics.print("Connected.", 100, 10);
elseif connected==false then
love.graphics.print("Couldn't connected.", 100, 10);
end
love.graphics.print(joystick:getName(), 10, 10);
love.graphics.rectangle("fill", player.x, player.y, 32, 32);
end
Did you call Joystick:isGamepad to see if it's recognized as an xbox360-like (probably means xinput-compatible, but i'm not sure) gamepad? If that returns false, but Joystick:isConnected is true, then you might have to resort to using the non-gamepad functions (and/or callbacks) instead; or in other words, most functions on the Joystick page that don't have "gamepad" in their names.
Last edited by zorg on Thu Oct 12, 2017 8:01 am, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
joysticks=love.joystick.getJoysticks();
joystick=joysticks[1];
player={
x=100,
y=100,
speed=200,
};
function joystickCalistir(dt)
local horizontal=joystick:getAxis(2);
local vertical=joystick:getAxis(1);
if horizontal==1 then
player.y=player.y+player.speed*dt;
elseif horizontal==-1 then
player.y=player.y-player.speed*dt;
end
if vertical==1 then
player.x=player.x+player.speed*dt;
elseif vertical==-1 then
player.x=player.x-player.speed*dt;
end
end
function love.update(dt)
joystickCalistir(dt);
connected=joystick:isConnected();
end
function love.draw()
love.graphics.setBackgroundColor(255, 255, 255);
love.graphics.setColor(255, 40, 40);
if connected==true then
love.graphics.print("Connected.", 100, 10);
elseif connected==false then
love.graphics.print("Couldn't connected.", 100, 10);
end
if joystick:isVibrationSupported()==false then
love.graphics.print("Your joystick doesn't support vibration.", 200, 10);
end
--love.graphics.print(joystick:getGUID(), 10, 30);
love.graphics.print(joystick:getAxis(2), 10, 30);
love.graphics.print(joystick:getName(), 10, 10);
love.graphics.rectangle("fill", player.x, player.y, 32, 32);
end
Looks like it could work like that
Though if you decide to support analog stick movement (as in movement ranging from slow to fast) then you could remove the checks in your joystickCalistir function, and just multiply player.speed with them (assuming the axes' range is between -1 and 1).
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.