android – 使用libgdx旋转TextButton

android – 使用libgdx旋转TextButton,第1张

概述我有一个textButton,我想将它放在旋转90度的屏幕上. 由于某些原因,与TextButton对象相关的所有旋转方法(rotate(),setRotationAngle()等)都无法正常工作. 所以我实现了扩展TextButton和覆盖draw()方法的新类: @Overridepublic void draw(SpriteBatch batch, float parentAlpha) { @H_404_1@ 我有一个textbutton,我想将它放在旋转90度的屏幕上.

由于某些原因,与Textbutton对象相关的所有旋转方法(rotate(),setRotationAngle()等)都无法正常工作.

所以我实现了扩展Textbutton和覆盖draw()方法的新类:

@OverrIDepublic voID draw(SpriteBatch batch,float parentAlpha) {     Matrix4 rotationMatrix = new Matrix4();     Matrix4 oldMatrix = batch.gettransformMatrix();     rotationMatrix.IDt();     rotationMatrix.rotate(new Vector3(this.getX(),this.getY()+this.getHeight(),0),rotationAngle);     batch.settransformMatrix(rotationMatrix);     super.draw(batch,parentAlpha);     batch.settransformMatrix(oldMatrix);}

其中rotationAngle等于90.0.由于某种原因,按钮不会旋转90度,但是对于某些未知的度数.

UPD

我切换回Textbutton对象并做了:

newGame.settransform(true);newGame.rotate(90);

它几乎起作用意味着按钮中的文本被正确旋转,但按钮的背景仍保留在它的位置:

所以我的问题是:为什么会发生这种情况,我该如何解决这个问题呢?

解决方法 我根据 documentation实现了旋转小部件

这是我的代码:

table buttonContainer = new table(skin);buttonContainer.settransform(true);buttonContainer.add(button1);buttonContainer.row().pad(10);buttonContainer.add(button2);rotatingActor = buttonContainer;

然后:

rotatingActor.setRotation(newDegree);

即使小部件被旋转,所有点击处理程序等也按预期工作.

总结

以上是内存溢出为你收集整理的android – 使用libgdx旋转TextButton全部内容,希望文章能够帮你解决android – 使用libgdx旋转TextButton所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1129921.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存