溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Cocos2D-Android-1之源碼詳解:23.TileMapTest1

發(fā)布時間:2020-07-18 13:09:18 來源:網(wǎng)絡 閱讀:608 作者:abab99 欄目:移動開發(fā)

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);//設(shè)置觀景模式

            CCDirector.sharedDirector().setDisplayFPS(true);

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

            CCScene scene = CCScene.node();//必要的構(gòu)造

            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");//創(chuàng)建地圖

            addChild(map, 0, kTagTileMap);//添加子類

            map.setPosition(-1000,-50);//設(shè)置點

            tamara = CCSprite.sprite("grossinis_sister1.png");//創(chuàng)建精靈

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

            map.addChild(tamara, z);//地圖創(chuàng)建類

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

            tamara.setPosition( mapWidth/2, 0);//設(shè)置點

            tamara.setAnchorPoint(0.5f, 0);//設(shè)置焦點

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

            CCMoveBy back = move.reverse();

            CCSequence seq = CCSequence.actions(move, back);//移動和返回

            tamara.runAction(CCRepeatForever.action(seq));//執(zhí)行

            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);//調(diào)整順序

        }

    }

}


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI