How to detect diagonal on the directional pad..

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

How to detect diagonal on the directional pad..

Post by fattymc03 »

How can I detect the pressing of a diagonal on the directional pad. Like pressing up and right at the same time.
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Here for 'hardcoded':

Code: Select all

if pad:up() and pad:right() then
....
elseif pad:up() and pad:left() then
....
elseif pad:up() then
....
elseif pad:left() then
....
end
Make sure the diagonals are before the 'normal' ones.



You can prolly use this if you use it for some kind of value changes, like y=y+1 and x=x+1 etc.:

Code: Select all

if pad:up() then
....
end

if pad:right() then
....
end

if pad:left() then
....
end

Last edited by MikeHaggar on Sat Feb 11, 2006 7:36 am, edited 1 time in total.
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

thanks for the quick response i appreciate it. that works, but its not that fluid. its like it moves in the direction of the first detected button. you have to press them both at exactly the same time to get it to move correctly, but it is not that fluid. are there any other solutions?
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

opps, sorry about the above post. i didnt realize i had a return statement in the wrong place. it works correctly now. i was wondering if you could explain the buttonmasks and when is the correct time to use them. thanks again.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Suggest a timer to allow the user to press two buttons before testing them.
Geo Massar
Retired Engineer
CaseyB
Posts: 15
Joined: Mon Jan 23, 2006 7:28 am

Post by CaseyB »

If you do it the second way suggested by MikeHaggar, i.e.,
MikeHaggar wrote: You can prolly use this if you use it for some kind of value changes, like y=y+1 and x=x+1 etc.:

Code: Select all

if pad:up() then
....
end

if pad:right() then
....
end

if pad:left() then
....
end

It should work perfectly without having to introduce the complexity of a timer or worrying about what order to call the checks in.
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

mike haggars way worked fine.. thanks guys
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

fattymc03 wrote:i was wondering if you could explain the buttonmasks and when is the correct time to use them. thanks again.
hm... what do you mean?
Post Reply