Title: Snippet: Analog Input Post by: Access_Denied on June 14, 2007, 09:54:20 AM Another thing that plagued me when I started was how to use the analog stick. Well, here's a quick example.
Look at this picture: (http://img101.mytextgraphics.com/photolava/2007/06/14/analog-46tceupgz.png) The back cirle shows the value of the analog. From the top to the bottom is the Y values from -128 to 127. From left to right is the X values from -128 to 127. The red circle represents the ''dead area' or the area where the analog doesn't register. That area is from -50 to 50 both ways. So, that means the analog value must be greater than 50 or less than -50 to register. So look at this example: player = {x = 100, y = 100, img = image.createEmpty(32,32)} player.img:clear(Color.new(255,0,0)) function Analog() pad = Controls.read() angX = pad:analogX() angY = pad:analogY() if angX() > 50 then player.x = player.x + 5 else if angX() < -50 then player.x = player.x - 5 end if angY() > 50 then player.y = player.y + 50 else if angY < -50 then player.y = player.y - 50 end end while true do screen:clear() screen:blit(player.x,player.y,player.img) Analog() screen.waitVblankStart() screen.flip() end |