PDA

View Full Version : Problem with analog stick



my psprecious
February 19th, 2006, 00:43
ok been looking around for info on analog stick and there's not much out there

here's my problem

I have an image with a big thick red line and a dot I am moving around with the analog stick, I use the pixel detection for this and tell it if you touch red pixel stop.

so far it works, but what I really want, and that I just can't figure out, is I want my dot not to stop but just be block from passage in the red zone.


red = Color.new(255, 0, 0)

dot = Image.load("DATA/dot.png")
bgC = Image.load("DATA/bg col2.png")

x0 = 0 ; y0 = 0 ; x1 = 0 ; y1 = 0
while true do

screen:clear()
pad = Controls.read()

dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x0 + dx / 64
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y0 + dy / 64
end

if bgC:pixel (x1, y1) == red then

x1 = x1 ; y1 = y1 else
x1 = x0 ; y1 = y0

end

screen:blit(0, 0, bgC)
screen:blit(x1, y1, dot)
screen.waitVblankStart()
screen.flip()

if pad:start() then break end

end

so if someone could help it be appreciate

rowanmcau
March 30th, 2006, 06:53
analogPad = Controls.read()
dx = analogPad:analogX()
dy = analogPad:analogY()





-- Analog up, down, right & left

if (dx > -45 and dx < 44 and dy == -128) then
sound3:play()
end
if (dx > -45 and dx < 44 and dy == 127) then
sound4:play()
end
if dy > -45 and dy < 44 and dx == 127 then
sound3:play()
end
if dy > -45 and dy < 44 and dx == -128 then
sound4:play()
end
this is the code i use for my app