This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcftTrans.monkey
executable file
·444 lines (414 loc) · 13 KB
/
cftTrans.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#rem
Title: fantomEngine
Description: A 2D game framework for the Monkey programming language
Author: Michael Hartlef
Contact: michaelhartlef@gmail.com
Website: http://www.fantomgl.com
License: MIT
#End
Import fantomEngine
Import cftTween
'nav:<blockquote><nav><b>fantomEngine documentation</b> | <a href="index.html">Home</a> | <a href="classes.html">Classes</a> | <a href="3rdpartytools.html">3rd party tools</a> | <a href="examples.html">Examples</a> | <a href="changes.html">Changes</a></nav></blockquote>
#Rem
'header:The class [b]ftTrans[/b] controls the way an object or layer does a transition. Starting with version 1.49, it utilizes the tween class from the
'monkey sample script in bananas/skn3/tweening/tween.monkey
#End
'#DOCOFF#
'***************************************
Class ftTransEntry
Field typ:Int
Field x:Float
Field y:Float
Field rot:Float
Field alpha:Float
Field scale:Float
Field duration:Float
Field timeLapsed:Float = 0.0
Field s_x:Float
Field s_y:Float
Field s_rot:Float
Field s_alpha:Float
Field s_scale:Float
Field e_x:Float
Field e_y:Float
Field e_rot:Float
Field e_alpha:Float
Field e_scale:Float
Field obj:ftObject = Null
Field layer:ftLayer = Null
'------------------------------------------
Method Update:Void(delta:Int, tween:Tween)
timeLapsed += delta
If obj <> Null Then
If delta = -1 Then
Select typ
Case 1
obj.SetPos(e_x, e_y, False)
Case 2
obj.SetAngle(e_rot, False)
Case 3
obj.SetScale(e_scale, False)
Case 4
obj.SetAlpha(e_alpha, False)
End
Else
Select typ
Case 1
'obj.SetPos(x * delta, y * delta, True)
'obj.SetPos(tween.equation.Call(timeLapsed, s_x, e_x - s_x, duration), tw.equation.Call(timeLapsed, s_y, e_y - s_y, duration), false)
obj.SetPosX(tween.equation.Call(timeLapsed, s_x, e_x - s_x, duration))
obj.SetPosY(tween.equation.Call(timeLapsed, s_y, e_y - s_y, duration))
Case 2
obj.SetAngle(rot * delta, True)
Case 3
obj.SetScale(scale * delta, True)
Case 4
obj.SetAlpha(alpha * delta, True)
End
Endif
Else
If delta = -1 Then
Select typ
Case 1
layer.SetPos(e_x, e_y, False)
'Case 2
'layer.SetAngle(e_rot, False)
Case 3
layer.SetScale(e_scale, False)
Case 4
layer.SetAlpha(e_alpha, False)
End
Else
Select typ
Case 1
layer.SetPos(x*delta, y*delta, True)
'Case 2
'layer.SetAngle(rot*delta, True)
Case 3
layer.SetScale(scale*delta, True)
Case 4
layer.SetAlpha(alpha*delta, True)
End
Endif
Endif
End
End
'#DOCON#
'***************************************
Class ftTrans
'#DOCOFF#
Field entryList := New List<ftTransEntry>
'Field startTime:Int
'Field lastTime:Int=0
Field currTime:Int=0
'Field endTime:Int=0
'Field deltaTime:Int=0
Field duration:Int
Field finishID:Int
Field obj:ftObject=Null
Field layer:ftLayer=Null
Field engine:ftEngine = Null
Field transNode:list.Node<ftTrans> = Null
Field deleted:Bool = False
Field isPaused:Bool = False
Field tween:Tween
Field equations:String[] = ["Linear","Back","Bounce","Circ","Cubic","Elastic","Expo","Quad","Quart","Quint","Sine"]
Field easeTypes:String[] = ["EaseIn","EaseOut","EaseInOut"]
Field currentEquation:Int
Field currentEaseType:Int
'-----------------------------------------------------------------------------
Method AddAlpha:Void(alpha:Float, obj:ftObject, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 4
transEntry.s_alpha = obj.alpha
If relative = True Then
transEntry.e_alpha = alpha + obj.alpha
Else
transEntry.e_alpha = alpha
Endif
transEntry.alpha = (transEntry.e_alpha - obj.alpha) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = obj
transEntry.layer = Null
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddAlpha:Void(alpha:Float, layer:ftLayer, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 4
transEntry.s_alpha = layer.alpha
If relative = True Then
transEntry.e_alpha = alpha + layer.alpha
Else
transEntry.e_alpha = alpha
Endif
transEntry.alpha = (transEntry.e_alpha - layer.alpha) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = Null
transEntry.layer = layer
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddPos:Void(xt:Float, yt:Float, obj:ftObject, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 1
transEntry.s_x = obj.xPos
transEntry.s_y = obj.yPos
If relative = True Then
transEntry.e_x = xt + obj.xPos
transEntry.e_y = yt + obj.yPos
Else
transEntry.e_x = xt
transEntry.e_y = yt
Endif
transEntry.x = (transEntry.e_x - obj.xPos) / duration
transEntry.y = (transEntry.e_y - obj.yPos) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = obj
transEntry.layer = Null
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddPos:Void(xt:Float, yt:Float, layer:ftLayer, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 1
transEntry.s_x = layer.xPos
transEntry.s_y = layer.yPos
If relative = True Then
transEntry.e_x = xt + layer.xPos
transEntry.e_y = yt + layer.yPos
Else
transEntry.e_x = xt
transEntry.e_y = yt
Endif
transEntry.x = (transEntry.e_x - layer.xPos) / duration
transEntry.y = (transEntry.e_y - layer.yPos) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = Null
transEntry.layer = layer
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddRot:Void(rot:Float, obj:ftObject, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 2
transEntry.s_rot = obj.angle
If relative = True Then
transEntry.e_rot = rot + obj.angle
Else
transEntry.e_rot = rot
Endif
transEntry.rot = (transEntry.e_rot - obj.angle) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = obj
transEntry.layer = Null
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddScale:Void(sca:Float, obj:ftObject, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 3
transEntry.s_scale = obj.scaleX
If relative = True Then
transEntry.e_scale = sca + obj.scaleX
Else
transEntry.e_scale = sca
Endif
transEntry.scale = (transEntry.e_scale - obj.scaleX) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = obj
transEntry.layer = Null
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method AddScale:Void(sca:Float, layer:ftLayer, duration:Float, relative:Int )
Local transEntry:ftTransEntry = New ftTransEntry
transEntry.typ = 3
transEntry.s_scale = layer.scale
If relative = True Then
transEntry.e_scale = sca + layer.scale
Else
transEntry.e_scale = sca
Endif
transEntry.scale = (transEntry.e_scale - layer.scale) / duration
transEntry.duration = duration
transEntry.timeLapsed = 0.0
transEntry.obj = Null
transEntry.layer = layer
entryList.AddLast(transEntry)
End
'-----------------------------------------------------------------------------
Method Cancel:Void()
Self.Clear()
Self.transNode.Remove()
Self.transNode = Null
Self.obj = Null
Self.engine = Null
Self.layer = Null
End
'------------------------------------------
Method Clear:Void()
For Local entry := Eachin entryList
entry.obj = Null
entry.layer = Null
Next
entryList.Clear()
End
'#DOCON#
'------------------------------------------
'summery:Returns TRUE if a transition is paused.
'seeAlso:SetPaused
Method GetPaused:Bool()
Return Self.isPaused
End
'------------------------------------------
'#DOCOFF#
Method New()
tween = New Tween(Tween.Linear,0,1,2000)
tween.Start()
End
'#DOCON#
'------------------------------------------
'summery:With this method you can pause and resume the transition.
'seeAlso:GetPaused
Method SetPaused:Void(pauseFlag:Bool = True)
Self.isPaused = pauseFlag
End
'------------------------------------------
#Rem
'summery:Sets the equation type of a transition.
This command sets the equation type of a transition. The equation type can be:
[list][*]Linear
[*]Back
[*]Bounce
[*]Circ
[*]Cubic
[*]Elastic
[*]Expo
[*]Quad
[*]Quart
[*]Quint
[*]Sine[/list]
#End
'seeAlso:SetEase
Method SetType(equationType:String="Linear")
currentEquation = 0
For Local i:Int = 0 To equations.Length()
If equations[i] = equationType Then
currentEquation = i
Exit
Endif
Next
SetEquation1()
End
'------------------------------------------
#Rem
'summery:Sets the ease type of a transition.
This command sets the ease type of a transition. The ease type can be:
[list][*]EaseIn
[*]EaseOut
[*]EaseInOut[/list]
#End
'seeAlso:SetType
Method SetEase(easeType:String="EaseIn")
For Local i:Int = 0 To easeTypes.Length()
If easeTypes[i] = easeType Then
currentEaseType = i
Exit
Endif
Next
SetEquation1()
End
'#DOCOFF#
'------------------------------------------
Method SetEquation1()
Select equations[currentEquation]
Case "Linear"
tween.SetEquation(Tween.Linear)
tween.Rewind()
tween.Start()
Case "Back"
SetEquation2(Tween.Back)
Case "Bounce"
SetEquation2(Tween.Bounce)
Case "Circ"
SetEquation2(Tween.Circ)
Case "Cubic"
SetEquation2(Tween.Cubic)
Case "Elastic"
SetEquation2(Tween.Elastic)
Case "Expo"
SetEquation2(Tween.Expo)
Case "Quad"
SetEquation2(Tween.Quad)
Case "Quart"
SetEquation2(Tween.Quart)
Case "Quint"
SetEquation2(Tween.Quint)
Case "Sine"
SetEquation2(Tween.Sine)
End
End
'------------------------------------------
Method SetEquation2(equation:TweenEquation)
Select easeTypes[currentEaseType]
Case "EaseIn"
tween.SetEquation(equation.EaseIn)
tween.Rewind()
tween.Start()
Case "EaseOut"
tween.SetEquation(equation.EaseOut)
tween.Rewind()
tween.Start()
Case "EaseInOut"
tween.SetEquation(equation.EaseInOut)
tween.Rewind()
tween.Start()
End
End
'------------------------------------------
Method Update:Void()
Local oldCurrTime:Int
Local deltaTime:Int
If deleted = False Then
oldCurrTime = currTime
currTime = engine.time
deltaTime = currTime - oldCurrTime
If engine.isPaused <> True And Self.isPaused <> True Then
duration -= deltaTime
If duration <= 0 Then
For Local entry := Eachin entryList
entry.Update(-1, Self.tween)
Next
If finishID <> 0 Then
If obj <> Null Then
engine.OnObjectTransition(finishID, obj)
Else
engine.OnLayerTransition(finishID, layer)
Endif
Endif
Self.deleted = True
Else
For Local entry := Eachin entryList
entry.Update(deltaTime, Self.tween)
Next
Endif
Endif
Endif
End
End
'#DOCON#
#rem
footer:This fantomEngine framework is released under the MIT license:
[quote]Copyright (c) 2011-2016 Michael Hartlef
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[/quote]
#end