libGdx如何将图像或演员用作身体 [英] libGdx How to use images or actor as body

查看:132
本文介绍了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.

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

You might also check this link http://www.netthreads.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如何将图像或演员用作身体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆