cocos2d-android的基础代码
2014-01-23 15:18
190 查看
1、新建项目
2、将下载好的cocos-master中的cocos2d-android中的libs目录中的所有东西拷到libs目录下,并将cocos2d-android.jar添加到buildpath
3、开始编写代码
1)MainActivity
package com.njupt.firstgame;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
//cocos2d引擎会把图形会知道在该view对象上
private CCGLSurfaceView view = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = new CCGLSurfaceView(this);
setContentView(view);
CCDirector director = CCDirector.sharedDirector();//得到CCDirector对象
/**
* 设置游戏程序的相关属性
*/
director.attachInView(view);//设置当前游戏程序中所使用的view对象
director.setDisplayFPS(true);//设置游戏程序是否显示FPS值
director.setAnimationInterval(1.0f/60);//设置游戏渲染一帧所需要的时间
//生成一个游戏场景对象
CCScene scene = CCScene.node();
//生成布景层对象
GameLayer gameLayer = new GameLayer();
//将布景层对象添加至游戏场景中
scene.addChild(gameLayer);
//运行游戏场景
director.runWithScene(scene);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
2)GameLayer
package com.njupt.firstgame;
import org.cocos2d.layers.CCLayer;
public class GameLayer extends CCLayer{
public GameLayer() {
}
}
----------------------------------------------------------------------------------------------------------------------------------------
本例子的源码的下载链接:http://download.csdn.net/detail/caihongshijie6/6877399
2、将下载好的cocos-master中的cocos2d-android中的libs目录中的所有东西拷到libs目录下,并将cocos2d-android.jar添加到buildpath
3、开始编写代码
1)MainActivity
package com.njupt.firstgame;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
//cocos2d引擎会把图形会知道在该view对象上
private CCGLSurfaceView view = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = new CCGLSurfaceView(this);
setContentView(view);
CCDirector director = CCDirector.sharedDirector();//得到CCDirector对象
/**
* 设置游戏程序的相关属性
*/
director.attachInView(view);//设置当前游戏程序中所使用的view对象
director.setDisplayFPS(true);//设置游戏程序是否显示FPS值
director.setAnimationInterval(1.0f/60);//设置游戏渲染一帧所需要的时间
//生成一个游戏场景对象
CCScene scene = CCScene.node();
//生成布景层对象
GameLayer gameLayer = new GameLayer();
//将布景层对象添加至游戏场景中
scene.addChild(gameLayer);
//运行游戏场景
director.runWithScene(scene);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
2)GameLayer
package com.njupt.firstgame;
import org.cocos2d.layers.CCLayer;
public class GameLayer extends CCLayer{
public GameLayer() {
}
}
----------------------------------------------------------------------------------------------------------------------------------------
本例子的源码的下载链接:http://download.csdn.net/detail/caihongshijie6/6877399
相关文章推荐
- Cocos2d-x游戏开发之代码如何识别ios平台与android并分开处理
- cocos2d-x之Android播放视频c++代码
- Android零基础入门第9节:Android应用实战,不懂代码也可以开发
- 用人类的思维方式去写更容易维护的代码——用<抽象-基础-逻辑>模式开发Java(Android)程序
- android第一行代码 第三章 常用基础控件
- Android第一行代码笔记 Activity的一些基础知识
- Hook Android C代码基础总结
- 2048聚合版开源代码,cocos2d-js编写,基于CocosEditor开发工具,可运行Android,ios,html5等
- android下,cocos2d-x 游戏密码框输入时 *号显示代码。。。。。。。
- Cocos2d-x游戏开发之Mac下Android如何更新项目代码
- Android学习之分析代码&巩固基础
- Android零基础入门第9节:Android应用实战,不懂代码也可以开发
- Cocos2d-x 调用 Android 代码的后续
- Android 基础代码实例:音频 均衡器 示波器 声场 等
- Android零基础入门第9节:Android应用实战,不懂代码也可以开发
- 爱测未来移动-从Emmagee代码浅谈Android基础性能数据监控方法
- Cocos2d-x3.3RC0通过JNI调用Android的Java层URI代码发送短信
- 使用Visual Studio 2015调试Android平台Cocos2d-x游戏的C++代码
- cocos2d-x基础<一> Android环境配置和HelloWorld的运行
- Android-NDK开发之基础--Android JNI实例代码(一)-- 在JNI中执行Java方法--C/C++调用Java