Howdy, Stranger!

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

How do you tilt your ipad to move a sprite

edited May 2013 in Code Sharing Posts: 23

pleas help



  • edited May 2013 Posts: 1,595
    function setup()
     img = sprite(yourimage,400,400)
     pos = vec2(400,400)
    function draw()
     pos = pos + vec2(Gravity.x,Gravity.y)
     img.x = pos.x
     img.y = pos.y

    I think that will work im not sure I havent tried it.

  • dave1707dave1707 Mod
    edited May 2013 Posts: 8,739

    Here's an example.

    displayMode(FULLSCREEN) supportedOrientations(PORTRAIT) function setup()     x=WIDTH/2     y=HEIGHT/2 end function draw()     background(40,40,50)     x=x+Gravity.x*10     y=y+Gravity.y*10     sprite("Planet Cute:Character Pink Girl",x,y) end
  • Posts: 2

    Use Gravity

  • edited May 2013 Posts: 2

    I'm still working on this, but it includes Gravity, so try use this example:

    -- Rockets
    -- Use this function to perform your initial setup
    function setup()
        default = 500
        rangemax = 700
        rangemin = 0
    -- Settings
        x = -1
        speed = 20
    -- Double check for position of x
        if x >= rangemin then
            print("In range")
        elseif x < rangemin then
            print("Not in range")
            x = default
    -- Parameters"x")
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        -- Do your drawing here
        sprite("Cargo Bot:Background Fade",374,374)
        sprite("Space Art:Red Ship",x,100)
        x = x + Gravity.x * speed
Sign In or Register to comment.