温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Cocos2D-Android-1之源码详解:23.TileMapTest1

发布时间:2020-07-18 13:09:18 来源:网络 阅读:592 作者:abab99 栏目:移动开发

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, 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);//调整顺序

        }

    }

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI