根据上一篇文章,创建好cocos2d——android的开发环境

先上效果图

cocos2d_android 第一个游戏_第1张图片

实现该效果的代码:

package com.cn.firstgame;import org.cocos2d.layers.CCScene;import org.cocos2d.nodes.CCDirector;import org.cocos2d.opengl.CCGLSurfaceView;import android.app.Activity;import android.os.Bundle;import android.view.Menu;public class MainActivity extends Activity {//CC引擎会把图像绘制在该Viewprivate CCGLSurfaceView view;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);view=new CCGLSurfaceView(this);setContentView(view);//获得导演对象CCDirector director=CCDirector.sharedDirector();/*** 设置游戏属性*/director.attachInView(view);director.setDisplayFPS(true);director.setAnimationInterval(1.0f/30);//生成游戏场景对象CCScene scene=CCScene.node();//生成游戏布景对象GameLayer layer=new GameLayer();//将布景对象加入到场景中scene.addChild(layer);//运行布景director.runWithScene(scene);}@Overridepublic 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;}}
package com.cn.firstgame;import org.cocos2d.layers.CCLayer;public class GameLayer extends CCLayer {public GameLayer() {        }}
  

更多相关文章

  1. android activity之间传递对象(Serializable 和 Parcelable)
  2. Android保证首次获取到的location对象不为空的解决方案
  3. 网页拉起游戏APP
  4. android 扫雷游戏

随机推荐

  1. android用户界面之Gallery教程实例汇总
  2. 实现导航栏的左右滑动效果
  3. Android - Navigation
  4. android 开发技巧(13)--处理空列表
  5. Android基础知识总结(转载)
  6. 在Android中创建启动界面 编辑
  7. Ubuntu中编译Android(安卓)JellyBean 4.2
  8. (2) 搭建 Android 系统开发环境
  9. android 播放assets目录内的音乐,及使用Se
  10. YOLOv5-pytorch迁移至android