libGdx如何将图像或演员用作身体

编程入门 行业动态 更新时间:2024-10-27 03:37:25
本文介绍了libGdx如何将图像或演员用作身体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我浏览了libGdx Wiki/教程,但没有找到使用图像或演员作为物理物体的示例. 在我的游戏中,我正在舞台上添加一名演员. 但是我想将此演员或精灵图像添加为物理物体.

I gone through the libGdx wiki/tutorial but I didn't find example to use an image or an actor as a physics body. In my game I am adding an actor to the stage. But I want to add this actor or sprite image as physics body.

我不得不拖动这个演员,甚至想检测与其他物体的碰撞.

I have to drag this actor and even want to detect collision with other bodies.

请给我参考.

谢谢

推荐答案

这有点棘手.您不会将图像或Actor用作物理物体.

This is a bit tricky. You don't use an image or an Actor as a physics body.

您将需要实现类似于扩展Actor的新"PhysicsActor"之类的东西.这个物理演员将拥有一个身体作为属性,并将成为您的libgdx场景和box2d世界之间的桥梁.

You will need to implement something like a new "PhysicsActor" which extends Actor. This Physics actor will have a body as a property and will be the bridge between your libgdx scene and the box2d world.

Actor将根据身体的位置更新其位置(请注意仪表到像素的转换). Actor会像单击鼠标一样收到输入,并需要创建一个(Mouse-)Joint来拖动Body并跟随鼠标.

The Actor will update it's position based on the body's position (be careful with the meter to pixel conversion). The Actor will receive the input like a click on it and needs to create a (Mouse-)Joint for the Body to be dragged and follow the mouse.

如何处理附着在人体上的图像的渲染也是自定义的.您可以手动给每个PhysicsEntity一个Sprite,该Sprite将通过绘画调用进行渲染.或者,您将使用编辑器(例如,RUBE,libgdx论坛的贡献"部分中还有一个rube-loader),该编辑器可让您将图像附加到主体上,并从编辑器中读取这些图像.

How you handle the rendering of images attached to the body is also custom. You might give each PhysicsEntity manually a Sprite which will be rendered by the draw-call. Or you will use an editor (RUBE for example, there is also a rube-loader in the Contributions-section of the libgdx forum) which will let you attach images to the bodies and you will read those from the editor.

您还可以检查此链接 www. netthreads.co.uk/2012/04/23/libgdx-box2d-scene2d-bumpers-demo/我想这正是您所需要的,但似乎实现起来有些不同.他使用某种Layer架构来桥接libgdx场景和box2d世界.

You might also check this link wwwthreads.co.uk/2012/04/23/libgdx-box2d-scene2d-bumpers-demo/ I guess it's exactly what you need, but it seems to be implemented a little bit different. He used some kind of Layer architecture to bridge the libgdx scene and the box2d world.

更多推荐

libGdx如何将图像或演员用作身体

本文发布于:2023-11-25 03:51:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   图像   演员   身体   libGdx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!