新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package org.cocos2d.tests;
创新互联提供高防主机、云服务器、香港服务器、IDC机房托管等
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, 0, 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 = (int) (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 = (int) (4 - (p.y / 48));//计算
newZ = (newZ > 0 ? newZ : 0);//大于0就返回新顺序
map.reorderChild(tamara, newZ);//调整顺序
}
}
}