Corona SDK + Tiled + Ceramic Tile Engine:创建碰撞图? [英] Corona SDK + Tiled + Ceramic Tile Engine : Create Collision Map?

查看:76
本文介绍了Corona SDK + Tiled + Ceramic Tile Engine:创建碰撞图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的基于图块的游戏,其中包括:

I'm making a simple tiled-based game, with a:

  • 具有碰撞层的瓷砖地图(由Tiled制作,并加载陶瓷瓷砖引擎)
  • 在地图内移动的角色

我想做的是:在Tile Map中移动角色,同时注意Tile Map中的碰撞层.

What I want to do: Move character around in Tile Map, with respecting collision layer in Tile Map.

这是代码:

-- Load Map
local ceramic = require("Ceramic")
local map = ceramic.buildMap("maps/map.lua")


-- Create Character
hero = display.newImage("images/man.png")
hero.x = 0
hero.y = 0
map.layer['World']:insert(hero)

-- Create buttons
btnLeft = display.newImage("images/btnLeft.png", 10, 10)
btnRight = display.newImage("images/btnRight.png", 150, 10)

-- Button Event Listeners
btnLeft:addEventListener("tap", moveLeft)
btnRight:addEventListener("tap", moveRight)

-- Button functions
function moveLeft()
    hero.x = hero.x - 50
end

function moveRight()
    hero.x = hero.x + 50
end

问题是,地图与字符分开.如何将角色放入"地图?我想念什么?

The problem is, the map is separate with the character. How can I put the character "into" the map? What did I miss?

注意:图块地图是自上而下的角度.

Note: the tile map is Top-Down angle.

注意:该地图分为4层:背景,世界,门,碰撞,我希望玩家不要进入碰撞层的区域.

Note: The Map has 4 layers: Background, World, Doors, Collision, and I want player NOT to walk into Collision layer's areas.

推荐答案

为使玩家发生碰撞,您需要实现某种类型的碰撞检测-无论是否具有物理条件.

In order for the player to collide, you'll need to implement some type of collision detection - whether it be with or without physics.

这意味着您可以...

Which means you can either...

  1. 创建非物理碰撞系统,并检查附近的可碰撞"砖块
  2. 在您的地图中实现Corona的Box2D物理.

Nota Bene:使用Ceramic时,使用Box2D更容易,但是一旦Twilight Engine出现,非物理碰撞将更易于使用.

在这里,我仅提供Box2D的过程.通过简单地将单个图块物理化或将整个层的图块物理化,可以非常简单地完成此操作.可以通过编辑图块属性并在其中添加physics:enabled = true来使单个图块成为物理的.要查看有关物理学的更深入的解释,可以查看此链接.它也适用于单个图块.

Here I'll only give the procedure for Box2D. It's done quite simply by either making single tiles physical or making an entire layer's tiles physical. Single tiles can be made physical by editing the tile properties and adding physics:enabled = true in them. To see a slightly more in-depth explanation about physics, you can check out this link. It also applies to single tiles.

您可以通过将该属性添加到图层的属性列表中来使整个图层变为物理图层;要更改单个图块的物理身体,请编辑图块特定的属性.

You can make entire layers physical by adding that property to your layer's property list; to change single tiles' physical body, edit the tile-specific properties.

这篇关于Corona SDK + Tiled + Ceramic Tile Engine:创建碰撞图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆