我正在开发Cocos2D android应用程序,这是我的第一个示例应用程序。 cocos2d-android.jar我下载并将其附加在/ libs文件夹中。这是我的classActivity& logcat输出
CocosMainActivity :
CCGLSurfaceView mGLSurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cocos_main);
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);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
CCDirector.sharedDirector().attachInView(mGLSurfaceView);
CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationPortrait);
CCDirector.sharedDirector().setDisplayFPS(true);
CCDirector.sharedDirector().setAnimationInterval(1.0f/60);
CCScene scene = CocosLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
CCDirector.sharedDirector().pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
CCDirector.sharedDirector().resume();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
CCDirector.sharedDirector().end();
}
static class CocosLayer extends CCLayer{
CCLabel label;
CCSprite iconImage;
public static CCScene scene(){
CCScene scene = CCScene.node();
CCLayer layer = new CocosLayer();
scene.addChild(layer);
return scene;
}
protected CocosLayer(){
this.setIsTouchEnabled(true);
//add label
label = CCLabel.makeLabel("cocos2d Droid Label", "Droid Sans", 30);
label.setPosition(CGPoint.ccp(164, 240));
addChild(label,0);
//add image
iconImage = CCSprite.sprite("ic_launcher.png");
iconImage.setPosition(CGPoint.make(100, 100));
addChild(iconImage,0);
}
}
LogCat :
01-30 10:52:40.642: E/AndroidRuntime(664): FATAL EXCEPTION: GLThread 75
01-30 10:52:40.642: E/AndroidRuntime(664): java.lang.NullPointerException
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCAtlasNode.updateBlendFunc(CCAtlasNode.java:168)
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCAtlasNode.<init> (CCAtlasNode.java:77)
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCLabelAtlas.<init>(CCLabelAtlas.java:40)
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCLabelAtlas.label(CCLabelAtlas.java:35)
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCDirector.setGLDefaultValues(CCDirector.java:593)
01-30 10:52:40.642: E/AndroidRuntime(664): at org.cocos2d.nodes.CCDirector.onSurfaceCreated(CCDirector.java:636)
01-30 10:52:40.642: E/AndroidRuntime(664): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
01-30 10:52:40.642: E/AndroidRuntime(664): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
我将这个“ic_launcher.png”放在assets文件夹中。
提前致谢