2015-12-23 95 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