• <legend id='X2sEA'><style id='X2sEA'><dir id='X2sEA'><q id='X2sEA'></q></dir></style></legend>

        <small id='X2sEA'></small><noframes id='X2sEA'>

        <i id='X2sEA'><tr id='X2sEA'><dt id='X2sEA'><q id='X2sEA'><span id='X2sEA'><b id='X2sEA'><form id='X2sEA'><ins id='X2sEA'></ins><ul id='X2sEA'></ul><sub id='X2sEA'></sub></form><legend id='X2sEA'></legend><bdo id='X2sEA'><pre id='X2sEA'><center id='X2sEA'></center></pre></bdo></b><th id='X2sEA'></th></span></q></dt></tr></i><div id='X2sEA'><tfoot id='X2sEA'></tfoot><dl id='X2sEA'><fieldset id='X2sEA'></fieldset></dl></div>

      1. <tfoot id='X2sEA'></tfoot>

          <bdo id='X2sEA'></bdo><ul id='X2sEA'></ul>
      2. libgdx 在受伤时改变精灵颜色

        时间:2023-05-20
        <i id='Xxqj5'><tr id='Xxqj5'><dt id='Xxqj5'><q id='Xxqj5'><span id='Xxqj5'><b id='Xxqj5'><form id='Xxqj5'><ins id='Xxqj5'></ins><ul id='Xxqj5'></ul><sub id='Xxqj5'></sub></form><legend id='Xxqj5'></legend><bdo id='Xxqj5'><pre id='Xxqj5'><center id='Xxqj5'></center></pre></bdo></b><th id='Xxqj5'></th></span></q></dt></tr></i><div id='Xxqj5'><tfoot id='Xxqj5'></tfoot><dl id='Xxqj5'><fieldset id='Xxqj5'></fieldset></dl></div>

          <bdo id='Xxqj5'></bdo><ul id='Xxqj5'></ul>

              <small id='Xxqj5'></small><noframes id='Xxqj5'>

                <legend id='Xxqj5'><style id='Xxqj5'><dir id='Xxqj5'><q id='Xxqj5'></q></dir></style></legend>
              1. <tfoot id='Xxqj5'></tfoot>
                    <tbody id='Xxqj5'></tbody>
                1. 本文介绍了libgdx 在受伤时改变精灵颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 libgdx 制作一个小平台游戏,我想让敌人在玩家用武器伤害敌人时闪烁红色.

                  I am using libgdx to make a little platformer and I would like to make the enemies blink in red while the player hurt them with his weapon.

                  我已经尝试更改精灵颜色和精灵批次颜色但没有成功,它只会将新颜色与纹理之一融合.

                  I already tried to change the sprite color and the sprite batch color with no success, it only melt the new color with the one of the texture.

                  sprite.setColor(Color.RED);
                  spriteBatch.draw(sprite);
                  

                  我想要达到的效果是:

                  从精灵纹理变为全红色,然后再返回.我认为这与混合功能有关,但我不确定.我想避免为我的游戏中的每个怪物制作一些红色精灵.有人知道如何实现这种效果吗?

                  going from sprite texture to full red and then back again. I think there is something to do with the Blending function, but I am not sure about that. I want to avoid making some red sprite for each monsters of my game. Does someone know how to achieve this effect?

                  推荐答案

                  你可以像这样创建一个着色器来改变所有像素的颜色,而不是把它们乘以那个颜色.通过调用 spriteBatch.setShader(shader); 将此着色器与 SpriteBatch 一起使用.

                  You can create a shader like this to change the color of all pixels instead of multiplying them by that color. Use this shader with SpriteBatch by calling spriteBatch.setShader(shader);.

                  这基本上是默认的 SpriteBatch 着色器,除了最终颜色替换所有非 alpha 像素.

                  This is basically the default SpriteBatch shader, except the final color replaces all non-alpha pixels.

                  要使用此方法,您必须将彩色精灵与普通精灵分开批处理.调用 spriteBatch.setShader(null); 返回绘制常规精灵.

                  To use this method, you must batch your colored sprites separately from your normal sprites. Call spriteBatch.setShader(null); to go back to drawing regular sprites.

                  String vertexShader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";
                  " //
                              + "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";
                  " //
                              + "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;
                  " //
                              + "uniform mat4 u_projTrans;
                  " //
                              + "varying vec4 v_color;
                  " //
                              + "varying vec2 v_texCoords;
                  " //
                              + "
                  " //
                              + "void main()
                  " //
                              + "{
                  " //
                              + "   v_color = " + ShaderProgram.COLOR_ATTRIBUTE + ";
                  " //
                              + "   v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;
                  " //
                              + "   gl_Position =  u_projTrans * " + ShaderProgram.POSITION_ATTRIBUTE + ";
                  " //
                              + "}
                  ";
                          String fragmentShader = "#ifdef GL_ES
                  " //
                              + "#define LOWP lowp
                  " //
                              + "precision mediump float;
                  " //
                              + "#else
                  " //
                              + "#define LOWP 
                  " //
                              + "#endif
                  " //
                              + "varying LOWP vec4 v_color;
                  " //
                              + "varying vec2 v_texCoords;
                  " //
                              + "uniform sampler2D u_texture;
                  " //
                              + "void main()
                  "//
                              + "{
                  " //
                              + "  gl_FragColor = v_color * texture2D(u_texture, v_texCoords).a;
                  " //
                              + "}";
                  
                          ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
                  

                  这篇关于libgdx 在受伤时改变精灵颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将多个精灵旋转为一个(围绕同一原点) 下一篇:Box2d libgdx,对像素到米的东西有点困惑

                  相关文章

                  最新文章

                    <legend id='PiKNX'><style id='PiKNX'><dir id='PiKNX'><q id='PiKNX'></q></dir></style></legend>

                  1. <i id='PiKNX'><tr id='PiKNX'><dt id='PiKNX'><q id='PiKNX'><span id='PiKNX'><b id='PiKNX'><form id='PiKNX'><ins id='PiKNX'></ins><ul id='PiKNX'></ul><sub id='PiKNX'></sub></form><legend id='PiKNX'></legend><bdo id='PiKNX'><pre id='PiKNX'><center id='PiKNX'></center></pre></bdo></b><th id='PiKNX'></th></span></q></dt></tr></i><div id='PiKNX'><tfoot id='PiKNX'></tfoot><dl id='PiKNX'><fieldset id='PiKNX'></fieldset></dl></div>

                      • <bdo id='PiKNX'></bdo><ul id='PiKNX'></ul>

                      <small id='PiKNX'></small><noframes id='PiKNX'>

                      <tfoot id='PiKNX'></tfoot>