andengine, Colliding sprites

Problems with Canvas, OpenGL, etc...

andengine, Colliding sprites

Postby DasKaktus » Sun Oct 02, 2011 6:24 pm

Hello.

I'm a new developer so excuse my code ;)

I trying to make a simple game, where i have a box grid and a player tile that can bump into other tiles.
I have made a function that's add tiles (shortened for reading purposes):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private Sprite tile;
  2. private Body tilebody;
Parsed in 0.029 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onLoadResources() {
  2. this.mTile0Texture = new BitmapTextureAtlas(32,32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  3.         this.mTile0TextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTile0Texture, this, "tile_0.png", 0, 0);
  4. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void addTile(final float pX, final float pY, final Integer pValue) {        
  2.         switch (pValue) {
  3.                 case 0:
  4.                         tile = new Sprite(pX, pY, this.mTile0TextureRegion);
  5.                         tilebody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, tile, BodyType.StaticBody, FIXTURE_DEF);
  6.                
  7.                         this.mScene.attachChild(tile);
  8.                         this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(tile, tilebody, true, true));
  9.                         break;
  10.         }
  11. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And the player tile:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private Body mPlayerBody;
  2. private Sprite mPlayer;
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onLoadResources() {
  2. this.mPlayerTexture = new BitmapTextureAtlas(32,32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  3.         this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mPlayerTexture, this, "playertile.png", 0, 0);
  4. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void initPlayer() {
  2.                 final TextureRegion PlayerTextureRegion = this.mPlayerTextureRegion.deepCopy();
  3.                 PlayerTextureRegion.setWidth(this.mPlayerTextureRegion.getWidth());
  4.                 this.mPlayer = new Sprite(32*7, 32*7, 32, 32, PlayerTextureRegion);
  5.                
  6.         this.mPlayerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, this.mPlayer, BodyType.DynamicBody, FIXTURE_DEF);
  7.  
  8.         this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(this.mPlayer, this.mPlayerBody, true, false));
  9.  
  10.         this.mScene.attachChild(this.mPlayer);
  11. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


But I tried everything and cannot get collision to work in:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public Scene onLoadScene() {
  2.  
  3.                 this.mEngine.registerUpdateHandler(new IUpdateHandler() {
  4.  
  5.                         @Override
  6.                         public void onUpdate(float pSecondsElapsed) {
  7.                                 if(mPlayer.collidesWith(????????)) {
  8.                                 }
  9.                                        
  10.                     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Is there anybody that can help me?

Maybe it's just the tile creation process thats needs a rewrite, but how.
I want to clone several types of tiles to the board and have them collideable.

Thanks in advance.
DasKaktus
Freshman
Freshman
 
Posts: 3
Joined: Mon May 16, 2011 10:38 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests