Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With your code, you seem to try to do collision checking with your sprites ?!</p> <p>It would be complicated and not nice when you try to do things without physics bodies. So lets use the physics bodies with your sprites. </p> <p>But note that, DO NOT create a solid box body for your area (containing your sprites), lets use 4 separated body walls (left, top, right, bottom) to form a closed box; because game engine can only check collision with solid shapes.</p> <p>The following is the code for reference:</p> <pre><code>/** * @param pScene * Sence of the game, get from class member * @param pWorld * physics world of the game, get from class member */ public void CreateSprites(final Scene pScene, final PhysicsWorld pWorld) { final FixtureDef mFixtureDef = PhysicsFactory.createFixtureDef(10, 1.1f, 0.0f);//should be placed as member of class final Sprite letterTwo = new Sprite(centerX - centerX / 2, centerY, this.mFaceTextureRegionLetterTwo, this.getVertexBufferObjectManager()); final Body letterTwoBody = PhysicsFactory.createBoxBody(pWorld, letterTwo, BodyType.DynamicBody, mFixtureDef); letterTwo.setUserData(letterTwoBody); // for later sprite-body attachment access pScene.attachChild(letterTwo); pWorld.registerPhysicsConnector(new PhysicsConnector(letterTwo, letterTwoBody, true, true)); } /** Create the walls, in these boudaries sprites will move */ public void InitBoxWalls(Scene pScene, PhysicsWorld pWorld) { final float WALL_MARGIN_WIDTH = 5f; final float WALL_MARGIN_HEIGHT = 10f; final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); mWallGround = new Rectangle(-WALL_MARGIN_WIDTH, mCameraHeight + WALL_MARGIN_HEIGHT - 2, mCameraWidth + 2*WALL_MARGIN_WIDTH, 2, vertexBufferObjectManager); mWallRoof = new Rectangle(-WALL_MARGIN_WIDTH, -WALL_MARGIN_HEIGHT, mCameraWidth + 2*WALL_MARGIN_WIDTH, 2, vertexBufferObjectManager); mWallLeft = new Rectangle(-WALL_MARGIN_WIDTH, -WALL_MARGIN_HEIGHT, 2, mCameraHeight + 2*WALL_MARGIN_HEIGHT, vertexBufferObjectManager); mWallRight = new Rectangle(mCameraWidth + WALL_MARGIN_WIDTH - 2, -WALL_MARGIN_HEIGHT, 2, mCameraHeight + 2*WALL_MARGIN_HEIGHT, vertexBufferObjectManager); PhysicsFactory.createBoxBody(pWorld, mWallGround, BodyType.StaticBody, mWallFixtureDef); PhysicsFactory.createBoxBody(pWorld, mWallRoof, BodyType.StaticBody, mWallFixtureDef); PhysicsFactory.createBoxBody(pWorld, mWallLeft, BodyType.StaticBody, mWallFixtureDef); PhysicsFactory.createBoxBody(pWorld, mWallRight, BodyType.StaticBody, mWallFixtureDef); pScene.attachChild(mWallGround); pScene.attachChild(mWallRoof); pScene.attachChild(mWallLeft); pScene.attachChild(mWallRight); } </code></pre> <p>And the last thing you should do is to look up example of Physics/MouseJoint in AndEngine examples.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload