mc跑酷地图游戏的地图用Tiledmap滚动不流畅

安全检查中...
请打开浏览器的javascript,然后刷新浏览器
< 浏览器安全检查中...
还剩 5 秒&TiledMap能够做多大的地图,有什么好的优化方式? - 知乎15被浏览2607分享邀请回答0添加评论分享收藏感谢收起网站已改版,请使用新地址访问:
tiledMap 跑酷地图素材
值得下载。
2d横板游戏 Other Games 其他
238万源代码下载-
&文件名称: tiledMap
& & & & &&]
&&所属分类:
&&开发工具: C++
&&文件大小: 1080 KB
&&上传时间:
&&下载次数: 19
&&提 供 者:
&详细说明:跑酷地图素材
tiledmap可用
值得下载。
2d横板游戏-Parkour map material available tiledmap worth downloading. 2d cross board game
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&璺峰板剧&&..................\.DS_Store&&__MACOSX&&........\璺峰板剧&&........\..................\._.DS_Store&&璺峰板剧\map_1.png&&__MACOSX\璺峰板剧\._map_1.png&&璺峰板剧\map_10.png&&..................\map_2.png&&__MACOSX\璺峰板剧\._map_2.png&&璺峰板剧\map_3.png&&__MACOSX\璺峰板剧\._map_3.png&&璺峰板剧\map_4.png&&__MACOSX\璺峰板剧\._map_4.png&&璺峰板剧\map_5.png&&__MACOSX\璺峰板剧\._map_5.png&&璺峰板剧\map_6.png&&__MACOSX\璺峰板剧\._map_6.png&&璺峰板剧\map_7.png&&__MACOSX\璺峰板剧\._map_7.png&&璺峰板剧\map_8.png&&__MACOSX\璺峰板剧\._map_8.png&&璺峰板剧\map_9.png&&__MACOSX\璺峰板剧\._map_9.png
&近期下载过的用户:
&相关搜索:
&输入关键字,在本站238万海量源码库中尽情搜索:
&[] - 一个用objective-c开发的横版,屋顶上面,跑酷的游戏。可以直接编译运行在iphone上面
&[] - 翡翠宫殿内藏着神龙秘籍,传说神龙秘籍具有通天彻底的威力。熊猫阿宝为了得到它决定独闯翡翠宫,只是前往翡翠宫殿的路途遥远,要经过十盘阶梯的考验才能到达!它能否顺利拿到神龙秘籍呢?让我们拭目以待!
&[] - 火柴人的跳跃和滚动 按s滚动躲避障碍 按w跳跃躲避障碍本文使用的libgdx是0.92版本,和现在的最新版可能有一些不一样的地方。全文内容仅供参考。
本文紧跟上文:
上文说到绘制了Map,然后我们的主角也可以四处活动了,但是仍有一些不完善的地方。
1.地图的边界没有控制。Camera的位置其实是viewport的位置,不是屏幕边界,所以如果直接按照上文的做法做的话主角走到屏幕边缘的时候就有问题了。
2.没有障碍,主角的行动没有约束。
现在先来解决第一个问题。
解决方案很简单,我们时刻注意viewport的位置,根据viewport计算Screen的边界,让其不超过地图。
代码如下:
private void CameraMove(Vector3 vector3, Actor mainActor) {
Vector3 viewport = stage.getCamera().position.cpy();
viewport = viewport.add(vector3);
Vector3 zbound = new Vector3(width / 2, height / 2, 0).add(viewport);
if (zbound.x & maxCamPosition.x || zbound.y & maxCamPosition.y) {
Vector3 fbound = new Vector3(-width / 2, -height / 2, 0).add(viewport);
if (fbound.x & 0 || fbound.y & 0) {
stage.getCamera().position.add(vector3);
for (Actor actor : stage.getActors()) {
actor.x += vector3.x;
actor.y += vector3.y;
运行一下,恩,感觉还行。但是又有一个问题出现了&当地图达到边界时地图不能滚动了,但是主角应该还是可以前进的。
处理方法我采用的是将Camera和主角分开处理,还是判断一下,主角如果移动后不超出屏幕,就继续移动。
Vector3 viewport = stage.getCamera().position.cpy();
viewport = viewport.add(vector3);
Vector3 zbound = new Vector3(width / 2, height / 2, 0).add(viewport);
if (zbound.x & maxCamPosition.x || zbound.y & maxCamPosition.y) {
isCameraMove = false;
Vector3 fbound = new Vector3(-width / 2, -height / 2, 0).add(viewport);
if (fbound.x & 0 || fbound.y & 0) {
isCameraMove = false;
Vector3 v3 = new Vector3(mainActor.x, mainActor.y, 0);
stage.getCamera().project(v3);
Vector3 a = v3.cpy().add(vector3);
if (a.x & width || a.y & height) {
isActorMove = false;
if (a.x & 0 || a.y & 0) {
isActorMove = false;
if (isCameraMove) {
stage.getCamera().position.add(vector3);
for (Actor actor : stage.getActors()) {
if (!actor.equals(player)) {
actor.x += vector3.x;
actor.y += vector3.y;
if (isActorMove) {
player.x += vector3.x;
player.y += vector3.y;
第一个问题基本解决,为什么说是基本解决?因为主角和Camera的位置可能会变动。造成主角在屏幕一角行走的问题。我一般是判断主角位置,当位于中心区域时在让二者联动。
现在来解决第二个问题,障碍物的问题。
重新编辑我们的TMX文件。添加一个新图块:
大小还是32*32.
然后新建一个图层,将地图中不能穿越的部分用红色的方块填充。
编辑红色块的属性,添加一个Pass-False键值(这个值是随意的,只要你能懂就行)
最后隐藏该图层,保存文件。(我在Editor里面确实隐藏了这个层,但是libgdx还是绘制了,只有自己处理一下了)
map = TiledLoader.createMap(mapHandle);
for (int i = 0; i & map.layers.size(); i++) {
if ("NoPass".equals(map.layers.get(i).name)) {
nopassLayer = map.layers.get(i);
map.layers.remove(i);
map实例化以后,先寻找我们的障碍层,将其从map中移除。为了方便调试,暂时没有移除它。
在主角每次移动时我们就检查主角移动后的位置是在哪块里面,这块是不是不能通过的,如果不能就不移动,否则就移动。
先遍历所有tiles,看一下pass=false的是多少ID的那块。
int nopassId = 0;
TileSet set = map.tileSets.get(map.tileSets.size() - 1);
int masSize = set.firstgid + layer.tiles.
for (int i = 0; i & masS i++) {
if ("False".equals(map.getTileProperty(i, "Pass"))) {
nopassId =
Gdx.app.log("Find!", i + " ");
然后推算移动后会处于哪块中,哪一块是不是不能通过的。
int xid = MathUtils.ceilPositive(pos.x / map.tileWidth);
int yid = MathUtils.ceilPositive(pos.y / map.tileWidth);
if (layer.tiles[layer.tiles.length - yid][xid - 1] == nopassId) {
return true;
return false;
在移动时先判断一下,如果会达到不能到达的块就直接退出。
Vector2 pos = new Vector2(mainActor.x, mainActor.y);
if (CheckMoveable(map, nopassLayer, vector3, pos)) {
完整代码:(代码有点乱&)
package blogs.htynkn.import javax.swing.text.ZoneV import javax.swing.text.html.MinimalHTMLWimport com.badlogic.gdx.ApplicationL import com.badlogic.gdx.G import com.badlogic.gdx.InputM import com.badlogic.gdx.InputP import com.badlogic.gdx.files.FileH import com.badlogic.gdx.graphics.C import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.OrthographicC import com.badlogic.gdx.graphics.T import com.badlogic.gdx.graphics.g2d.BitmapF import com.badlogic.gdx.graphics.g2d.SpriteB import com.badlogic.gdx.graphics.g2d.TextureR import com.badlogic.gdx.graphics.g2d.tiled.TileA import com.badlogic.gdx.graphics.g2d.tiled.TileMapR import com.badlogic.gdx.graphics.g2d.tiled.TileS import com.badlogic.gdx.graphics.g2d.tiled.TiledL import com.badlogic.gdx.graphics.g2d.tiled.TiledL import com.badlogic.gdx.graphics.g2d.tiled.TiledM import com.badlogic.gdx.graphics.g2d.tiled.TiledO import com.badlogic.gdx.graphics.g2d.tiled.TiledObjectG import com.badlogic.gdx.graphics.glutils.ShaderP import com.badlogic.gdx.math.MathU import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.A import com.badlogic.gdx.scenes.scene2d.S import com.badlogic.gdx.scenes.scene2d.ui.I import com.badlogic.gdx.scenes.scene2d.ui.L import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelSpublic class JavaGame implements ApplicationListener, InputProcessor {
private TiledM
private TileA
private TileMapRenderer tileMapR
Vector3 camDirection = new Vector3(1, 1, 0);
Vector2 maxCamPosition = new Vector2(0, 0);
Vector3 moveVector = new Vector3(0, 0, 0);
boolean isP
TiledLayer nopassL
public void create() {
final String path = "map/";
final String mapname = "tilemap";
FileHandle mapHandle = Gdx.files.internal(path + mapname + ".tmx");
map = TiledLoader.createMap(mapHandle);
for (int i = 0; i & map.layers.size(); i++) {
if ("NoPass".equals(map.layers.get(i).name)) {
nopassLayer = map.layers.get(i);
// map.layers.remove(i);
atlas = new TileAtlas(map, new FileHandle("map/"));
tileMapRenderer = new TileMapRenderer(map, atlas, 10, 10);
maxCamPosition.set(tileMapRenderer.getMapWidthUnits(), tileMapRenderer
.getMapHeightUnits());
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
stage = new Stage(width, height, true);
Label label = new Label("FPS:", new LabelStyle(new BitmapFont(Gdx.files
.internal("font/blue.fnt"),
Gdx.files.internal("font/blue.png"), false), Color.WHITE),
"fpsLabel");
label.y = height - label.getPrefHeight();
label.x = 0;
stage.addActor(label);
for (TiledObjectGroup group : map.objectGroups) {
for (TiledObject object : group.objects) {
if ("play1".equals(object.name)) {
player = new Image(new TextureRegion(new Texture(Gdx.files
.internal("map/player.png")), 0, 0, 27, 40));
player.x = object.x;
player.y = tileMapRenderer.getMapHeightUnits() - object.y; // map是左上角,Stage是左下角
stage.addActor(player);
InputMultiplexer inputMultiplexer = new InputMultiplexer();
inputMultiplexer.addProcessor(this);
inputMultiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(inputMultiplexer);
public void dispose() {
// TODO Auto-generated method stub
public void pause() {
// TODO Auto-generated method stub
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
OrthographicCamera c = (OrthographicCamera) stage.getCamera();
if (isPress) {
CameraMove(moveVector, player);
((Label) stage.findActor("fpsLabel")).setText("FPS: "
+ Gdx.graphics.getFramesPerSecond());
stage.act(Gdx.graphics.getDeltaTime());
tileMapRenderer.render(c);
stage.draw();
private void CameraMove(Vector3 vector3, Actor mainActor) {
boolean isCameraMove = true;
boolean isActorMove = true;
Vector2 pos = new Vector2(mainActor.x, mainActor.y);
if (CheckMoveable(map, nopassLayer, vector3, pos)) {
if (CheckMoveable(map, nopassLayer, vector3, pos.cpy().add(
mainActor.width, 0))) {
if (CheckMoveable(map, nopassLayer, vector3, pos.cpy().add(
mainActor.width, mainActor.height))) {
if (CheckMoveable(map, nopassLayer, vector3, pos.cpy().add(0,
mainActor.height))) {
Vector3 viewport = stage.getCamera().position.cpy();
viewport = viewport.add(vector3);
Vector3 zbound = new Vector3(width / 2, height / 2, 0).add(viewport);
if (zbound.x & maxCamPosition.x || zbound.y & maxCamPosition.y) {
isCameraMove = false;
Vector3 fbound = new Vector3(-width / 2, -height / 2, 0).add(viewport);
if (fbound.x & 0 || fbound.y & 0) {
isCameraMove = false;
Vector3 v3 = new Vector3(mainActor.x, mainActor.y, 0);
stage.getCamera().project(v3);
Vector3 a = v3.cpy().add(vector3);
if (a.x & width || a.y & height) {
isActorMove = false;
if (a.x & 0 || a.y & 0) {
isActorMove = false;
if (isCameraMove) {
stage.getCamera().position.add(vector3);
for (Actor actor : stage.getActors()) {
if (!actor.equals(player)) {
actor.x += vector3.x;
actor.y += vector3.y;
if (isActorMove) {
player.x += vector3.x;
player.y += vector3.y;
private boolean CheckMoveable(TiledMap map, TiledLayer layer,
Vector3 vector3, Vector2 playpos) {
Vector3 pos = new Vector3(playpos.x, playpos.y, 0).add(vector3);
int nopassId = 0;
TileSet set = map.tileSets.get(map.tileSets.size() - 1);
int masSize = set.firstgid + layer.tiles.
for (int i = 0; i & masS i++) {
if ("False".equals(map.getTileProperty(i, "Pass"))) {
nopassId =
Gdx.app.log("Find!", i + " ");
int xid = MathUtils.ceilPositive(pos.x / map.tileWidth);
int yid = MathUtils.ceilPositive(pos.y / map.tileWidth);
if (layer.tiles[layer.tiles.length - yid][xid - 1] == nopassId) {
return true;
return false;
public void resize(int width, int height) {
// TODO Auto-generated method stub
public void resume() {
// TODO Auto-generated method stub
public boolean keyDown(int keycode) {
return false;
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
private void ChangeDirect(int typeId) {
switch (typeId) {
moveVector.set(0, 1, 0);
Gdx.app.log("方向变动", "向上");
moveVector.set(0, -1, 0);
Gdx.app.log("方向变动", "向下");
moveVector.set(-1, 0, 0);
Gdx.app.log("方向变动", "向左");
moveVector.set(1, 0, 0);
Gdx.app.log("方向变动", "向右");
public boolean touchDown(int x, int y, int pointer, int button) {
Vector3 tmp = new Vector3(x, y, 0);
stage.getCamera().unproject(tmp);
float newx = tmp.x - player.x;
float newy = tmp.y - player.y;
if (newx & 0 && newy & 0) {
if (newx & newy) {
ChangeDirect(4);
ChangeDirect(1);
} else if (newx & 0 && newy & 0) {
if (newx & -newy) {
ChangeDirect(4);
ChangeDirect(2);
} else if (newx & 0 && newy & 0) {
if (-newx & newy) {
ChangeDirect(3);
ChangeDirect(1);
if (-newx & -newy) {
ChangeDirect(3);
ChangeDirect(2);
isPress = true;
return false;
public boolean touchDragged(int x, int y, int pointer) {
// TODO Auto-generated method stub
return false;
public boolean touchMoved(int x, int y) {
// TODO Auto-generated method stub
return false;
public boolean touchUp(int x, int y, int pointer, int button) {
isPress = false;
Gdx.app.log("Info", "touchUp: x:" + x + " y: " + y + " pointer: "
+ pointer + " button: " + button);
return false;
最终效果:
写在最后:
1.调试好了就要在绘制前把障碍层删除。
2.注意各种坐标转化。
3.如果需要变化地图,直接操作Layer里面的那个二维数组。
本文用的检测方法只是一种可行方案而已,也可以直接看角色占的块数。
本文参考了:
阅读(...) 评论()

我要回帖

更多关于 我的世界跑酷地图下载 的文章

 

随机推荐