unity做2d必备
2012-12-05 13:41
183 查看
//这个方法只适合横向的序列图片 private var startFrame:int; function animationBase(columnSize : int , colFrameStart : int ,sizeY:float, offsetY:float , frames : int)// function for animating sprites { // modulate to total number of frames startFrame ++; var size:Vector2 =new Vector2 ( 1.0f / columnSize, sizeY); renderer.material.mainTextureScale = size; if(startFrame % frames == 0) { var u:float = startFrame/frames; if(u >= columnSize) { u = 0; startFrame = 0; } var offset = Vector2 ((u + colFrameStart) * size.x, offsetY); // v gets current y coordinate by dividing by column size renderer.material.mainTextureOffset = offset; // texture offset for diffuse map(漫反射) } print(startFrame + "--" +sizeY); // texture scale for diffuse map // texture scale for bump (normal map) } private var startTime : float; function aniSprite (columnSize : int , rowSize : int, colFrameStart : int , rowFrameStart : int , totalFrames : int, framesPerSecond : int, isStart: boolean)// function for animating sprites { if(isStart) { startTime = Time.time; } var index : int = (Time.time-startTime) * framesPerSecond; // time control fps index = index % totalFrames; // modulate to total number of frames var size = Vector2 ( 1.0f / columnSize, 1.0f / rowSize); // scale for column and row size var u = index % columnSize; // u gets current x coordinate from column size var v = index / columnSize; // v gets current y coordinate by dividing by column size var offset = Vector2 ((u + colFrameStart) * size.x,(1.0 - size.y) - (v + rowFrameStart) * size.y); // offset equals column and row renderer.material.mainTextureOffset = offset; // texture offset for diffuse map(漫反射) renderer.material.mainTextureScale = size; // texture scale for diffuse map if(u == totalFrames-1) { return true; } else { return false; } //renderer.material.SetTextureOffset ("_BumpMap", offset); // texture offset for bump (normal map)(法线贴图) //renderer.material.SetTextureScale ("_BumpMap", size); // texture scale for bump (normal map) }
相关文章推荐
- Unity2D屏幕适配方案
- Unity_2D系统_023
- Unity 3d转2d再转3d
- Uni2D Unity4.3 2D Skeletal Animation
- unity2d创建一个随机方向运动对象
- Unity_2D游戏对象的移动_075
- Unity即将到来的2D工具
- Collider2D碰撞检测异常-Rotating sprite does not rotate collider[Unity]
- Unity4.3.4_2D—刚体移动
- 使用 Unity 3D 製作 2D 遊戲的重點做法
- 独立开发unity2d游戏的问答群
- Unity + NGUI开发2D游戏的笔记。
- Unity使用代码控制2d游戏物体(一)
- unity初写游戏(一)2D界面GUIText
- Unity2d 弱联网游戏制作(二) 动画、场景、渲染层、碰撞检测、音乐播放
- Unity 2D游戏开发教程之2D游戏的运行效果
- unity 2D 透明遮罩 简单实现
- Unity 4.x 2D游戏开发基础教程
- Unity 4.x 2D游戏开发基础教程大学霸第一更
- unity 2D中的向着鼠标点击方向进行射击