先上图
环境配置步骤
1、新建android 项目[最好4.x版本]
3、右击cocos2d-android-2.jar 选择 bulid path ——>add to bulid
4、编写测试文件
Mainactivity
package com.diecolor; import org.cocos2d.layers.CCLayer; 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; import android.view.MenuItem; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { //cocos2d把图形绘制到当前 activity private CCGLSurfaceView ccglSurfaceView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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); ccglSurfaceView=new CCGLSurfaceView(this); setContentView(ccglSurfaceView); CCDirector ccDirector=CCDirector.sharedDirector(); ccDirector.attachInView(ccglSurfaceView);//设置导演 //显示FPS值 ccDirector.setDisplayFPS(true);// //设置游戏的FPS值 高于30 渲染一帧 所需要的时间 秒 ccDirector.setAnimationInterval(1/30.0); //生成 游戏 场景 CCScene scene=CCScene.node(); //图层 放入 游戏场景 scene.addChild(new NewLayer()); //导演 启动游戏 ccDirector.runWithScene(scene); } }
NewLayer类
package com.diecolor; import org.cocos2d.layers.CCLayer; import org.cocos2d.layers.CCTMXTiledMap; import org.cocos2d.nodes.CCDirector; import org.cocos2d.nodes.CCSprite; import org.cocos2d.types.CGSize; public class NewLayer extends CCLayer{ CCSprite sprite; CGSize winSize=CCDirector.sharedDirector().winSize(); public NewLayer() { sprite=CCSprite.sprite("myplane1.png"); sprite.setPosition(winSize.width/2,winSize.height/2); //CCTMXTiledMap map=CCTMXTiledMap.tiledMap("test.tmx"); // this.addChild(map); this.addChild(sprite); } }这里用到的myplane1.png 文件 要放在项目的assets目录下
5、启动模拟器
6、正常运行android程序即可
材料下载地址:http://www.diecolor.com/bbs/forum.php?mod=forumdisplay&fid=40&page=1
http://www.diecolor.com/bbs/forum.php?mod=viewthread&tid=194&extra=page%3D1
原文链接:https://www.f2er.com/cocos2dx/345988.html