box2d

基于HTML5的WebGL结合Box2DJS物理引擎应用

坚强是说给别人听的谎言 提交于 2019-12-23 13:51:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 上篇 我们基于 HT for Web 呈现了 A* Search Algorithm 的3D寻路效果,这篇我们将采用 HT for Web 3D 来呈现Box2DJS物理引擎的碰撞效果,同上篇其实Box2DJS只是二维的平面碰撞物理引擎,但同样通过3D的呈现能让人更直观的体验到碰撞效果,最终例子效果: http://hightopo.com/demo/box2djs/ht-box2d-demo.html Box2D最早是Erin Catto在 GDC 大会上的一个展示例子,后来不断完善成C++的开源物理引擎库,这些年了衍生出Java、ActionScript以及JS等版本,被广泛应用在游戏领域。说其丰富的确很丰富,说乱也够乱的,找个Box2D的JS版就有N多选择,而且不同版本API还有差异,可参考这里的对比 http://stackoverflow.com/questions/7628078/which-box2d-javascript-library-should-i-use 虽然版本较多有点乱,但各个版本的基本原理和API都类似,以下为我基于Box2DJS融合 HT for Web 写的例子代码。Box2D有很多参数功能点,这里例子我们仅呈现最基础简单的要素,主要让大家理解Box2DJS引擎的基本使用

How to set centers of shapes/fixtures/bodies in Box2D

我与影子孤独终老i 提交于 2019-12-23 08:34:07
问题 Hey i'm trying to integrate SFML and Box2D, and SFML has made setting centers for sprites, shapes, etc. very easy. Box2D, on the other hand, I'm having trouble with as i can't figure out how to set or even find the center of a shape or fixture. It seems to me that when adding vertices manually to a b2_PolygonShape the center is set to the first vertex in the vertex array, but the results are very different when using the shortcut functions SetAsBox() or any other SetAs_ _ (). The Center is

Change Box2D Anchor Point?

拟墨画扇 提交于 2019-12-23 03:50:19
问题 In Cocos2D I am creating my CCSprites with anchor points of (0,1) which is similar to the way UIKit does it. Anyway, I am trying to change the anchor point in Box2D, is this possible? If so how would I do it with an anchor point of (0,1)? Thanks! 回答1: Box2D bodies don't have an anchor point. The anchorPoint is an offset of a node's texture relative to the node's position. Box2D bodies don't have a texture, hence no anchor point. Generally speaking you're going to make a lot of things more

Disable collision completely of a body in AndEngine Box2D

牧云@^-^@ 提交于 2019-12-23 03:19:15
问题 I am working on a Bubble Shooter type game where I want a body not to collide with any thing else when its burst or falling down. I cant use collision filtering because all the bodies on the scene are of same type. I want to disable the collision. I don't want to collide a body with any other body.Some one told me to set the isSensor flag to true but again I am not able to get the flag and set it. Please help. 回答1: Found the answer: for(int i=0; i<getBody().getFixtureList().size();i++){ this

Box2D - How can I know when 2 Fixtures are touching?

徘徊边缘 提交于 2019-12-23 01:29:13
问题 I'm just curious, in the case that I have a body that has 2 or more fixtures in it that are not "joined together", how can I determine this definitively in code? Here is an example of what I mean: I marked the vertices for each distinctive fixture just to make it completely clear that these are separate shapes which do not share vertices with each other. They are however combined into a single body. As you can see, two fixtures are within very close proximity to each other or "touching", and

Box2D: How to manually render a body

邮差的信 提交于 2019-12-22 18:32:38
问题 I succeed installing Box2D into my project. But how can I render a body? Assume I'm using something that supports drawing polygons. I just want to find out the current positions of the vertices of the body-polygon, to draw it with the engine. If you can help me, I will be very thankful. 回答1: I found it!!! void Box2DUtils::DrawBody(SDL_Surface *buffer, b2Body *body, int fr, int fg, int fb, int falpha, int lr, int lg, int lb, int lalpha, bool aa) { const b2Transform& xf = body->GetTransform();

Game crashes when I try to destroy a b2Body, what should I do?

我只是一个虾纸丫 提交于 2019-12-22 12:32:29
问题 "Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file libs/Box2D/Dynamics/b2Island.h, line 65." That is what it the crash leaves in the console. [self removeChild:(CCSprite*)body->GetUserData() cleanup:YES]; body->SetTransform(b2Vec2(30, 30), 0); //moving the body out of the scene so it doesnt collide anymore! world->DestroyBody(body); I think im doing the right stuff.. @property (nonatomic, assign) b2Body *body; Here is how i "make it" a property I dont understand why it

how do I drag an object in libgdx using box2d?

爱⌒轻易说出口 提交于 2019-12-22 12:05:19
问题 I have added objects to a box2d world in libgdx . I am wondering if it was possible to drag objects with the mouse? If so, how? thanks! 回答1: There are a couple of options here. You can use a mouse joint or you can use a kinematic body and set it's position manually. A good example of how to use a mouse joint check this out: http://code.google.com/p/libgdx-backend-android-livewallpaper/source/browse/gdx-backend-android-livewallpaper-example/src/com/badlogic/gdx/tests/box2d/Box2DTest.java?r

Collision Detection using Box2d(for Android)?

这一生的挚爱 提交于 2019-12-22 08:57:09
问题 Can someone explain the in what way works the collision detection using box2d for android. I cannot understand in what way works BBContactListener. BBContactListener listener = new BBContactListener(); world = new BBWorld(gravity, doSleep); world.SetContactListener(listener); How to use that listener? Should I extend standart to create my own or how? 回答1: I did not use box2d for android, but I think the idea is the same there. You have to implement contact processing methods. That's the way

How to apply constant force on a Box2D body?

冷暖自知 提交于 2019-12-22 08:33:44
问题 I am making a Box2d game for the iPhone. I need to apply a force on a body which represents my main character. The body is actually a rectangle on top of a circle connected using a revolute joint. I am using this as the skeleton for my character who is supposed to be running through the game(any suggestions or feedback on this too would be appreciated). I need a force to be applied continuously so that it keeps him moving. What would be the best way to do this? I am currently applying linear