Narendrabrsoft / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Multiple problems with CCTMXTiledMap #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello, guys.
I found the following issues with CCTMXTiledMap. I run it on Android Emulator 
2.2, as well as 1.6.
The screenshots of the invalid displaying of the tiled map is in appropriate 
attachements. I also include sample project for your convenience.

Waiting for your comments.

package com.cocosTest;

import org.cocos2d.events.CCTouchDispatcher;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.layers.CCTMXTiledMap;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.opengl.CCGLSurfaceView;
import org.cocos2d.types.CGPoint;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class GameActivity extends Activity {
    private CCGLSurfaceView mGLSurfaceView;

    public class GameLayer extends CCLayer
    {     
      public GameLayer() 
      {
        super();
        this.setIsTouchEnabled(true);       
      }

      @Override
      public boolean ccTouchesBegan(MotionEvent event)
      {      
      CGPoint convertedLocation = CCDirector.sharedDirector()
        .convertToGL(CGPoint.make(event.getX(), event.getY()));

      CCSprite sprite = CCSprite.sprite("tmw_desert_spacing.png");
      sprite.setPosition(convertedLocation);
      addChild(sprite);        

      return CCTouchDispatcher.kEventHandled;
      }       
    }

  @Override
  public void onStart() {
      super.onStart();        
  }

  @Override
  public void onPause() {
      super.onPause();

      CCDirector.sharedDirector().pause();
  }

  @Override
  public void onResume() {
      super.onResume();

      CCDirector.sharedDirector().resume();
  }

  @Override
  public void onDestroy() {
      super.onDestroy();

      CCDirector.sharedDirector().end();
  }

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set the window status, no tile, full screen and don't sleep
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mGLSurfaceView = new CCGLSurfaceView(this);

    setContentView(mGLSurfaceView);

    CCDirector.sharedDirector().attachInView(mGLSurfaceView);
    CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
    CCDirector.sharedDirector().setDisplayFPS(false);
    CCDirector.sharedDirector().setAnimationInterval(1.0f / 60);

    CCScene scene = CCScene.node();        

    CCLayer tiledLayer = CCLayer.node();        
    CCLayer aboveLayer = new GameLayer();

//    //--------------------------------------------------
//    // TEST1. This order of loading results in daubed tile picture
//    //--------------------------------------------------
//    CCSprite anObject = CCSprite.sprite("fire.png");
//    anObject.setPosition(100, 100);
//    aboveLayer.addChild(anObject);    
//    CCTMXTiledMap map = CCTMXTiledMap.tiledMap("map1.tmx");
//    tiledLayer.addChild(map);

//    //--------------------------------------------------
//    // TEST2. This order of loading results in disappearing of most of the 
tile
//    //--------------------------------------------------
//    CCTMXTiledMap map = CCTMXTiledMap.tiledMap("map1.tmx");
//    tiledLayer.addChild(map);
//    CCSprite anObject = CCSprite.sprite("fire.png");
//    anObject.setPosition(100, 100);
//    aboveLayer.addChild(anObject);    

    //--------------------------------------------------
    // TEST3. This order of loading results in correct displaying the tile,
    // but the most part of the tile will disappear when sprite is added 
    // in GameLayer.ccTouchesBegan
    //--------------------------------------------------
    CCTMXTiledMap map = CCTMXTiledMap.tiledMap("map1.tmx");
    tiledLayer.addChild(map);

    scene.addChild(tiledLayer, 10);
    scene.addChild(aboveLayer, 20);

    // Make the Scene active
    CCDirector.sharedDirector().runWithScene(scene);    
  }

}

Original issue reported on code.google.com by Plin...@gmail.com on 29 Jan 2011 at 2:41

Attachments:

GoogleCodeExporter commented 8 years ago
I have the same issues here, 
also when you do a TintBy() or setColor() on the object in the layer above the 
tiledLayer, then some tiles will have the same TintBy/setColor behaviour as the 
object above the layer.

Original comment by erwin.ja...@gmail.com on 4 Feb 2011 at 2:21

GoogleCodeExporter commented 8 years ago
I'm also experiencing problems with CCTMXTiledMap, even just with the default 
.tmx files supplied with cocos2d.  I've downloaded the latest revision from 
github as of March 4th 2011, jar-ed up the source, and created a brand new 
project (with a copy of the assets from the original in the assets folder), and 
a very stripped down main activity, attempting to load a .tmx into a layer.

I've attached the exported project.  

As you can see, no tile map appears at all.  I've tried substituting a few 
other tile maps but they don't work either.  The ones that do work only display 
a single tile, similar to test2.png above.  

Furthermore, I'm trying to create tilemaps with Tiled, but ones I generate from 
scratch appear to kill cocos at runtime with an endless series of recursive 
NullPointerExceptions (this is not included in the current upload).

Original comment by tony.ada...@gmail.com on 15 Mar 2011 at 5:48

Attachments:

GoogleCodeExporter commented 8 years ago
tony, the problem yo face with tiles from tiled may be caused by the default 
encoding of the maps generated with tiled. you should change them to base64 
with gzip compression (that worked for me). but even if they did not crash, i 
face the same problems as others with tiled maps.

Original comment by roberto....@gmail.com on 29 Mar 2011 at 11:15

GoogleCodeExporter commented 8 years ago
Hi.. I'm still not able to display the TMX Map. I checked the Tiled Map Editor 
encoding, and it was set to Base 64 GZipped compression. All I get is a blank 
screen with the FPS. Nothing else.

Thanks for the help in advance,
Abhimanyu

Original comment by abhimany...@gmail.com on 16 Jun 2011 at 12:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi Abhimanyu,

I've changed the Tiled Map Editor encoding to Base 64 GZipped compression and 
it works for me but the result displayed was the same of first post.

Original comment by leoapgo...@gmail.com on 22 Jun 2011 at 2:39

GoogleCodeExporter commented 8 years ago
Hello,

I had the same issue and after analyzing it found (at least) a workaround (at 
least for me). I wrote the following class:

public class TCCTMXLayer extends CCNode {
    private CCTMXLayer layer;

    public TCCTMXLayer(CCTMXLayer layer) {
        this.layer = layer;
    }

    @Override
    public void draw(GL10 gl) {
        gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
        layer.draw(gl);
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    }
}

, and used it to add tiled layers and sprite sheet with sprite to a layer:

        CCParallaxNode pn = CCParallaxNode.node();
        pn.addChild(new TCCTMXLayer(map.layerNamed("back1")) , -2, 1, 1, 0, 0);
        pn.addChild(new TCCTMXLayer(map.layerNamed("mountain")), -1, 0.7f, 0.7f, -18, -18);
        pn.addChild(new TCCTMXLayer(map.layerNamed("main")), 1, 1, 1, 0, 0);
        pn.addChild(aSheet,2, 1, 1, 0, 0);

                addChild(pn);

At least for me the problem was fixed after this workaround.

I'm really new to cocos2d (and graphic engine in general), so don't blame me 
hard if I wrote something stupid =] .

Original comment by pboklas...@gmail.com on 11 Jul 2011 at 8:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hello Weikuan,

   I found probably better, more logical, way to fix the issue in CCTextureAtlas draw method:

        if (withColorArray_) {
            gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
            gl.glColorPointer(4, GL10.GL_FLOAT, 0, colors.bytes);
        }
        else
            // Disable color buffer if it hasn't been initialized
            gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

Best Regards, Petr Boklashov.

Original comment by pboklas...@gmail.com on 13 Jul 2011 at 5:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Yes, you'r right, it needs to be enabled after the draw.

Original comment by pboklas...@gmail.com on 13 Jul 2011 at 11:04

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi Weikuan,

Can you please confirm that the code for rendering TMX files properly has been 
tested and integrated into the Github repository.

Thanks,
Abhimanyu

Original comment by abhimany...@gmail.com on 9 Nov 2011 at 1:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks a lot Weikuan. :)

Abhimanyu

Original comment by abhimany...@gmail.com on 10 Nov 2011 at 6:18

GoogleCodeExporter commented 8 years ago
hi, 

i am not able to load .tmx file. 
can anyone plese help me here?

regards, 
g bali

Original comment by guru.sin...@gmail.com on 28 Feb 2012 at 6:14

GoogleCodeExporter commented 8 years ago
hi all,
 I m new to cocos2d-android.
I m not able to load .tmx file.
and how it works please help me.

Regards
Achin 

Original comment by achingup...@gmail.com on 7 Mar 2012 at 3:16