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);
// 渲染玛丽
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员入门进阶(免费辅导开题报告)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值