2016-09-23 31 views
1

改變顏色,我需要改變我的粒子效果顏色的顏色根據我的遊戲,一些用戶事件,這是我在做什麼:粒子效果在運行時

float temp[] = new float[4]; 
temp[0] = 0.937f; 
temp[1] = 0.325f; 
temp[2] = 0.314f; 
pe.getEmitters().first().getTint().setColors(temp); 
pe.start(); 

和渲染我這樣做:

pe.draw(batch, Gdx.graphics.getDeltaTime()); 

但不幸的是我收到此錯誤:

java.lang.ArrayIndexOutOfBoundsException: length=4; index=4 
at com.badlogic.gdx.graphics.g2d.ParticleEmitter$GradientColorValue.getColor(ParticleEmitter.java:1313) 
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.activateParticle(ParticleEmitter.java:439) 
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.addParticle(ParticleEmitter.java:154) 
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.draw(ParticleEmitter.java:299) 
at com.badlogic.gdx.graphics.g2d.ParticleEffect.draw(ParticleEffect.java:74) 
at com.approduction.game.GameScreen.render(GameScreen.java:218) 
at com.badlogic.gdx.Game.render(Game.java:46) 
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459) 
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557) 
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263) 

我不知道我做錯了,我閱讀文檔,並根據它做了一切任何幫助將是救世主...在此先感謝..

回答

0

你的float數組長度有誤。您實際上不需要創建新的數組。你可以完全避免這個問題通過填充你的顏色到它已經有這樣的陣列:

float temp[] = pe.getEmitters().first().getTint().getColors(); 
temp[0] = 0.937f; 
temp[1] = 0.325f; 
temp[2] = 0.314f; 
pe.start(); 
+0

Thanks..it working .. :) – Ashwani