It looks like you're new here. If you want to get involved, click one of these buttons!
Hey guys, so I have a ball and a direction set up depending on where you touch the screen but I don't know how to set up the direction with the object on the screen. Here's the code:
-- Lines1
displayMode(FULLSCREEN)
-- Use this function to perform your initial setup
function setup()
held=false
directionx=0
directiony=0
speedx=WIDTH/2
speedy=HEIGHT/2
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(95, 112, 115, 255)
fill(255, 255, 255, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
ellipse(ballx,bally,40)
if held == true then
line(ballx,bally,CurrentTouch.x,CurrentTouch.y)
end
end
function touched(touch)
if touch.state == BEGAN then
held=true
direction=vec2(touch.prevX,touch.prevY)
end
if touch.state == ENDED then
held=false
directionx=touch.prevX
directiony=touch.prevY
end
end
Any help is much appreciated!
Comments
I suggest you separate speed and direction, then you can calculate the direction from your current position to the touch like this
and here is your amended program. If anything isn't clear,ask.
Thanks @Ignatz!