Narendrabrsoft / cocos2d-android-1

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

simple tile demo is working in the emulator but not on actual hardware #47

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I created an simple demo and could run it successfully inside the emulator 
but not on actual device

here is my reduced code example. 

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.CCNode;
import org.cocos2d.nodes.CCSpriteSheet;
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 MainGame extends Activity {
    public static final String LOG_TAG = MainGame.class.getSimpleName();
    private CCGLSurfaceView mGLSurfaceView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        mGLSurfaceView = new CCGLSurfaceView(this);
        setContentView(mGLSurfaceView);

        // attach the OpenGL view to a window
        CCDirector.sharedDirector().attachInView(mGLSurfaceView);

        // set landscape mode
        CCDirector.sharedDirector().setLandscape(false);

        // show FPS
        CCDirector.sharedDirector().setDisplayFPS(true);

        // frames per second
        CCDirector.sharedDirector().setAnimationInterval(1.0f / 60);

        CCScene scene = CCScene.node();
        scene.addChild(new TMXOrtho());
        // Make the Scene active
        CCDirector.sharedDirector().runWithScene(scene);
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    protected void onPause() {
        super.onPause();
        CCDirector.sharedDirector().onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        CCDirector.sharedDirector().onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        CCDirector.sharedDirector().end();
    }
}

class TMXOrtho extends CCLayer {
    public static final int kTagTileMap = 1;

    public TMXOrtho() {
        super();
        this.setIsTouchEnabled(true);
        CCTMXTiledMap map = CCTMXTiledMap.tiledMap("level01.tmx");
        addChild(map, 0, kTagTileMap);

        for (CCNode child : map.getChildren()) {
            CCSpriteSheet css = (CCSpriteSheet) child;
            css.getTexture().setAntiAliasTexParameters();
        }

    }

    public String title() {
        return "Level 1";
    }

    public void registerWithTouchDispatcher() {
        // CCTouchDispatcher.sharedDispatcher().addTargetedDelegate(this, 0, true);
        CCTouchDispatcher.sharedDispatcher().addDelegate(this, 0);
    }

    @Override
    public boolean ccTouchesBegan(MotionEvent event) {
        return true;
    }

    @Override
    public boolean ccTouchesEnded(MotionEvent event) {
    return false;
    }

    @Override
    public boolean ccTouchesCancelled(MotionEvent event) {
    return false;
    }

    @Override
    public boolean ccTouchesMoved(MotionEvent event) {
        final int N = event.getHistorySize() - 1;
        if (N <= 0)
            return true;
        CGPoint touchLocation = CGPoint.make(event.getX(), event.getY());
        CGPoint prevLocation = CGPoint.make(event.getHistoricalX(N), event.getHistoricalY(N));

        touchLocation   = CCDirector.sharedDirector().convertToGL(touchLocation);
        prevLocation    = CCDirector.sharedDirector().convertToGL(prevLocation);

        CGPoint diff = CGPoint.ccpSub(touchLocation, prevLocation);

        CCNode node = getChild(kTagTileMap);
        CGPoint currentPos = node.getPosition();
        node.setPosition(CGPoint.ccpAdd(currentPos, diff));
        return true;
    }
}

What is the expected output? What do you see instead?
my desire shows a black screen where only the fps is displayed and updated. 

What version of the product are you using? On what operating system?
the emulator I am using is android 2.2 just like my HTC desire. I also tested 
the demo with emu 1.6 and there it runs also fine.

Please provide any additional information below.

i checked the log and there is no stack trace or something indication a faulty 
application flow except one entry "fail to set top app changed" don´t know if 
it has something to do with the black screen.

Original issue reported on code.google.com by Bauer.Va...@gmail.com on 23 Jan 2011 at 10:52

Attachments:

GoogleCodeExporter commented 8 years ago
Can you please continue the tutorial made by:
http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d
?

I'm having so many issues with trying to get an the CCTMXObjectGroup to work.

Original comment by cancienn...@gmail.com on 16 May 2011 at 4:23

GoogleCodeExporter commented 8 years ago
i am also trying for tilemap in cocos2d for android.Please help me if you got 
any solution

Original comment by ashw...@impressol.com on 22 Jan 2013 at 5:50