在重力(Box2D/AndEngine)的作用下,如何使物体在屏幕周围反弹? [英] How do I get a body to bounce around the screen when there is gravity (Box2D/AndEngine)?

查看:101
本文介绍了在重力(Box2D/AndEngine)的作用下,如何使物体在屏幕周围反弹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了大量的搜索工作,并且发现了有关反重力物体的多种建议,但是似乎没有什么是正确的.我有一个用地球引力创造的物理世界.用户点击屏幕并创建子画面/动态实体.然后这些由于重力而落到屏幕的底部.我还有另一个精灵/物体,应该在屏幕周围反弹,忽略重力并弹回已创建的精灵. AndEngine的Box2D似乎没有setGravityScale(),所以我无法将引力设置为0.在运动物体上创建固定装置以确定哪一侧发生碰撞的问题是精灵是一个圆(这不算大)交易),但我不太了解它们是如何工作的.我看到我可能能够以等于body.getMass()* SensorManager.Earth的恒定力创建一个动态物体,并将其弹性设置为1,但是无法获得完美的弹性碰撞.任何人都有完美的建议吗?

I've done quite a bit of searching and have found multiple suggestions for anti-gravity objects, but nothing seems to work just right. I have a physics world created with Earth's gravity. The user taps the screen and creates sprites/dynamic bodies. These then fall to the bottom of the screen due to the gravity. I have another sprite/body that is supposed to bounce around the screen, ignoring gravity and bouncing off the sprites that have been created. AndEngine's Box2D does not seem to have setGravityScale() so I can't set gravity to 0. The problem with creating fixtures attached to a kinematic body to determine which side is colliding is that the sprite is a circle (which isn't a big deal) and I don't quite understand how they work. I saw that I might be able to create a dynamic body with a constant force equal to body.getMass()*SensorManager.Earth in the -y direction and set the elasticity to 1, but there is no way to get a perfectly elastic collision. Anyone have any perfect suggestions?

推荐答案

JohnEye是正确的,只是提供的信息不如我喜欢.在类似的问题中,我回答了这个问题:

JohnEye was correct, just not quite as informative as I liked. In a similar question, I answered this: How do I apply a force to a body in the direction it is traveling (Box2D)?

这篇关于在重力(Box2D/AndEngine)的作用下,如何使物体在屏幕周围反弹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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