首页 > 其他 > 详细

u3d 2d序列动画代码

时间:2015-03-06 16:59:16      阅读:217      评论:0      收藏:0      [点我收藏+]
using UnityEngine;
using System.Collections;
 
public class AniSprite : MonoBehaviour {
 
    private float myTime = 0;
    private bool isPlay = true;
    //anisprit.Sprite(4, 6, 0, 0, 20, 24, 1f);的意思是:改图是一个4列6行的动画图,图以坐标(0,0)开始,总帧数给定20帧,帧速率24,总用时1秒
    public bool Sprite(int columnSize,int rowSize, float colFrameStart, float rowFrameStart, int totalFrames, int framesPerSecond, float totalTime)
    {
        myTime += Time.deltaTime;
        if (totalTime != 0 && myTime > totalTime)
        {
            isPlay = false;
            myTime = 0;
            return isPlay;
        }
        int index = (int)(Time.time * framesPerSecond)% totalFrames;
 
        Vector2 size = new Vector2(1.0f/columnSize,1.0f/rowSize);
 
        int u = index % columnSize;
        int v = index / columnSize;
 
        Vector2 offset = new Vector2((u + colFrameStart) * size.x, (1.0f - size.y) - (v + rowFrameStart) * size.y);
        renderer.material.mainTextureScale = size;
        renderer.material.mainTextureOffset = offset;
        return true;
    }
}

 

u3d 2d序列动画代码

原文:http://www.cnblogs.com/ershiqibeijiu/p/4318647.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!