-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcftEngine.cxs
3162 lines (2860 loc) · 104 KB
/
cftEngine.cxs
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Strict
#rem
Title: fantomCX
Description: A 2D game framework For the Cerberus X programming language
Author: Michael Hartlef
Contact: [email protected]
Website: http://www.fantomgl.com
License: MIT
#End
Import fantomCX
'nav:<blockquote><nav><img src="logo.png"> <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 module [b]cftEngine[/b] contains the ftEngine class, which is the main part of the fantomCX.
#End
'***************************************
'summery:The class [b]ftEngine[/b] is the heart of the fantomCX. After you have created one instance of it, you can let it deal with scenes, layers, objects and all the stuff a game needs.
Class ftEngine
'#DOCOFF#
Field _imgLoading:Image[]
Field _imgLoadingFrame:Int = 0
Field objectPool := New Pool<ftObject>(1)
Field soundList := New List<ftSound>
Field layerList := New List<ftLayer>
Field sceneList := New List<ftScene>
Field fontList := New List<ftFont>
Field timerList := New List<ftTimer>
Field scoreList := New ftHighScoreList
Field defaultLayer:ftLayer = Null
Field defaultScene:ftScene = Null
' Field currCamera:ftCamera = Null
Field currentCanvas:Canvas
Field defaultActive:Bool = True
Field defaultVisible:Bool = True
Field swiper:ftSwipe = Null
Field imgMng:ftImageManager = Null
' Field camMng:ftCameraMng = Null
Field red:Float = 255.0
Field blue:Float = 255.0
Field green:Float = 255.0
Field alpha:Float = 1.0
Field blendMode:Int = 0
Field screenWidth:Float
Field screenHeight:Float
Field canvasWidth:Float
Field canvasHeight:Float
Field camX:Float = 0.0
Field camY:Float = 0.0
Field camOffX:Float = 0.0
Field camOffY:Float = 0.0
Field camShakeF:Float = 0.0
Field camShakeD:Float = 0.0
Field scaleX:Float = 1.0
Field scaleY:Float = 1.0
Field autofitX:Int = 0
Field autofitY:Int = 0
Field delta:Float = 1.0
Field lastLayerScale:Float= 1.0
Field lastLayerAngle:Float= 0.0
Field time:Int
Field _fps:Int=0
Field _ifps:Int=0
Field _fpsTime:Int = 0
Field timeScale:Float = 1.0
Field oldtimeScale:Float = 0.0
Field deltaTime:Int = 0
Field lastTime:Int = 0
Field lastMillisecs:Int = app.Millisecs()
Field engineTime:Float = 0.0
Field accelX:Float
Field accelY:Float
Field accelZ:Float
Field isPaused:Bool = False
Field volumeSFX:Float = 1.0
Field volumeMUS:Float = 1.0
Field objhandleX:Float = 0.5
Field objhandleY:Float = 0.5
Field nextSoundChannel:Int = 99
Field maxSoundChannel:Int = 32
Field firstSoundChannel:Int = 0
Field hasSound:Bool = True
Field hasMusic:Bool = True
'#DOCON#
'Object types
Const otImage% = 0
Const otText% = 1
Const otCircle% = 2
Const otBox% = 3
Const otZoneBox% = 4
Const otZoneCircle% = 5
Const otTileMap% = 6
Const otTextMulti% = 7
Const otPoint% = 8
Const otStickMan% = 9
Const otOval% = 10
Const otLine% = 11
Const otPoly% = 12
Const otPivot% = 13
Const otGUI% = 100
'**-----------------------------------**
'Collision types
Const ctCircle% = 0
Const ctBox% = 1
Const ctBound% = 2
Const ctLine% = 3
'touch modes
Const tmCircle% = 1
Const tmBound% = 2
Const tmBox% = 3
'touch states
Const tsNoTouch% = 0
Const tsEnter% = 1
Const tsIsTouch% = 2
Const tsWasTouch% = 3
Const tsExit% = 99
'Canvas center modes
Const cmZoom% = 0 'Old behaviour, canvas will be stretched/fitted into the screen.
Const cmCentered% = 1 'Pixel perfect, canvas will be centered into the screen space. No content scaling.
Const cmLetterbox% = 2 'Default. Canvas will be scaled to the smaller scale factor of X or Y.
Const cmPerfect% = 3 'Pixel perfect (Top left). No content/Canvas scaling.
'Text align modes Y/X
Const taTopLeft% = 0
Const taTopCenter% = 1
Const taTopRight% = 2
Const taCenterLeft% = 7
Const taCenterCenter% = 3
Const taCenterRight% = 4
Const taBottomLeft% = 8
Const taBottomCenter% = 5
Const taBottomRight% = 6
'Transition tween modes
Const twmLinear% = 0
Const twmBounceEaseIn% = 1
Const twmBounceEaseInOut% = 2
Const twmBounceEaseOut% = 3
Const twmCircleEaseIn% = 4
Const twmCircleEaseInOut% = 5
Const twmCircleEaseOut% = 6
Const twmCubicEaseIn% = 7
Const twmCubicEaseInOut% = 8
Const twmCubicEaseOut% = 9
Const twmEaseIn% = 10
Const twmEaseInOut% = 11
Const twmEaseOut% = 12
Const twmElasticEaseIn% = 13
Const twmElasticEaseInOut% = 14
Const twmElasticEaseOut% = 15
Const twmExpoEaseIn% = 16
Const twmExpoEaseInOut% = 17
Const twmExpoEaseOut% = 18
Const twmSineEaseIn% = 19
Const twmSineEaseInOut% = 20
Const twmSineEaseOut% = 21
Const twmQuadEaseIn% = 22
Const twmQuadEaseInOut% = 23
Const twmQuadEaseOut% = 24
Const twmQuartEaseIn% = 25
Const twmQuartEaseInOut% = 26
Const twmQuartEaseOut% = 27
Const twmQuintEaseIn% = 28
Const twmQuintEaseInOut% = 29
Const twmQuintEaseOut% = 30
' Object edge constants
Const oedBottom% = 1
Const oedTop% = 2
Const oedLeft% = 3
Const oedRight% = 4
' Transition loop types
Const tltRepeat% = 1
Const tltBounce% = 2
'------------------------------------------
'summery:De-/activates the music playback for the engine.
'seeAlso:ActivateSound
Method ActivateMusic:Void(onOff:Bool=True)
Self.hasMusic = onOff
End
'------------------------------------------
'summery:De-/activates the sound playback for the engine.
'seeAlso:ActivateMusic
Method ActivateSound:Void(onOff:Bool=True)
Self.hasSound = onOff
End
'------------------------------------------
#Rem
'summery:Activates swipe gesture detection.
'To (de)activate the swipe detection, use ActivateSwipe. To detect(update) a swipe, use SwipeUpdate. If a swipe is detected, fantomCX will call its OnSwipeDone method.
'Also have a look at the sample script [a ..\examples\SwipeDetection\SwipeDetection.cxs]SwipeDetection.cxs[/a]
#End
'seeAlso:SwipeUpdate
Method ActivateSwipe:Void(onOff:Bool=True)
swiper.swipeActive = onOff
End
'------------------------------------------
#Rem
'summery:Returns the delta time in milliseconds since the last call.
'Calculates the current delta time in milliseconds since the last call of this command.
'Usually you call this command during the OnUpdate event of your app. If you just need to retrieve the delta time and not recalculate it, use GetDeltaTime.
#End
'seeAlso:GetDeltaTime,Update
Method CalcDeltaTime:Int()
deltaTime = Self.GetTime() - lastTime
lastTime += deltaTime
Return deltaTime
End
'------------------------------------------
#Rem
'summery:Clears the current active canvas.
#End
Method Clear:Void(red:Float, green:Float, blue:Float)
Self.currentCanvas.Clear(red/255.0, green/255.0, blue/255.0)
End
'------------------------------------------
#Rem
'summery:Does a collision check over all layers and active objects which has a collision group assigned to them.
'To check for collisions via the build-in functionality, use CollisionCheck. Without a parameter, it will check all active objects for collisions.
' Typically you do this inside mojos' OnUpdate method. If a collision appears, it will call the ftEngine.onObjectCollision method with the two objects as parameters.
' Objects that will be part of a collision need to have a collision group with [ftObject.SetColGroup SetColGroup] assigned to them.
'The objects that then will need to be checked have to be told with which collision group the can collide. You do that with [ftObject.SetColWith SetColWith].
#End
'seeAlso:SetColType,SetColWith,SetColGroup,OnObjectCollision
Method CollisionCheck:Void()
For Local layer := Eachin layerList
If layer.isActive Then layer.CollisionCheck()
Next
End
'------------------------------------------
#Rem
'summery:Does a collision check of the given layer and it's active objects which has a collision group assigned to them.
#End
'seeAlso:SetColType,SetColWith,SetColGroup,OnObjectCollision
Method CollisionCheck:Void(layer:ftLayer)
If layer.isActive Then layer.CollisionCheck()
End
'------------------------------------------
#Rem
'summery:Does a collision check of the given active object.
#End
'seeAlso:SetColType,SetColWith,SetColGroup,OnObjectCollision
Method CollisionCheck:Void(obj:ftObject)
If obj.layer.isActive Then obj.layer.CollisionCheck(obj)
End
'-----------------------------------------------------------------------------
'summery:Cancels all timers attached of the engine.
'seeAlso:CreateTimer,OnTimer
Method CancelTimerAll:Void()
For Local timer := Eachin timerList
timer.RemoveTimer()
Next
End
'------------------------------------------
#Rem
'summery:Copies an existing object.
This command copies a given object and returns the copy. The new object contains all properties of the source object, but not the following:
[list][*]user data object
[*]box2D object
[*]path marker
[*]timer
[*]transitions
[*]tileMaps[/list]
#End
Method CopyObject:ftObject(srcObj:ftObject)
Local newObj:ftObject
newObj = New ftObject
newObj.xPos = srcObj.xPos
newObj.yPos = srcObj.yPos
newObj.zPos = srcObj.zPos
newObj.w = srcObj.w
newObj.h = srcObj.h
newObj.x2 = srcObj.x2
newObj.y2 = srcObj.y2
newObj.verts = srcObj.verts
newObj.renderWidth = srcObj.renderWidth
newObj.renderHeight = srcObj.renderHeight
newObj.renderOffX = srcObj.renderOffX
newObj.renderOffY = srcObj.renderOffY
newObj.angle = srcObj.angle
newObj.scaleX = srcObj.scaleX
newObj.scaleY = srcObj.scaleY
newObj.radius = srcObj.radius
newObj.friction = srcObj.friction
newObj.speed = srcObj.speed
newObj.speedX = srcObj.speedX
newObj.speedY = srcObj.speedY
newObj.speedSpin = srcObj.speedSpin
newObj.speedAngle = srcObj.speedAngle
newObj.speedMax = srcObj.speedMax
newObj.speedMin = srcObj.speedMin
newObj.engine = srcObj.engine
newObj.red = srcObj.red
newObj.blue = srcObj.blue
newObj.green = srcObj.green
newObj.alpha = srcObj.alpha
newObj.blendMode = srcObj.blendMode
newObj.objImg = srcObj.objImg
newObj.frameCount = srcObj.frameCount
newObj.frameStart = srcObj.frameStart
newObj.frameEnd = srcObj.frameEnd
newObj.frameLength = srcObj.frameLength
If srcObj.layer <> Null Then
newObj.SetLayer(srcObj.layer)
Endif
If srcObj.parentObj <> Null Then
newObj.SetParent(srcObj.parentObj)
Endif
' Copy all children and assign the new object as their parent
For Local ci:Int = 1 To srcObj.GetChildCount()
Local co:= srcObj.GetChild(ci)
Local tmpCo:= Self.CopyObject(co)
tmpCo.SetParent(newObj)
Next
newObj.objFont = srcObj.objFont
newObj.id = srcObj.id
newObj.textMode = srcObj.textMode
newObj.name = srcObj.name
newObj.text = srcObj.text
newObj.tag = srcObj.tag
newObj.type = srcObj.type
newObj.groupID = srcObj.groupID
newObj.collType = srcObj.collType
newObj.collGroup = srcObj.collGroup
newObj.collWith = srcObj.collWith
newObj.colCheck = srcObj.colCheck
newObj.collScale = srcObj.collScale
newObj.isVisible = srcObj.isVisible
newObj.isAnimated = srcObj.isAnimated
newObj.isActive = srcObj.isActive
newObj.isWrappingX = srcObj.isWrappingX
newObj.isWrappingY = srcObj.isWrappingY
newObj.touchMode = srcObj.touchMode
newObj.isFlipH = srcObj.isFlipH
newObj.isFlipV = srcObj.isFlipV
newObj.onDeleteEvent = srcObj.onDeleteEvent
newObj.onRenderEvent = srcObj.onRenderEvent
newObj.onUpdateEvent = srcObj.onUpdateEvent
newObj.x1c = srcObj.x1c
newObj.y1c = srcObj.y1c
newObj.x2c = srcObj.x2c
newObj.y2c = srcObj.y2c
newObj.x3c = srcObj.x3c
newObj.y3c = srcObj.y3c
newObj.x4c = srcObj.x4c
newObj.y4c = srcObj.y4c
newObj.deleted = srcObj.deleted
newObj._RotateSpriteCol()
newObj.objPathUpdAngle = srcObj.objPathUpdAngle
newObj.offAngle = srcObj.offAngle
newObj.handleX = srcObj.handleX
newObj.handleY = srcObj.handleY
newObj.handleOffX = srcObj.handleOffX
newObj.handleOffY = srcObj.handleOffY
If srcObj.animMng <> Null Then
newObj.animMng = srcObj.animMng._CopyAnim()
newObj.animMng.animObj = newObj
Endif
newObj.currImageIndex = srcObj.currImageIndex
newObj.currImageFrame = srcObj.currImageFrame
newObj.objMinX = srcObj.objMinX
newObj.objMinY = srcObj.objMinY
newObj.objMaxX = srcObj.objMaxX
newObj.objMaxY = srcObj.objMaxY
newObj.scale9T = srcObj.scale9T
newObj.scale9B = srcObj.scale9B
newObj.scale9L = srcObj.scale9L
newObj.scale9R = srcObj.scale9R
newObj.scale9Type = srcObj.scale9Type
newObj.touchState = Self.tsNoTouch
Return ftObject(newObj)
End
'-----------------------------------------------------------------------------
#Rem
'summery:Creates an animated image object (sprite) from the given sprite atlas with a center at xPos/yPos.
The texture will be grabbed from frameStartX/frameStartY with the given frameWidth/frameHeight. The number of frames will be taken from the given frameCount.
It creates a DEFAULT animation automatically.
#End
'seeAlso:CreateBox,CreateCircle,CreateImage,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateAnimImage:ftObject(atl:ftImage, frameStartX:Int, frameStartY:Int, frameWidth:Int, frameHeight:Int, frameCount:Int, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
Endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = imgMng.GrabImage(atl,frameStartX,frameStartY,frameWidth,frameHeight,frameCount)
obj.CreateAnim("DEFAULT", 1, 1, obj.objImg[0].img.Length())
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'-----------------------------------------------------------------------------
'changes:2.01:Subimages will now loaded with the Image.Filter flag.
#Rem
'summery:Creates an animated image object (sprite) from the given sprite atlas with a center at xPos/yPos.
The texture will be grabbed from frameStartX/frameStartY with the given frameWidth/frameHeight. The number of frames will be taken from the given frameCount.
It creates a DEFAULT animation automatically.
#End
'seeAlso:CreateBox,CreateCircle,CreateImage,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateAnimImage:ftObject(atl:Image, frameStartX:Int, frameStartY:Int, frameWidth:Int, frameHeight:Int, frameCount:Int, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
Endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = imgMng.GrabImage( atl, frameStartX,frameStartY,frameWidth,frameHeight,frameCount, Image.Filter )
obj.CreateAnim("DEFAULT", 1, 1, obj.objImg[0].img.Length())
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
'summery:Creates a rectangle with the given width/height and the center at xpos/ypos.
'seeAlso:CreateAnimImage,CreateCircle,CreateImage,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateBox:ftObject(width:Float, height:Float, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
Endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otBox
obj.radius = (Max(width,height))/2.0
obj.w = width
obj.h = height
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctBound
obj._RotateSpriteCol()
Return obj
End
#rem
'------------------------------------------
'summery:Creates a new camera with the dimensions of the device.
'seeAlso:GetCamera
Method CreateCamera:ftCamera()
Return Self.camMng.CreateCamera()
End
'------------------------------------------
'summery:Creates a new camera and sets its dimensions.
'seeAlso:GetCamera
Method CreateCamera:ftCamera(left:Int, top:Int, width:Int, height:Int)
Local newCam:ftCamera = Self.camMng.CreateCamera()
newCam.SetDimensions(left,top,width,height)
Return newCam
End
#end
'------------------------------------------
'changes:2.0:New command
'summery:Creates a new canvas. If an image is given, this will be a new render target.
'seeAlso:SetCanvas,GetCanvas
Method CreateCanvas:Canvas(image:Image = Null)
Local cv:Canvas
If image = Null
cv = New Canvas
Else
cv = New Canvas(image)
Endif
Return cv
End
'------------------------------------------
'summery:Creates a circle with the given radius and the center at xpos/ypos.
'seeAlso:CreateAnimImage,CreateBox,CreateImage,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateCircle:ftObject(radius:Float, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otCircle
obj.radius = radius
obj.w = obj.radius*2
obj.h = obj.radius*2
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
'summery:Creates an custom GUI manager object which you can use to GUI child objects to.
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateImage
Method CreateGUI:ftGuiMng(xpos:Float=0.0, ypos:Float=0.0)
Local obj:ftGuiMng = New ftGuiMng
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otGUI
obj.radius = 1
obj.w = 1
obj.h = 1
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = 0
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
#Rem
'summery:Creates an image object (sprite) from the given filename with a center at xpos/ypos.
'To load an animated image object, use CreateAnimImage.
#End
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(filename:String, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
Endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = Self.imgMng.LoadImage(filename)
#If CONFIG="debug"
If obj.objImg[0] = Null Then Error("~n~nError in file fantomCX.cftEngine, Method ftEngine.CreateImage:ftObject(filename:String, xpos:Float, ypos:Float, _ucob:Object=Null):~n~nImage "+filename+" not found!")
#End
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
'changes:2.0:New command
#Rem
'summery:Creates an empty image object (sprite) with the given size. It can be used as a render target.
#End
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(width:Int, height:Int, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
Local image:Image
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
image = New Image(width, height)
obj.objImg[0] = imgMng.LoadImage(image)
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
#Rem
'summery:Creates an image object (sprite) from the given image with a center at xpos/ypos.
#End
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(image:Image, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = imgMng.LoadImage(image)
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
#Rem
'summery:Creates an image object (sprite) from the given ftImage with a center at xpos/ypos.
#End
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(image:ftImage, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = image
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'-----------------------------------------------------------------------------
'changes:2.01:Subimages will now be loaded with the Image.Filter flag.
'summery:Creates an image object (sprite) from the given sprite atlas with a center at xPos/yPos. The texture will be grabbed from x/y with the given width/height.
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(atlas:Image, x:Int, y:Int, width:Int, height:Int, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
'obj = New ftObject
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
obj.objImg[0] = imgMng.GrabImage(atlas, x,y,width,height,1, Image.Filter )
'obj.radius = (Max(obj.objImg.img.Height(), obj.objImg.img.Width())*1.42)/2.0
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'-----------------------------------------------------------------------------
#Rem
'summery:Loads a subimage from a packed texture created by the tool TexturePacker with a center at xpos/ypos.
It supports rotated sub images in LibGDX files too.
From version 1.52 on it supports Sparrow compatible files (.xml).
#End
' The next CreateImage version uses image atlas created by the tool TexturePacker, a data file
' exported from TexturePacker in LibGDX format and the name of the sub image stored inside the texture atlas
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateLine,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateImage:ftObject(atlas:Image, dataFileName:String, subImageName:String, xpos:Float, ypos:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
Endif
'Code provided by fantomCX user TriGaDe, modified by Michael Hartlef >>>>>>>>>>>
'** TexturePacker variables
Local tpStringFromFile:String = LoadString(dataFileName)
'Local tpAllStrings:String[] = tpStringFromFile.Split(String.FromChar(10))
Local tpAllStrings:String[] = tpStringFromFile.Split(String.FromChar(13)+String.FromChar(10))
If tpAllStrings.Length() < 2 Then
tpAllStrings = tpStringFromFile.Split(String.FromChar(10))
Endif
Local tpXPos:Int
Local tpYPos:Int
Local tpWidth:Int
Local tpHeight:Int
Local aslen:Int
Local strRot:String = "false"
If dataFileName.ToLower().Find(".txt") > 0 Then
aslen = tpAllStrings.Length()
For Local count:Int = 0 To aslen-1
If( String(tpAllStrings[count]).ToLower() = subImageName.ToLower()) Then
'** Get rotation flag
strRot = tpAllStrings[count+1]
strRot = strRot.Replace("rotate:","").Trim()
If strRot.ToLower() = "true" Then obj.offAngle = -90
'** Get X, Y
Local strXY:String = tpAllStrings[count+2]
strXY = strXY.Replace("xy:","").Trim()
Local strXYsplit:String[] = strXY.Split(",")
tpXPos = Int(strXYsplit[0])
tpYPos = Int(strXYsplit[1])
'** Get Width, Height
Local strWH:String = tpAllStrings[count+3]
strWH = strWH.Replace("size:","").Trim()
Local strWHsplit:String[] = strWH.Split(",")
tpWidth = Int(strWHsplit[0])
tpHeight = Int(strWHsplit[1])
Endif
Next
Else
aslen = tpAllStrings.Length()
For Local count:Int = 0 To aslen-1
Local s:String = String(tpAllStrings[count]).ToLower().Trim()
If s.Contains(String.FromChars([34])+subImageName.ToLower()+String.FromChars([34])) Then
s = s.Replace(String.FromChars([34]),"")
s = s.Replace("<subtexture ","")
s = s.Replace("/>","")
Local strSplit:String[] = s.Split(" ")
'** Get X
Local strX:String = strSplit[1]
Local strXsplit:String[] = strX.Split("=")
tpXPos = Int(strXsplit[1])
'** Get Y
Local strY:String = strSplit[2]
Local strYsplit:String[] = strY.Split("=")
tpYPos = Int(strYsplit[1])
'** Get Width
Local strW:String = strSplit[3]
Local strWsplit:String[] = strW.Split("=")
tpWidth = Int(strWsplit[1])
'** Get Height
Local strH:String = strSplit[4]
Local strHsplit:String[] = strH.Split("=")
tpHeight = Int(strHsplit[1])
Endif
Next
Endif
'<<<<<<<<< Code provided by fantomCX user TriGaDe, modified by Michael Hartlef
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.type = otImage
If obj.objImg.Length() = 0
obj.objImg = obj.objImg.Resize(1)
Endif
If strRot.ToLower() = "true" Then
obj.objImg[0] = imgMng.GrabImage(atlas, tpXPos,tpYPos,tpHeight,tpWidth,1 )
Else
obj.objImg[0] = imgMng.GrabImage(atlas, tpXPos,tpYPos,tpWidth,tpHeight,1 )
Endif
obj.radius = (Max(obj.objImg[0].img[0].Height(), obj.objImg[0].img[0].Width()))/2.0
obj.w = obj.objImg[0].img[0].Width()
obj.h = obj.objImg[0].img[0].Height()
obj.renderWidth = obj.objImg[0].img[0].Width()
obj.renderHeight = obj.objImg[0].img[0].Height()
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)
obj.SetVisible(Self.defaultVisible)
obj.collType = ctCircle
obj._RotateSpriteCol()
Return obj
End
'------------------------------------------
#Rem
'summery:Creates a new layer.
'To create a new layer, use CreateLayer. To delete a layer, use RemoveLayer. A new layer is automatically added to the defaultScene scene.
#End
'seeAlso:SetDefaultLayer,GetDefaultLayer,RemoveLayer,RemoveAllLayer
Method CreateLayer:ftLayer(_ucla:Object=Null)
Local layer:ftLayer
If _ucla = Null Then
layer = New ftLayer
Else
layer = ftLayer(_ucla)
Endif
layer.engine = Self
layer.engineNode = layerList.AddLast(layer)
Self.defaultScene.AddLayer(layer)
Return layer
End
'------------------------------------------
#Rem
'summery:Creates a line object starting at xpos/ypos and ending at x/y.
The objects handle is in the middle of the line by default and can be changed via a call to ftObject.SetHandle.
#End
'Provided by Douglas Williams
'seeAlso:CreateAnimImage,CreateBox,CreateCircle,CreateImage,CreateOval,CreatePoint,CreatePoly,CreateStickMan,CreateTileMap,CreateText,CreateGUI
Method CreateLine:ftObject(xpos:Float, ypos:Float, x2:Float, y2:Float, _ucob:Object=Null)
Local obj:ftObject
If _ucob = Null Then
obj = New ftObject
obj = Self.objectPool.Allocate()._Init()
Else
obj = ftObject(_ucob)
endif
obj.engine = Self
obj.xPos = xpos
obj.yPos = ypos
obj.x2 = x2
obj.y2 = y2
obj.type = otLine
obj.w = obj.GetVectorDist(x2,y2)
obj.h = 1
obj.xPos = (x2-xpos)/2.0+xpos
obj.yPos = (y2-ypos)/2.0+ypos
obj.radius = obj.w / 2.0
obj.renderWidth = obj.w
obj.renderHeight = obj.h
obj.SetLayer(Self.defaultLayer)
obj.SetActive(Self.defaultActive)