查看: 2192|回复: 4
打印 上一主题 下一主题

[其他] 经典精灵动画脚本

[复制链接]

2722

主题

42

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
38266
精华
111

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2014-11-14 01:10:48 |只看该作者 |倒序浏览

下面的脚本是经典精灵动画,还经常用吧,简单备忘一下

// Animation Sprite Sheet
// Walker Boys (www.walkerboystudio.com)
// March 18, 2011
// Description: Plays an animated sprite using a sprite sheet
// Instruction: Assign script to a gameObject with a material/texture (sprite sheet)
// Function arguments:
// columnSize      - number of frames across (horizontal)
// rowSize         - number of frames down (vertical)
// colFrameStart   - where frame starts (remember 0 is first number in counting)
// rowFrameStart   - where frame starts (remember 0 is first number in counting)
// totalFrames     - number of frames in the animation (count regular)
// framesPerSecond - how fast do you want it to play through (Standard: 12 - 30 fps)

function aniSprite (columnSize, rowSize, colFrameStart, rowFrameStart, totalFrames, framesPerSecond)// function for animating sprites
{
        var index : int = Time.time * framesPerSecond;                                                                                                        // time control fps
        index = index % totalFrames;                                                                                                                                        // modulate to total number of frames
       
        var size = Vector2 ( 1.0 / columnSize, 1.0 / 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
       
        //renderer.material.SetTextureOffset ("_BumpMap", offset);                                                                                // texture offset for bump (normal map)
        //renderer.material.SetTextureScale  ("_BumpMap", size);                                                                                        // texture scale  for bump (normal map)
}

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

115

主题

3

听众

5676

积分

高级设计师

Rank: 6Rank: 6

纳金币
7268
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2014-11-14 09:06:24 |只看该作者
Thanks for sharing this one !
回复

使用道具 举报

hyui    

1

主题

2

听众

6671

积分

高级设计师

Rank: 6Rank: 6

纳金币
2715
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2014-11-14 15:39:25 |只看该作者
Thaks for this !
回复

使用道具 举报

7

主题

0

听众

2518

积分

中级设计师

Rank: 5Rank: 5

纳金币
317
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2014-11-14 17:51:01 |只看该作者
感謝狂風大衛大人!!
回复

使用道具 举报

100

主题

3

听众

7683

积分

高级设计师

Rank: 6Rank: 6

纳金币
2378
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2014-11-14 21:25:16 |只看该作者
Thanks for sharing this one !
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-18 08:58 , Processed in 0.087116 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部