1. <legend id='fb9P6'><style id='fb9P6'><dir id='fb9P6'><q id='fb9P6'></q></dir></style></legend>
      <bdo id='fb9P6'></bdo><ul id='fb9P6'></ul>

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

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

      无法循环操作.库GDX

      时间:2023-07-27

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

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

              <legend id='CdkdR'><style id='CdkdR'><dir id='CdkdR'><q id='CdkdR'></q></dir></style></legend>
                <tbody id='CdkdR'></tbody>

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

                本文介绍了无法循环操作.库GDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在 4 天前问过一个问题.得到了一些帮助,现在我的代码看起来像

                I've asked a question like 4 days ago. Got some help and now my code looks like

                ColorAction actionBtG = new ColorAction();
                ColorAction actionGtB = new ColorAction();
                SequenceAction sequenceAction;
                RepeatAction repeatAction = new RepeatAction();
                ShapeRenderer shapeRenderer;
                Color blue = new Color(Color.BLUE);
                
                @Override
                public void create () {
                
                    shapeRenderer = new ShapeRenderer();
                    actionBtG.setColor(blue);
                    actionBtG.setEndColor(Color.GOLD);
                    actionBtG.setDuration(5);
                
                    actionGtB.setColor(blue);
                    actionGtB.setEndColor(Color.BLUE);
                    actionGtB.setDuration(5);
                    sequenceAction = new sequenceAction(actionBtG,actionGtB);
                
                
                
                
                
                
                    repeatAction = new RepeatAction():        
                    repeatAction.setAction(sequenceAction);
                    repeatAction.setCount(RepeatAction.FOREVER);
                }
                
                @Override
                public void render () {
                
                    repeatAction.act(Gdx.graphics.getDeltaTime());
                    Gdx.gl.glClearColor(1,1,1,1);
                    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(blue);
                    shapeRenderer.rect(100, 100, 40, 40);
                    shapeRenderer.end();
                
                
                }
                

                但它仍然工作错误.它执行一次并停止.当我需要循环时.从蓝色到金色,然后从金色到蓝色.我真的很感激任何帮助,因为我只是在学习 libGDX.谢谢.

                But it still works wrong. It does action once and stops. When I need to loop that. From blue to gold, then from gold to blue. I would really appreciate any help, because I'm just learning libGDX. Thanks.

                我已阅读所有答案并编辑了我的代码,但它仍然不起作用:

                I have read all of the answers and edited my code, but it still doesnt work:

                private Actor actionManager = new Actor();
                ColorAction actionBtG = new ColorAction();
                ColorAction actionGtB = new ColorAction();
                SequenceAction sequenceAction;
                RepeatAction repeatAction;
                Color activeColor = new Color(Color.BLUE);
                ShapeRenderer shapeRenderer;
                
                
                @Override
                public void create () {
                
                    shapeRenderer = new ShapeRenderer();
                    actionBtG.setColor(activeColor);
                    actionBtG.setEndColor(Color.GOLD);
                    actionBtG.setDuration(5);
                
                    actionGtB.setColor(activeColor);
                    actionGtB.setEndColor(Color.BLUE);
                    actionGtB.setDuration(5);
                    sequenceAction = new SequenceAction(actionBtG,actionGtB);
                    repeatAction = new RepeatAction();
                    repeatAction.setAction(sequenceAction);
                    repeatAction.setCount(RepeatAction.FOREVER);
                
                    actionManager.addAction(repeatAction);
                }
                

                这里是渲染()

                @Override
                    public void render () {
                    Gdx.gl.glClearColor(1, 1, 1, 1);
                    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                    actionManager.act(Gdx.graphics.getDeltaTime());
                
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(blue);
                    shapeRenderer.rect(100, 100, 40, 40);
                    shapeRenderer.end();
                }
                

                现在它没有改变颜色,它总是蓝色的.

                Now it's not changing the color, it's always blue.

                推荐答案

                您遇到了与期望与 Actor 一起使用的操作相关的错误.很多 Action 在没有 Actor 的情况下也能正常工作,但 SequenceAction 却不行,因为它希望附加到 Actor 以检测它是否仍应运行.

                You're encountering a bug related to Actions expecting to be used with Actors. A lot of Actions work fine without an Actor, but SequenceAction does not because it expects to be attached to an Actor to detect if it should still be running.

                因此,一个有点老套的解决方案是在您设置它时向您的顶级操作添加一个虚拟演员.这模拟了当您向舞台中的演员添加动作时发生的情况.

                So a somewhat hacky solution would be to add a dummy actor to your top level action when you set it up. This simulates what happens when you add an action to an actor in a stage.

                repeatAction.setActor(new Actor());
                

                如果您计划在您的应用中使用更多操作,您可以创建一个 Actor 来管理您的所有操作:

                If you plan to use more Actions in your app, you can create a single Actor that you use to manage all your actions:

                private Actor actionManager = new Actor();
                
                //when creating actions:
                actionManager.addAction(repeatAction);
                
                //In render(), use this instead of calling act on individual actions
                //It will call act on all actions in the actor:
                actionManager.act(Gdx.graphics.getDeltaTime());
                

                当然,如果您想使用 Stage 来绘制东西,您可以简单地将您的动作添加到 Stage,而不是使用 Actor 作为您的动作管理器.

                And of course, if you want to use a Stage for drawing stuff, you could simply add your actions to the Stage instead of using an Actor as your action manager.

                我个人认为,scene2d 动作必须比 UniversalTweenEngine 更易于使用和设置.

                I personally find scene2d Actions must easier to use and set up than UniversalTweenEngine.

                这篇关于无法循环操作.库GDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 Android 设备上通过 libGDX Preferences 正确保存 下一篇:我的 Admob 广告没有绘图,但有吗?(LibGDX Admob 6.4

                相关文章

                最新文章

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

                    <tfoot id='pAumA'></tfoot>

                  1. <legend id='pAumA'><style id='pAumA'><dir id='pAumA'><q id='pAumA'></q></dir></style></legend>
                  2. <small id='pAumA'></small><noframes id='pAumA'>

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