2017-10-20 124 views
0

我正在做一個Tap遊戲的原型。
當玩家破壞怪物時,我會處理動畫。如何反覆更改ImageView的色調?

怪物只是一個ImageView的,我用這行來的ImageView色調更改爲紅色(在color.xml定義)

imageView.setColorFilter(this.getResources().getColor(R.color.damage)); 

我的目標是讓ImageView的「閃爍」在原始ImageView和帶有紅色色調的ImageView之間。
但我不知道如何反覆做這件事。

你能幫我嗎? (我希望我自己清楚 - 我是法國人,我的英語不是很好)

回答

0

最簡單的:

public void blinkLimited(long started, long duration) { 
    if(duration > System.currentTimeInMillis() - started) return; 
    imageView.setColorFilter(this.getResources().getColor(R.color.damage)); 
    imageView.postDelayed(new Runnable(){ public void run() { 
    imageView.setColorFilter(this.getResources().getColor(R.color.atention)); 
       imageView.postDelayed(new Runnable(){ public void run() { 
        blinkLimited(started, duration); 
       }, 200); 
    }, 200); 
    } 

執行blinkLimited(System.currentTimeInMillis(),2000),您會注意到。

+0

你好,首先感謝你的回答,它的工作! 但uuuh如何我可以讓它停止,如果我想讓動畫在最後2秒內完成?像你說的永遠^^' –

+0

檢查答案,2000年在毫秒等於兩秒,如果答案幫助upvote,如果它解決請接受爲正確 –

+0

謝謝你的男人!有一個愉快的一天/晚上:D –