libgdx Tiled 实例分析(中)

这节来查看oncreat接口,来看下整个的思路:
@Override
public void create () {
// load the koala frames, split them, and assign them to Animations
koalaTexture = new Texture("data/maps/tiled/super-koalio/koalio.png");
TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0];
stand = new Animation(0, regions[0]);
jump = new Animation(0, regions[1]);
walk = new Animation(0.15f, regions[2], regions[3], regions[4]);
walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);
// 构造三个动画,描述站立,跳起,以及行走。一个玛丽的纹理资源


// figure out the width and height of the koala for collision
// detection and rendering by converting a koala frames pixel
// size into world units (1 unit == 16 pixels)
Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth();
Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight();
// 设置玛丽的宽高,这里1/16 的意思为需要缩放比例,这个值是在制作地图时填写对的一个瓦片的大小。
// load the map, set the unit scale to 1/16 (1 unit == 16 pixels)
map = new TmxMapLoader().load("data/maps/tiled/super-koalio/level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f);
// 加载地图,设置渲染器,1/16 意思一致
// create an orthographic camera, shows us 30x20 units of the world
camera = new OrthographicCamera();
camera.setToOrtho(false, 30, 20);
camera.update();
// 创建一个正交摄像头,设置显示30*20格瓦片
// create the Koala we want to move around the world
koala = new Koala();
koala.position.set(20, 20);
// 将玛丽放置在对应位置上
}

下来我们看下render接口,主要是渲染方法


@Override
public void render () {
// clear the screen
Gdx.gl.glClearColor(0.7f, 0.7f, 1.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// 设置背景色
// get the delta time
float deltaTime = Gdx.graphics.getDeltaTime();
// 时间
// update the koala (process input, collision detection, position update)
updateKoala(deltaTime);
//更新玛丽位置,判断行走或者静止
// let the camera follow the koala, x-axis only
camera.position.x = koala.position.x;
camera.update();
// 摄像头跟随玛丽移动
// set the tile map rendere view based on what the
// camera sees and render the map
renderer.setView(camera);
renderer.render();
// 设置渲染的摄像头,进行渲染


// render the koala
renderKoala(deltaTime);
// 渲染玛丽
}

你可能感兴趣的:(android,源码分析,libgdx)