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

Tagged:

Comments

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

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

  • dave1707dave1707 Mod
    edited May 2013 Posts: 7,809

    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
        end
    
    -- Parameters
        parameter.watch("x")
        parameter.number("speed",20,40)
    
    end
    
    
    
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        background(0,0,0)
    
        -- Do your drawing here
    
        sprite("Cargo Bot:Background Fade",374,374)
        sprite("Space Art:Red Ship",x,100)
        x = x + Gravity.x * speed
    
    end
    
Sign In or Register to comment.