-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcftScene.cxs
226 lines (204 loc) · 7.3 KB
/
cftScene.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
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><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]ftScene[/b] groups assigned layers and lets you manage them in a combined way. Layers can be connected to several scenes at one time.
#End
'***************************************
Class ftScene
'#DOCOFF#
Field layerList := New List<ftLayer>
Field engine:ftEngine = Null
Field engineNode:list.Node<ftScene> = Null
Field isActive:Bool = True
Field isVisible:Bool = True
Field alpha:Float = 1.0
'#DOCON#
'------------------------------------------
#Rem
'summery:Add a layer to a scene.
#End
'SeeAlso:RemoveLayer
Method AddLayer:Void(layer:ftLayer)
layerList.AddLast(layer)
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create an alpha transition for the scene.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnLayerTrans[/b] method for the first layer of a scene.
#End
'seeAlso:CreateTransPos
Method CreateTransAlpha:ftTrans(alpha:Float, duration:Float, relative:Int, transId:Int=0 )
Local layer:ftLayer = Null
Local trans:ftTrans = Null
Local c:Int = 0
For layer = Eachin layerList
If c = 0 Then
trans = layer.CreateTransAlpha(alpha, duration, relative, transId )
Else
trans.AddAlpha(alpha, layer, duration, relative )
Endif
c += 1
Next
Return trans
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create an position transition for the scene.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnLayerTrans[/b] method for the first layer of a scene.
#End
'seeAlso:CreateTransAlpha
Method CreateTransPos:ftTrans(xt:Float, yt:Float, duration:Float, relative:Int, transId:Int=0 )
Local layer:ftLayer = Null
Local trans:ftTrans = Null
Local c:Int = 0
For layer = Eachin layerList
If c = 0 Then
trans = layer.CreateTransPos(xt, yt, duration, relative, transId )
Else
trans.AddPos(xt, yt, layer, duration, relative )
Endif
c += 1
Next
Return trans
End
'------------------------------------------
#Rem
'summery:Returns the active flag of the scene.
#End
'SeeAlso:SetActive
Method GetActive:Bool()
Return Self.isActive
End
'------------------------------------------
#Rem
'summery:Returns the visible flag of the scene.
#End
'SeeAlso:SetVisible
Method GetVisible:Bool()
Return Self.isVisible
End
'------------------------------------------
#Rem
'summery:Remove the scene from the engine.
#End
Method Remove:Void()
layerList.Clear()
Self.engineNode.Remove()
Self.engine = Null
End
'------------------------------------------
#Rem
'summery:Remove a layer from a scene.
#End
'SeeAlso:AddLayer
Method RemoveLayer:Void(layer:ftLayer)
layerList.RemoveEach(layer)
End
'------------------------------------------
'changes:2.0:New command
#Rem
'summery:Renders all active and visible layers of this scene with their objects.
'The layers have to be active and visible. They are rendered in their order of assignment to this scene.
#End
Method Render:Void(setupRender:Bool = False)
If setupRender = True
Self.engine.red = 255
Self.engine.green = 255
Self.engine.blue = 255
Self.engine.currentCanvas.SetColor(1.0,1.0,1.0)
Self.engine.alpha = 1.0
Self.engine.currentCanvas.SetAlpha(1.0)
Self.engine.currentCanvas.PushMatrix()
Self.engine.currentCanvas.Translate(Self.engine.autofitX, Self.engine.autofitY)
Self.engine.currentCanvas.Scale(Self.engine.scaleX, Self.engine.scaleY)
Self.engine.currentCanvas.SetScissor( Self.engine.autofitX, Self.engine.autofitY, Self.engine.canvasWidth*Self.engine.scaleX, Self.engine.canvasHeight*Self.engine.scaleY )
Endif
For Local layer := Eachin layerList
If layer.isVisible And layer.isActive Then layer.Render()
Next
If setupRender = True
Self.engine.currentCanvas.PopMatrix()
Endif
End
'------------------------------------------
#Rem
'summery:Set the active flag of the scenes layers.
#End
'SeeAlso:GetActive
Method SetActive:Void(activeFlag:Bool)
Local layer:ftLayer = Null
For layer = Eachin layerList
layer.SetActive(activeFlag)
Next
Self.isActive = activeFlag
End
'------------------------------------------
#Rem
'summery:Set the alpha value of each layer in the scene.
#End
'seeAlso:SetPos
Method SetAlpha:Void(newAlpha:Float, relative:Bool = False)
Local layer:ftLayer = Null
For layer = Eachin layerList
layer.SetAlpha(newAlpha, relative)
Next
Self.alpha = newAlpha
End
'------------------------------------------
#Rem
'summery:Set the position of each layer in the scene.
#End
'seeAlso:SetAlpha
Method SetPos:Void(x:Float, y:Float, relative:Bool = False)
Local layer:ftLayer = Null
For layer = Eachin layerList
layer.SetPos(x, y, relative)
Next
End
'------------------------------------------
#Rem
'summery:Set the visible flag of the scenes layers.
#End
'SeeAlso:GetVisible
Method SetVisible:Void(visibleFlag:Bool)
Local layer:ftLayer = Null
For layer = Eachin layerList
layer.SetVisible(visibleFlag)
Next
Self.isVisible = visibleFlag
End
'------------------------------------------
'changes:2.0:New command
#Rem
'summery:Updates all active layers of this scene with their objects.
'The layers have to be active and visible. They are updated in their order of assignment to this scene.
#End
Method Update:Void(speed:Float=1.0, updateEngineTimer:Bool = False)
If updateEngineTimer = True
Self.engine.time = Self.engine.GetTime()
For Local timer:ftTimer = Eachin Self.engine.timerList.Backwards()
timer.Update()
Next
Endif
For Local layer := Eachin layerList
If layer.isActive Then layer.Update(speed)
Next
End
End
#rem
footer:This fantomCX framework is released under the MIT license:
[quote]Copyright (c) 2011-2018 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