码迷,mamicode.com
首页 > 其他好文 > 详细

u3d 2d序列动画代码

时间:2015-03-06 16:59:17      阅读:118      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!