2015-12-23 64 views
-1

为什么只有第一个动画在我的程序中运行良好?图像应该从左向右移动,然后从右向左移动。这只是从左到右发生的。红宝石鞋动画

Shoes.app do 

    @im = image("D:/image.jpg", left: 0, top: 220, width: 180, height: 230) 

    @an = animate 20 do 
    if @im.left < ([email protected]) 
     @im.left += 5 
    else 
     @an.stop 
    end 
    end 

    @an2 = animate 20 do 
    if @im.left <= ([email protected]) and @im.left > 0 
     @im.left -= 5 
    else 
     @an2.stop 
    end 
    end 

end 

回答

0

看起来你并不需要两个animation对象,但单动画对象的工作动画过程中向前和向后移动。

这是一个工作应用程序,它从左到右和从右到左进行动画,以指定变量@iterations定义的迭代次数。

运行之前,不要忘记更新图像路径(目前,a.jpg

Shoes.app do 

    @im = image("a.jpg", left: 0, top: 220, width: 180, height: 230) 

    @direction = :forward 
    @iteration = 5 

    @an = animate 64 do 
    if (@im.left < ([email protected])) && @direction == :forward 
     @im.left += 5 
    elsif @direction == :forward 
     @direction = :backward 
    end 

    if @im.left > 0 && @direction == :backward 
     @im.left -= 5 
    elsif @direction == :backward 
     @direction = :forward 
     @iteration -= 1 
    end 

    @an.stop if @iteration == 0 
    end 
end