【问题标题】:Particle Effect Changing Color at runtime粒子效果在运行时改变颜色
【发布时间】:2016-09-23 12:55:22
【问题描述】:

我需要根据游戏中的某些用户事件更改粒子效果颜色的颜色,因为这就是我正在做的事情:

 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)

我不知道我做错了什么,我阅读了文档并按照它做了所有的事情任何帮助都会是一个救星......提前谢谢......

【问题讨论】:

    标签: libgdx game-engine


    【解决方案1】:

    您的浮点数组长度错误。

    您实际上不需要创建新数组。您可以通过将颜色填充到它已经拥有的数组中来完全避免这个问题:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多