Detailed explanation libgdx uses shapereader custom actor in Android to solve the problem that touch events cannot be received

Detailed explanation libgdx uses shapereader custom actor in Android to solve the problem that touch events cannot be received

Today, I realized an effect in the project, mainly drawing a circle. For the convenience of subsequent use, the circle is encapsulated in a custom actor (circleactot). When you want to display a circle later, just create a circleactor. Some codes are as follows:

Then create a stage object and add the circleactor object to the stage to display it. However, you cannot add a clicklistener listener to this circleactor object.

For example, the following code:

The click method in the above code can never be called! After adjusting for more than half a day, I finally figured out the reason: Although a circle is drawn to a certain position on the screen through shapereader.circle method in the draw method of circleactor, there is not much connection between shaperector and actor. The only connection is the following two sentences of code, which means that the shaperer's camera and actor objects should be consistent.

However, at this time, the circleactor does not set the real size and position. Therefore, to solve the above problems, you need to make the size and position of the circleactor consistent with the shaperer in the constructor!!

As shown in the following code, just add two lines of code:

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>