This repository was archived by the owner on Jan 13, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcftTrans.cxs
More file actions
536 lines (501 loc) · 15.4 KB
/
cftTrans.cxs
File metadata and controls
536 lines (501 loc) · 15.4 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
Strict
#rem
Title: fantomCX
Description: A 2D game framework for the Cerberus X programming language
Author: Michael Hartlef
Contact: michaelhartlef@gmail.com
Website: http://www.fantomgl.com
License: MIT
#End
Import fantomCX
Import cftTween
'nav:<blockquote><nav><b>fantomCX 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
'Cerberus X sample script in bananas/skn3/tweening/tween.cxs
#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 s_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 Reset:Void(loopTyp:Int)
timeLapsed = 0.0
duration = s_duration
If obj <> Null Then
If loopTyp = ftEngine.tltRepeat
Select typ
Case 1
obj.SetPos(s_x, s_y, False)
x = (e_x - s_x) / duration
y = (e_y - s_y) / duration
Case 2
obj.SetAngle(s_rot, False)
rot = (e_rot - s_rot) / duration
Case 3
obj.SetScale(s_scale, False)
scale = (e_scale - s_scale) / duration
Case 4
obj.SetAlpha(s_alpha, False)
alpha = (e_alpha - s_alpha) / duration
End
Elseif loopTyp = ftEngine.tltBounce
Select typ
Case 1
Local tx:= Self.s_x
Local ty:= Self.s_y
s_x = e_x
s_y = e_y
e_x = tx
e_y = ty
obj.SetPos(s_x, s_y, False)
x = (e_x - s_x) / duration
y = (e_y - s_y) / duration
Case 2
Local tr:= Self.s_rot
s_rot = e_rot
e_rot = tr
obj.SetAngle(s_rot, False)
rot = (e_rot - s_rot) / duration
Case 3
Local ts:= Self.s_scale
s_scale = e_scale
e_scale = ts
obj.SetScale(s_scale, False)
scale = (e_scale - s_scale) / duration
Case 4
Local ta:= Self.s_alpha
s_alpha = e_alpha
e_alpha = ta
obj.SetAlpha(s_alpha, False)
alpha = (e_alpha - s_alpha) / duration
End
Endif
Endif
End
'------------------------------------------
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.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)
obj.SetAngle(tween.equation.Call(timeLapsed, s_rot, e_rot - s_rot, duration))
Case 3
'obj.SetScale(scale * delta, True)
obj.SetScale(tween.equation.Call(timeLapsed, s_scale, e_scale - s_scale, duration))
Case 4
obj.SetAlpha(alpha * delta, True)
obj.SetAlpha(tween.equation.Call(timeLapsed, s_alpha, e_alpha - s_alpha, duration))
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 currTime:Int=0
Field duration:Int
Field s_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 loop:Bool = False
Field loopType:Int = 0
Field loopCount:Int = -1
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.s_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.s_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.s_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.s_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.s_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.s_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.s_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#
'------------------------------------------
Method SetLoop:Void(loopFlag:Bool = True, ltype:Int = ftEngine.tltRepeat, rcount:Int = -1)
Self.loop = loopFlag
Self.loopType = ltype
Self.loopCount = rcount
End
'------------------------------------------
Method SetLoopType:Void(loopTyp:Int = ftEngine.tltRepeat)
Self.loopType = loopTyp
End
'------------------------------------------
Method SetLoopRepeat:Void(rcount:Int = -1)
Self.loopCount = rcount
End
'------------------------------------------
'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:Void(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:Void(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:Void()
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:Void(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
If Self.loop = False Or Self.loopCount = 0
Self.deleted = True
Else
duration = s_duration
For Local entry := Eachin entryList
entry.Reset(Self.loopType)
Next
If Self.loopCount > 0 Then Self.loopCount -= 1
Endif
Else
For Local entry := Eachin entryList
entry.Update(deltaTime, Self.tween)
Next
Endif
Endif
Endif
End
End
'#DOCON#
#rem
footer:This fantomCX framework is released under the MIT license:
[quote]Copyright (c) 2011-2025 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