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

查看:27
本文介绍了libGdx 如何使用图像或演员作为身体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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"之类的东西.这个 Physics actor 将拥有一个 body 作为属性,并将成为您的 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 会像点击它一样接收输入,并且需要为要拖动的 Body 创建一个 (Mouse-)Joint 并跟随鼠标.

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 将由 draw-call 渲染.或者您将使用一个编辑器(例如 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天全站免登陆