unity 5.5 tilemap哪个版本增加tile map

Unity 3D(5)
这里我举例的是我自己写的一些算法和代码,写的是diamond isometric tilemap.很少写这些,主要目的还是想保留代码用的,这里用的unity3d本身的GL库,下一篇我用Gizmos
using UnityE
using System.C
using UnityE
[ExecuteInEditMode]
public class TilemapEditor : MonoBehaviour {
Vector2 middleP
public Vector2
public Vector2
public Vector2[]
Vector2[] pointone=new Vector2[50];
Vector2[] pointtwo=new Vector2[50];
Vector2[] pointThree= new Vector2[50];
Vector2[] pointFour= new Vector2[50];
// Use this for initialization
void Start () {
// Handles.DrawLine(new Vector3(0,0,0),new Vector3(100,300,0));
// Update is called once per frame
void Update () {
// Debug.DrawLine(new Vector3(0,0,0),new Vector3(100,300,0));
void OnPostRender()
if(!material)
material.SetPass(0);
GL.PushMatrix();
GL.LoadOrtho();
// GL.MultMatrix(transform.localToWorldMatrix);
GL.Begin(GL.LINES);
for(int i=0; i&20;i++)
pointone[i]= Vector2.Lerp(two,one,test*i);
pointtwo[i]=Vector2.Lerp(list[0],new Vector2(two.x,two.y-(two.y-one.y)*2),test*i);
pointThree[i]=Vector2.Lerp(two,list[0],test*i);
pointFour[i]= Vector2.Lerp(one,new Vector2(two.x,two.y-(two.y-one.y)*2),test*i);
// pointone[0]= Vector2.Lerp(two,one,test);
// pointtwo[0]=Vector2.Lerp(list[0],new Vector2(two.x,two.y-(two.y-one.y)*2),test);
DrawLine(one.x,one.y,two.x,two.y);
DrawLine(list[0].x,list[0].y,two.x,two.y);
DrawLine(one.x,one.y,two.x,two.y-(two.y-one.y)*2);
DrawLine(two.x,two.y-(two.y-one.y)*2,list[0].x,list[0].y);
for(int i=0; i&20;i++)
DrawLine(pointone[i].x,pointone[i].y,pointtwo[i].x,pointtwo[i].y);
DrawLine(pointThree[i].x,pointThree[i].y,pointFour[i].x,pointFour[i].y);
GL.PopMatrix();
void DrawLine(float x1,float y1,float x2,float y2)
// GL.PushMatrix();
GL.Vertex(new Vector3(x1/Screen.width,y1/Screen.height,0));
GL.Vertex(new Vector3(x2/Screen.width,y2/Screen.height,0));
// GL.PushMatrix();
// void OnSceneGUI()
// Handles.color=Color.
// HandleUtility.Repaint();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:8045次
排名:千里之外
(2)(2)(1)(2)(3)(2)Pages: 1/3
主题 : cocos2d-x做地图能用tiledMap?渣渣,开什么玩笑,不服来辩!
级别: 新手上路
可可豆: 11 CB
威望: 11 点
在线时间: 1(时)
发自: Web Page
来源于&&分类
cocos2d-x做地图能用tiledMap?渣渣,开什么玩笑,不服来辩!&&&
cocos2d-x做地图能用tiledMap?渣渣,开什么玩笑,不服来辩!cocos2d-x的tiledMap有个很严重的问题,就是不能很好的处理遮挡!什么?你说TestCpp里有例子?那个叉腰眼镜女在树林之间穿梭的很欢乐?我详细的看了TestCpp里的例子,他里面处理层遮挡主要有两种方式:1.使用 iso-test-zorder.tmx 地图文件的,一共只有三排树,每排树就是一个单独的层,文件中分别是trees1,trees2,trees3。坑爹呢你这是,想累死美工啊,如果是100X100的地图,敢情是要做199个层么?   而且不在同一个层里的话,以后怎么做碰撞检测自动寻路之类的?渣渣方案,不适合真正的游戏,否掉。2.使用 iso-test-vertexz.tmx 地图文件的,这下是把树全都放在同一个层Trees里了。你以为这个就能解决实际问题?可里面穿来穿去的小美妞是用layer-&tileAt( ccp(29,29) ) 这个方式取的啊,这是拿地图文件里已经有的瓦片来移来移去啊。你自己做游戏的话,单机还好,可以把主角自己预先写到地图文件里,但网游呢?  你怎么知道会有多少个玩家在这个地图上跑?  把玩家画到.tmx文件里?想吓死爹啊。渣渣方案,不适合真正的游戏,否掉。好吧,那咱是不是该自己想办法解决这个问题呢?1.有了,针对上面的问题,既然.tmx文件里的cc_vertexz的automatic可以把瓦片自动Zorder排序好,我们可以创建额外的精灵sprite,然后用 tmxTiledMap-&addChild的方式把sprite给添加进去,然后在帧循环中对这个sprite修改Zorder不就可以嵌入小树林了吗?好聪明耶~现实总是残忍的,事实结果是,sprite被加进tmxTiledMap之后,不是与瓦片并列的,而是与层并列的…比如tmxTiledMap中有两个层,grass和trees,不管你sprite的值怎么改,要么在grass下面不可见,要么在所有的trees和grass之间,要么在所有的trees之上。也就是说被加进来的sprite的Zorder没有进入trees的Zorder体系中。失败。2.有的读者可能会说,你SB啊,你都知道sprite和trees并列了,那么直接把sprite添加到trees的那个层中不就可以了么?好吧,实践是检验真理的唯一标准。结果是,当我使用tmxLayer-&addChild方法后,会报错...跟到源代码里,发现有一句:CCAssert(0, \\\&addChild: is not supported on CCTMXLayer. Instead use setTileGID:at:/tileAt:\\\&);我勒个擦,直接告诉你不要使用这个方法。3.当你窃喜的看到他说要让你使用setTileGID方法,兴奋的以为找到了解决之道时,再去看看setTileGID方法的源码,不得不怒了,什么玩意啊!这方法连精灵或者节点的参数都没有,添加个毛啊,跟addChild完全是不用的用途,居然好意思写 Instead use xxx,我真是无语了。顺便说说度娘和谷哥,一查,哇咧,好多资源好多博客好多帖子啊,一细看,要么是对TestCpp的代码解释一番,要么是复制转载别人的解释,就连好几个错误都是相同的。国内的程序员同行们,给点力行不?好不容易国人出一个不错的游戏框架,大家不好好努力的话,看样子有被Unity3D搞死搞残的节奏啊。本人QQ
能解决此问题的欢迎沟通。
本帖最近评分记录: 共1条评分记录
干得漂亮,欢迎下次多提一些问题,骂的我面红耳赤,好久没被咬了。
级别: 新手上路
可可豆: 220 CB
威望: 220 点
在线时间: 87(时)
发自: Web Page
关注一下,目前还没做这种游戏
级别: 新手上路
UID: 273966
可可豆: 115 CB
威望: 110 点
在线时间: 41(时)
发自: Web Page
还有对象层里面的对象只能按照先前创建的顺序,不能后来随意更改,而且遍历的顺序就是按照这个来的,不清楚这个的话,在程序中遍历有的时候还会有问题,希望作者在下个版本中改善一下
级别: 新手上路
UID: 134515
可可豆: 21 CB
威望: 21 点
在线时间: 54(时)
发自: Web Page
mark,有时间再细看
级别: 新手上路
可可豆: 117 CB
威望: 117 点
在线时间: 11(时)
发自: Web Page
英文不好,不会google,不会stackoverflow去找,是硬伤。
级别: 圣骑士
可可豆: 3638 CB
威望: 3638 点
在线时间: 380(时)
发自: Web Page
楼主这是激将法么?引擎不支持就自己想想办法实现呗。开源引擎就这点好,不满意可以自己改呀
级别: 精灵王
可可豆: 4556 CB
威望: 4506 点
在线时间: 1471(时)
发自: Web Page
为什么不自己写一个地图编辑器,或者使用其他的现成的地图编辑器呢?“我觉着,这个地方可以这样修改,会更好一点”比起“这个东西是个垃圾”更容易让别人接受。即使围棋达到了9段,也可能被一个年长者批评“臭棋”。
级别: 圣骑士
可可豆: 2524 CB
威望: 2519 点
在线时间: 825(时)
发自: Web Page
lz提到的这些问题确实存在,tiledmap远谈不上好用,当初用的时候也很困惑,现在也没有找到好的解决方案……
级别: 侠客
可可豆: 296 CB
威望: 296 点
在线时间: 99(时)
发自: Web Page
楼主搞的好像做游戏只能tiledMap似的。你不喜欢解放鞋,不等于解放鞋没有存在的价值,买解放鞋的人多的去,关键还是看用来干什么?你参加婚礼会 西装 + 解放鞋么?
级别: 骑士
可可豆: 573 CB
威望: 573 点
在线时间: 364(时)
发自: Web Page
回 楼主(yy) 的帖子
我用cocos2d做的,也碰上了这个问题。我记得我是分开解决了。tiledMap只负责绘制场景,动态元素都是直接在cocos2d的Layer 中解决了。没有在tiledMap中实现。给你截个屏,tiledMap只用了5个层搞定。关于使用tiledMap的逻辑,我写在了楼下。翻页儿。[ 此帖被flashbulb在 21:04重新编辑 ]
图片:屏幕快照
下午8.24.15.png
Pages: 1/3
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版c# - Need to use Tiled Map editor with Unity 4.3.4 - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
J it only takes a minute:
I shifted to unity few weeks ago. I am developing a 2D platformer. For creating the maps I am using Tiled map editor from www.mapeditor.org . I have created a basic map. Included the tileSheet png and the .tmx file (saved as XML) in the Assets
of the project. I am able to read the XML , that is all the gid's. But I don't know how to access a particular portion(tile) from the tileSheet corresponding to a gid.
I think for this I need to load sprite in the memory and select a tile (by specifying Height and width and coords) from texture memory to display it on screen. As given here :
but its for flash , how I can achieve same thing in Unity using C#. Notice the copyPixel stuff in the flash code. I thought I could use ReadPixels but it is used for reading from screen only not the texture memory.
If you're working in Windows then the
sounds like it will fit your needs. It exports Object Layers and was made with Unity 4.3 features in mind.
(Full disclosure: I'm the author of Tiled2Unity)
If you can describe more carefully your problem and what you are trying to do, maybe myself or someone can help you better,
for example what exactly do you mean by "load a sprite into memory"?
Or "select a tile"?
Copying pixel data is SLOWWW, and hopefully you don't mean to be doing this in real time.
Here is my real advice though:
Have you checked out UTiled?
It does tiled maps in 2D in Unity so I think it already does what you want and it's free.
There is also UniTMX... free.
There is also 'Tiled Tilemaps'... which is like $2.
I also built a system that can also do what I think you are trying to do
(your link is broken, so I can't be sure).
The system I built is called '' (you can search it in youtube to see if it does what you want).
It allows you to attach gameObjects to tiles and have tile variants, and can do 3D tiles.
Anyway, trying to roll your own pipeline from Tiled into Unity is a ton of work, and with these tools available, I think it is almost certainly unnecessary...
That's just imo.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
rev .25026
Stack Overflow works best with JavaScript enabledA Bitwise Method For Applying Tilemaps
Posted on&
A technique for automatically selecting the correct tile from a tilemap.
I originally wrote this as a reply to&&and I figure it’s worthy of expanding and repeating here.
The problem: We have generated a neat platformer level, and want to be able to automatically lay neighbour-sensitive tiles over it so that they fit properly.
Neighbour Sensitive Tiles
Super Mario’s tiles are not &the stone block always looks the same if it’s floating alone or if it’s part of a wall.
That’s fine for many games, but can look out of place if you’re trying to create a more organic feel in a level, or just wanting to cut down on repeated patterns. &Neighbour sensitive tiles overcome this by matching their appearance to the presence of their
neighbours.
A 1-bit Map
Let’s imagine that with some clever techniques we have generated a level layout for a platformer game that consists of either stone or empty air at each grid location. &This can be represented as a 1-bit image – that is each pixel’s state will be determined
by a single bit, so either on indicating rock or off to indicate open air. &Here’s a section of such a map, greatly enlarged and with grid lines added:
A tile set is simply a collection of the graphics that may be used to fill in a map. &Mario’s tileset is quite small, consisting of just a few different types of block and scenery, whilst ours will have many graphics for the same type of tile:
Valuing Neighbours
To determine which tile should go at each spot on the map, we shall examine that spot’s immediate neighbours (for now we’ll ignore diagonal neighbours.) &Rather than writing a huge if/else-if statement to handle all the possible combinations of neighbours,
we will use a system that assigns values to each direction.
A value is found for each location by looking at its neighbours and adding up the values for whichever ones have stone present. &So if the spot we’re examining has a neighbour above it that is also filled with stone then it is given the value 1. &If it has
stone-filled neighbours above and below then the value is 1 + 4, so 5.
You may notice that the values assigned to the directions are the same as the values of the positions in a binary number and both are ways of representing possible combinations of 4 units which can each be in an on or off (stone or air)
Here is the map segment with the value of each tile filled in. &You might like to manually work out the value for a couple of the tiles yourself so you’re clear on how it works.
Adding the Tiles
The order in which the tileset is laid out above is not& it is laid out so that each tile matches what would be expected of a tile in the map that would be assigned that value. &Once we have a value assigned for each spot on the map we just need to
look up that number in the tileset and place the correct tile there:
Wonderful!
Taking it Further
Part One – Removing Air
Whilst the above works very neatly for platforms floating in air, it doesn’t yet fully handle two tile types.
Instead of a platformer imagine we’re working on a top-down 2D RTS with two tile types of grass and water. &In such a case we would expect every spot on the map to have a
there’s no open spaces like in our platformer. &This means that
every spot on the map will need to have a value generated from its neighbours to determine which tile fits there.
We can use exactly the same neighbour valuing system as before, but we now need a way to differentiate between there being grass or water at the spot being examined itself. &This is actually very simply done – just add an extra value for the location itself,
following the same 2 to the power of n pattern from the other values:
Let’s decide that the presence of water means you do add on that position’s value, whilst the presence of grass means you do not. &So a grass tile surrounded on all sides by grass would be numbered at 0. &A grass tile with water to the top and left would be
1 + 8 = 9. &A water tile surrounded on all sides by grass would be 16. &A water tile with water on all sides would be 1 + 2 + 4 + 8 + 16 = 31
Part Two – Greater Variety
How do we handle adding additional types of terrain?
Let’s say we have three types of terrain in our top-down game: water, grass, and forest. &As well as water and grass meeting, we must now also deal with water and forest meeting as well as grass and forest meeting.
Previously there was two possibilities for each neighbour position (grass or water) so we used a&binary counting system.
&There’s now three possibilities so we shall use a&trinary counting system. &Our neighbour valuing system needs to be adjusted
to match the new counting system:
Just as the binary counting system followed the pattern of 2 to the power of n, this follows the pattern of 3 to the power of n.
Using a trinary system each position has three possible states: grass, water, or 0, 1, 2. &When there is grass in a given position, we ignore the value (multiply it by 0). &When there is water in the position we add on the value given (multiply it by
1). &When there is forest in the we add on twice the value (multiply it by 2.)
So if we had a tile that was forest with water above it, water to the right, forest below and grass to the left: 81 * 3 + 1 * 2 + 3 * 1 + 9 * 3 + 27 * 0 = 275
You might notice at this point that you’ll need to draw 324 tile graphics to cover all the possible combinations in a three-terrain map. &This is a lot of tiles to draw by hand. &I would strongly advise looking into at least partially automated methods of producing
the multitude of tile combinations.
Of course the system can be extended in just the same way for greater numbers of terrain types, but the number of tile graphics you would need would be even more huge. &Instead I would recommend placing some limits on what tiles are allowed to neighbour one-another.
&For instance if forest and water tiles are never allowed to directly touch then the above example will need several hundred less tile graphics.
原址:/2010/a-bitwise-method-for-applying-tilemaps/
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1263次
排名:千里之外}

我要回帖

更多关于 unity easy tile map 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信