box2d

Best way to deal with object that can't instantiate itself?

99封情书 提交于 2019-12-07 20:46:47
问题 I guess I've asked a few similar questions before, but I was beating around the bush. I think this is the real problem that I can't quite lay to rest. I'm dealing with a third party library, and there's an object that can't create itself, b2Body . The b2World has to instantiate it. I personally don't like this design pattern very much; I think the b2Body should be able to exist independently of the world, and then be added to the world when needed. Anyway, I've wrapped b2Body with my own

SKPhysicsBody with restitution 0 still bounces

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 17:35:25
问题 I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed

libgdx liquidfun integration runtime error

一曲冷凌霜 提交于 2019-12-07 16:50:20
问题 I'm new to this. I generated a new project using libgdx project generator, all worked fine. Then I tried to add liquidfun extension to the library using the following tutorial: https://github.com/finnstr/gdx-liquidfun-extension/wiki/Setup. It compiles all the dependencies are seen in the editor but at runtime I get this error. java.lang.NoClassDefFoundError: Failed resolution of: Lcom/badlogic/gdx/physics/box2d/World; 10-09 10:29:50.698 12790-12895/com.mygdx.game.android E/AndroidRuntime: at

Making a Box2d object follow a predetermined path

一曲冷凌霜 提交于 2019-12-07 09:38:27
问题 I'm making a game in which a certain object (modelled as a box2d body) has to follow a fixed path. Is there a way by which I can specify the path coordinates and make the object advance over it for each dt? Thanks 回答1: Another option: Attach a mouse joint to your body Use setTarget method of the mouse joint to move the body 回答2: You should use a Kinematic body, but you can't change its position manually, you have to change its speed for the dynamics and collisions to be applied correctly. I

Libgdx | Scene2d | Set background color of table?

风流意气都作罢 提交于 2019-12-07 05:19:32
问题 I am creating a menu (like the one is flappy bird, when you die it pops up over the play screen). I created a class that extends table, and I want to set the background of the table to white. Is there a way to do this? 回答1: I see that the problem has already been solved, but there are others asking to see the code and I can't comment yet. Here's an implementation of a similar solution, with the exception that a class will be made available for instantiation (so that the Table background color

Xcode C++ and Objective-C refactoring

假如想象 提交于 2019-12-07 00:40:45
问题 Is there a way to refactor mixed C++/Objective-C code in Xcode ?? I am writing a game using Cocos2D and Box2D, and the Box2D is written on C++, so every class I write should have .mm extension and therefore when I try to e.g. rename the variable, I got a message like " Xcode can only refactor C and Objective-C code ". Thanks in advance! 回答1: Xcode is VERY limited with refactoring, even with plain Obj-C. It's basically renaming and it can't even rename in comments. If it says it can't do

Deleting and creating body in libGDX

前提是你 提交于 2019-12-06 23:41:05
I have a problem with deleting/creating bodies in libGDX (box2d). I get a fatal error. Log: http://pastebin.com/fXWXpe8N I try to destroy bodies after collision. ~90% bodies are deleted good, without errors and crashes. But sometimes it happens. How can I fix this error? I have no idea. Contact: private void bulletGround(Contact contact) { Body bodyA = null; Body bodyB = null; if(contact.getFixtureA() != null && contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals(Ground.USERDATA)) bodyA = contact.getFixtureA().getBody(); if(contact.getFixtureB() != null &&

Cocos2d + Box2d - how to debug/show bodies?

微笑、不失礼 提交于 2019-12-06 15:49:45
问题 I've created a pretty simple setup using Cocos2d (2.0) and Box2d that comes packaged with it. I have a few bodies in my world, but don't have sprites linked up with them yet and I want to debug their orientations, positions, etc. This seems like a pretty standard task, but I could not find out how to do this easily. From my research it seems related to these methods: _world->SetDebugDraw(...); _world->DrawDebugData(...); // and the GLES-Render class Help? 回答1: I figured it out in case anyone

how do I drag an object in libgdx using box2d?

我们两清 提交于 2019-12-06 13:38:06
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! 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=ba02aaf34a8ca07daa0c30493bab993067c652f9 If you want to use a kinematic body you would do this: in render():

Box2D - b2body GetUserData always returns null

你。 提交于 2019-12-06 11:14:34
I am trying to adjust the position and rotation of a sprite based on that of a b2body in box2d. After I have created the body im setting the userData property to that of my body object that holds the sprite and position etc. The problem is that in the tick method b->GetUserData never retrieves the object I put in there. Can you see anything wrong with the following? Here is my add player method: -(void) addPlayerShip { CCSpriteSheet *sheet = [CCSpriteSheet spriteSheetWithFile:@"PlayerShip.png" capacity:1]; //Get sprite sheet CCSprite *sprite = [CCSprite spriteWithSpriteSheet:sheet rect