Howdy, Stranger!

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

Tween is acting weird

edited September 2013 in Questions Posts: 577

Hi! For some reason, my tween works fine when I use tween.stopAll(), but when I use the tween.stop( name), it acts stacitly, bouning around the scene, not going towards my finger, etc. Any suggestions how to fix this?


function setup() heroes = {vec2(30, 50), vec2(30, 150)} end function draw() sprite("hero", v[1].x, v[1].y) sprite("hero", v[2].x, v[2].y) controlling = v[1] end function touched(t) if controlling ~= nil then tween.stop(moving) moving = tween(4, controlling, {t.x, t.y}) end end

Comments

  • BriarfoxBriarfox Mod
    Posts: 1,542
    function setup()
    
    v = {vec2(30, 50), vec2(30, 150)}
    controlling = v[1]
    end
    
    function draw()
        background(255, 255, 255, 255)
    
    sprite("Planet Cute:Character Boy", v[1].x, v[1].y)
    sprite("Planet Cute:Character Cat Girl", v[2].x, v[2].y)
    
    
    end
    
    function touched(t)
    if t.state == ENDED then
    if moving ~= nil then
    tween.stop(moving)
    moving=nil
    else
     moving = tween(4, controlling, {x=t.x,y= t.y})
    end
    
    
    end
    
    end
    
  • Posts: 577

    Oh I see now, I have to tell the app what t.x and t.y is, correct?

    The only thing I don't understand is the "moving=nil" part, could someone explain? :)

  • BriarfoxBriarfox Mod
    edited September 2013 Posts: 1,542

    You also need to add the touch state in. When you touch it was firing off on start, moving and end.

    function touched(t)
    --stop the tween when you lift up your finger
       if t.state == ENDED then
          --If moving exists stop the tween
          if moving ~= nil then
             tween.stop(moving)
             --Make tween nil (doesnt exist) so you can tween again
             moving = nil
    
          else
              --to tween here
          end
    
       end
    
    end
    
Sign In or Register to comment.