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

编程入门 行业动态 更新时间:2024-10-28 01:14:16
本文介绍了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.

您也可以查看此链接 wwwthreads.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:48:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628196.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   图像   演员   身体   libGdx

发布评论

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

>www.elefans.com

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