Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2D-Android-1之源码详解:23.TileMapTest1大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

package org.cocos2d.tests;

import org.cocos2d.actions.base.CCRepeatForever;

import org.cocos2d.actions.interval.CCMoveBy;

import org.cocos2d.actions.interval.CCSequence;

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.CCSprite;

import org.cocos2d.opengl.CCGLSurfaceView;

import org.cocos2d.types.CGPoint;

import android.app.Activity;

import android.os.bundle;

public class TileMapTest1 extends Activity {

public static final String LOG_TAG = TileMapTest.class.getSimplename();//得到类的名字,若很多则返回很多

private CCGLSurfaceView mGLSurfaceView;

@Override

protected void onCreate(Bundle savedInstanceStatE) {

super.onCreate(savedInstanceStatE);

mGLSurfaceView = new CCGLSurfaceView(this);//实例化view

setContentView(mGLSurfaceView);//加载view

CCDirector.sharedDirector().attachInView(mGLSurfaceView);//附加开放图形语言视图

CCDirector.sharedDirector().setLandscape(false);//设置观景模式

CCDirector.sharedDirector().setDisplayFPS(true);

CCDirector.sharedDirector().setAnimationInterval(1.0f / 30);

CCScene scene = CCScene.node();//必要的构造

scene.addChild(new TMXIsoZorder());//属于next的子类

CCDirector.sharedDirector().runWithScene(scenE);

}

public static final int kTagTileMap = 1;

static class TMXIsoZorder extends CCLayer {//1

CCSprite tamara;//精灵

public TMXIsoZorder() {

super();

CCTMXTiledMap map = CCTMXTiledMap.tiledMap("iso-test-zorder.tmx");//创建地图

addChild(map,kTagTileMap);//添加子类

map.setPosition(-1000,-50);//设置点

tamara = CCSprite.sprite("grossinis_sister1.png");//创建精灵

int z = (map.getChildren()!=null?map.getChildren().size():0);

map.addChild(tamara,z);//地图创建类

int mapWidth = (@R_696_10185@ (map.getMapSize().width * map.getTileSize().width);

tamara.setPosition( mapWidth/2,0);//设置点

tamara.setAnchorPoint(0.5f,0);//设置焦点

CCMoveBy move = CCMoveBy.action(10,CGPoint.ccp(300,250));

CCMoveBy BACk = move.reverse();

CCSequence seq = CCSequence.actions(move,BACk);//移动和返回

tamara.runAction(CCRepeatForever.action(seq));//执行

schedule("repositionSprite");

}

public void repositionSprite(float dt) {

CGPoint p = tamara.getPosition();//得到点

CCNode map = getChildByTag(kTagTileMap);//得到地图

int newZ = (@R_696_10185@ (4 - (p.y / 48));//计算

newZ = (newZ > 0 ? newZ : 0);//大于0就返回新顺序


map.reorderChild(tamara,newz);//调整顺序

}

}

}

大佬总结

以上是大佬教程为你收集整理的Cocos2D-Android-1之源码详解:23.TileMapTest1全部内容,希望文章能够帮你解决Cocos2D-Android-1之源码详解:23.TileMapTest1所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。