Howdy, Stranger!

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

Scrolling of sprite

Hi
I have a question on the touch. I would like to know how to make a scrolling of sprite with the touch, a little as a Web site. You can help me please?

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,470

    @goodboy2004 Here's about as simple as it gets moving a Sprite with the function touched.

    function setup()
        sx,sy=WIDTH/2,HEIGHT/2
    end
    
    function draw()
        background(40, 40, 50)
        sprite("Planet Cute:Character Boy",sx,sy)
    end
    
    function touched(t)
        if t.state==MOVING then
            sx=t.x
            sy=t.y
        end
    end
    
  • dave1707dave1707 Mod
    edited February 2017 Posts: 7,470

    @goodboy2004 Here's another version. Slide your finger right/left/up/down not on the Sprite to move it.

    function setup()
        dx,dy=0,0
        sx,sy=WIDTH/2,HEIGHT/2
    end
    
    function draw()
        background(40, 40, 50)
        sprite("Planet Cute:Character Boy",sx+dx,sy+dy)
    end
    
    function touched(t)
        if t.state==MOVING then
            dx=dx+t.deltaX
            dy=dy+t.deltaY
        end
    end
    
  • Thanks

Sign In or Register to comment.