Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Rotating a Sprites Angle

edited November 14 in Questions Posts: 9

Hi, was attempting to be able to turn the angle of this sprite hoping it will turn according to my touch. For example, if I were to touch 200, 200, it would point that way. If dragging finger it would follow. Started this code but won’t seem to work. Any ideas?

-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)   
end

-- This function gets called once every frame
function draw()
  -- This sets a dark background color 
    background(255, 255, 255, 255)

    -- This sets the line thickness
    strokeWidth(5)
A=WIDTH
b=HEIGHT -- Do your drawing here



sprite("Tyrian Remastered:Boss D", 100, HEIGHT*1/2, 100, 100)
              function touched(touch)
    if touch.state ~= MOVING then rotate=(CurrentTouch.y-HEIGHT*1/2, CurrentTouch.x -100)

end
        end
end

Comments

  • dave1707dave1707 Mod
    Posts: 6,325

    @NG_2000 Welcome to the forum. I changed your code a little to do what you want.

    displayMode(FULLSCREEN)   
    
    function setup()
        x,y=WIDTH/2,HEIGHT/2
        ang=0
    end
    
    function draw()
        background(255)
        translate(x,y)
        rotate(ang-90)
        sprite("Tyrian Remastered:Boss D", 0,0,100,100)
    end
    
    function touched(touch)
        if touch.state==BEGAN or touch.state==MOVING then
            ang=math.deg(math.atan(touch.y-y,touch.x-x))    
        end
    end
    
  • Posts: 9

    Wow that was fast. Thanks so much.

Sign In or Register to comment.