图片精灵sprite动画插件
来源:互联网 发布:逐浪cms怎么样 编辑:程序博客网 时间:2024/05/16 06:20
好久好久没有写博客了,最近写了俩个小插件,这是其中一个。
我想大家在玩游戏的时候会看到人物走动,这些不管在3d还是2d游戏都会有这些动画,这些动画都有一个小单元一个小单元拼凑吹来的,这个小单元就是精灵,用js或者一些游戏引擎或者是用一些制作游戏的工具不如unity3D会有自带动画制作工具,都可以实现,这里主要由js来实现这一点,毕竟我只是个小前端~
首先我们需要知道UI给到我们的图片是什么样子的,然后根据UI给过来的图进行参数的处理。
我们先来看看那js吧
var spriteDemo = { rowCount:0, lastColCount:0, param:{}, currentCount:0, currentIndex:{rows:0,columns:0}, inifiteSave:"", initFunc:function(option){ this.param=option; this.rowCount=Math.floor((option.spriteLength-0)/(option.unitLength-0)); this.lastColCount=(option.spriteLength-0)%(option.unitLength-0)==0?option.unitLength-0:(option.spriteLength-0)%(option.unitLength-0);//获取最后一行的个数 var _this=this; this.inifiteSave = setInterval(function(){_this.aniFunc()},option.speed);// _this.aniFunc(); }, aniFunc:function(){ this.currentIndex.columns+=1; if(this.param.count!=""&&this.param.count!="auto"){ if(this.currentCount>this.param.count){ clearInterval(this.inifiteSave); return false; } } if((this.currentIndex.columns>(this.param.unitLength-1)&&this.currentIndex.rows<this.rowCount-1)){ this.currentIndex.rows++; this.currentIndex.columns=0; }else if((this.currentIndex.rows==this.rowCount-1)&&this.currentIndex.columns==this.lastColCount){ this.currentIndex.rows=0; this.currentIndex.columns=0; this.currentCount++; } this.param.targetDom.style.backgroundPosition="-"+(this.currentIndex.columns*this.param.unitArea.width+this.param.initPos.x)+"px -"+(this.currentIndex.rows*this.param.unitArea.height+this.param.initPos.y)+"px"; } };
这里就是全部的js了,你肯定会觉得,这么点js也算是一个插件了?您先别急,听我后面的给您介绍介绍这些参数哈。option代表需要传递的参数option={spriteLength:spriteLength,unitLength:unitLength,unitArea:unitArea,speed:speed,count:count,initPos:initPos,targetDom:targetDom}然后介绍一下里面具体的参数,spriteLength总共的精灵个数,unitLength单行的精灵个数,unitArea指的是每一个精灵的大小,speed速度,count运行的次数,initPos初始的位置,targetDom当前元素。
看了这些参数介绍大家应该都已经知道了这个函数的原理了,这里我就不在瞎比比了。希望此博客了对你有帮助。
0 0
- 图片精灵sprite动画插件
- Sprite Animations精灵动画
- 02 Sprite 图片精灵
- Sprite精灵帧图片
- cocos2d-x 3.2 |如何实现图片显示和精灵动画 Sprite
- NGUI Sprite精灵与精灵动画的使用
- NGUI研究之Sprite精灵与精灵动画的使用
- cocos3.3 lua sprite 精灵 修改 图片
- Sprite(精灵)
- Sprite精灵
- KING_UNITY学习之Unity2D代码动态为Sprite Renderer的Sprite赋值sprite精灵图片
- Direct3D学习笔记(二)——精灵动画(Sprite)
- sprite动画精灵中主要及常用的变量
- 免费的Sprite精灵图片,可以随便用。SpriteLib
- css sprite 图片整合处理技术(精灵技术)
- NGUI研究院之Sprite精灵与精灵动画的使用(二)
- NGUI研究院之Sprite精灵与精灵动画的使用(二)
- NGUI研究院之Sprite精灵与精灵动画的使用(二)
- Mysql存储过程——多结果集返回与java获取
- elasticsearch 集群搭建
- RecyclerView 实现点击的另外一种方式
- tmp
- 何求若求
- 图片精灵sprite动画插件
- linux mysql安装与维护
- 一些简单的小功能函数
- 城市查询-拼音、全拼、简拼、混拼、卷舌音、前后鼻音、兼容查询C#与nodejs+redis应用---笔记
- oracle 存储过程之游标(loop)使用
- 建议3: 区别对待强制转型与as和is
- A*B Problem
- Linux驱动开发-中断分层机制_工作队列 笔记 7
- js实现无刷新评论