| 赞 | 58 |
| VIP | |
| 好人卡 | |
| 积分 | 2 |
| 经验 | |
| 最后登录 | 2026-10-16 |
| 在线时间 | 1037 小时 |
- 梦石
- 0
- 星屑
- 196
- 在线时间
- 1037 小时
- 注册时间
- 2021-3-24
- 回帖
- 548

|
楼主 |
发表于 2022-1-24 17:31:05
|
显示全部楼层
创建 精灵类
精灵可以根据正弦做简谐运动,(需要自己配),并且规定做几个周期。
- var LIM=LIM||{};//;
- LIM.CS=LIM.CS||{};//;
- (function(_) {//;
- _.Sprite = function () {this.initialize.apply(this, arguments);}
- _.Sprite.prototype = Object.create(Sprite.prototype);
- _.Sprite.prototype.constructor = _.Sprite
- _.Sprite.prototype.initialize = function(data){
- this._data=data
- Sprite.prototype.initialize.call(this);
- this.scale.x=this.Size()
- this.scale.y=this.Size()
- this._anchor.x=this.AnchorX()
- this._anchor.y=this.AnchorY()
- this.x=this.MarginLeft()
- this.y=this.MarginTop()
- this._anime=[]
- if(data[6]>-1) this.setChartlet(data[6])
- if(data[7]>-1) this.setAnime(data[7])
- };
- _.Sprite.prototype.setAnime=function(index){
- if (this._anime.length > 0) {
- this._anime =[this._anime[0]]
- this._anime[0].times=2
- this._anime[0].time=this._anime[0].cycle*2-this._anime[0].time/2
- this._anime[0].trigger=null
- }
- else this._anime = []
- if(this.Action()&&this.Action()[index]) {
- let data=this.Action()[index]
- this._anime.push({mode:data.mode,method:data.method,time:0,cycle:data.cycle,ter:data.ter,
- trigger:data.trigger,times:(data.count?data.count+1:0)})
- }
- }
- _.Sprite.prototype.setChartlet=function (index) {
- if (this.Chartlet().length&&index>-1) {
- this.bitmap = ImageManager.loadUi(this.Chartlet()[index % this.Chartlet().length])
- this._refresh()
- }
- }
- _.Sprite.prototype.Trigger=function(code){}
- _.Sprite.prototype.Reborn=function(){
- if (this._anime.length > 0) {
- if (this._anime[0].times == 1) {
- let trigger = this._anime[0].trigger
- this._anime.splice(0, 1)
- if (trigger) this.parent.Trigger(trigger);
- }
- else {
- let num = LIM.MATH.sinNum(this._anime[0].cycle, this._anime[0].time++)
- num = (this._anime[0].method == 1 ? Math.abs(num) : this._anime[0].method == 2 ? num * num : num)
- if (Math.abs(this._anime[0].time - (this._anime[0].cycle / 2 * this._anime[0].ter)) < 1) {
- this._anime[0].times--;
- this._anime[0].time = 0
- }
- this.expressAnime(num, this._anime[0].mode)
- }
- }
- }
- _.Sprite.prototype.expressAnime=function(num,mode) {
- switch (mode) {
- case "shoadow":
- this._colorTone = [80 * num, 80 * num, 80 * num, 0]
- break
- case "rote":
- this.rotation = num*Math.PI
- break
- case "rote2":
- this.rotation = num*Math.PI*2
- break
- case "rote3":
- this.rotation = num*Math.PI/2
- break
- case "wobble":
- this.rotation = num*Math.PI/24
- this._anchor.y=this.AnchorY()+(num*num)*0.1
- break
- case "arouse":
- this.scale.x = num / 2 + 0.5
- this.scale.y = num / 2 + 0.5
- break
- case "countDown":
- this.scale.x = num / 2 + 0.5
- this.scale.y = num / 2 + 0.5
- this.alpha = 1 - num
- break
- }
- this._refresh()
- }
- _.Sprite.prototype.Chartlet = function() {return this._data[0]||[]};
- _.Sprite.prototype.MarginLeft = function() {return LIM.MATH.lengthNumW(this._data[1]||0)};
- _.Sprite.prototype.MarginTop = function() {return LIM.MATH.lengthNumH(this._data[2]||0)};
- _.Sprite.prototype.AnchorX = function() {return this._data[3][0]||0.5};
- _.Sprite.prototype.AnchorY = function() {return this._data[3][1]||0.5};
- _.Sprite.prototype.Action = function() {return this._data[4]||[]};
- _.Sprite.prototype.Size = function() {return this._data[5]||1};
- _.Sprite.prototype.hide=function () {
- this.alpha=0
- this.active=false
- }
- _.Sprite.prototype.show=function () {
- this.alpha=1
- this.active=true
- }
- })(LIM.CS)
复制代码
/////////////////////////////////////////////////////////////
正弦波
- _.sinNum=function(max,i){return Math.sin(Math.PI/2/max*i).toFixed(7)}
复制代码
/////////////////////////////////////////////////////////////
添加精灵 后的 菜单实例方法
- function Scene_Game() {this.initialize.apply(this, arguments);}//;
- Scene_Game.prototype = Object.create(LIM.CS.Scene.prototype)//;
- Scene_Game.prototype.constructor = Scene_Game//;
- Scene_Game.prototype.Back=function() {
- return "bg"
- }
- Scene_Game.prototype.createTxt=function(){
- this._txt=new Map()
- let t1=new LIM.CS.Txt(["tile",10,"100%-112",932,92,20,30,20,"#765fff","#f0b",4])
- t1.paintText("大本钟下送快递",0)
- t1.paintText("上面摆 下面寄",1)
- this._txt.set(1,[t1])
- this.addChild(t1)
- }
- Scene_Game.prototype.createSprite=function(){
- this._spr=new Map()
- let s1=new LIM.CS.Sprite([["gg"],250,250,[0.5,0.5],[{mode:"wobble",cycle:60,trigger:null,times:0,ter:8,method:0}],0.5,0,0])
- this._spr.set(1,[s1])
- this.addChild(s1)
- this.spriteSwitch.set(1,true)
- }
复制代码
参数解释
[
["gg"], 图案组
250, x坐标
250, y坐标
[0.5,0.5], 锚点
[{mode:"wobble",cycle:60,trigger:null,times:0,ter:8,method:0}], 动作 mode[动作类型] cycle[周期速度] trigger[动作结束触发] times周期数 ter[峰值] methgod[正弦波模式]
0.5, 缩放
0, 初始图案
0 初始动作
]
总之就是能搞出各种效果是了
|
|