It looks like you're new here. If you want to get involved, click one of these buttons!
I am trying to make the stick figure go in the direction that is the difference from where I fist touched and where my finger is moving now
This is what I have, any help would be appreciated
-- Stick
-- Use this function to perform your initial setup
function setup()
angH = 0
time = 0
motion = "standing"
stickx = 100
sticky = 100
speed = 0
end
function touched(touch)
if touch.state == BEGAN then
startx = touch.x
starty = touch.y
elseif touch.state == MOVING then
angH=angH-(touch.deltaX)%360
speed=(touch.y-starty)/250
if speed > 1 then
speed = 1
elseif speed < -1 then
speed = -1
end
elseif touch.state == ENDED then
speed= 0
end
end
-- This function gets called once every frame
function draw()
background(255, 255, 255, 255)
time = time + 1
-- This sets the line thickness
strokeWidth(5)
x=speed*math.sin(math.rad(angH))
y=speed*math.cos(math.rad(angH))
if time > 30 then
if motion == "standing" then
motion = "walking"
else
motion = "standing"
end
time=0
end
stickx = stickx + x
sticky = sticky + y
if motion == "standing" then
sprite("Documents:stand",stickx,sticky,40,100)
else
sprite("Documents:walk",stickx,sticky,40,100)
end
-- Do your drawing here
end
Comments
If all you want is the stick figure to go towards your finger, this will work. Just a suggestion. If you use sprites other than those that come with Codea, other users can’t see or use them. We can’t see your Documents walk or stand sprites. For me, I just see a black rectangle. If you’re going to post code with sprites, replace your sprites with some close Codea sprites just so we see something.
How would you make it with a joystick?
Here’s something I had.
This is exactly what I wanted thanks