Skip to content

Commit

Permalink
V3.02 Added ShakeCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeHart66 committed Nov 17, 2019
1 parent 1e0bba6 commit becd581
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 35 deletions.
11 changes: 7 additions & 4 deletions 3rdparty.cerberusdoc/fantomCX/changes.cerberusdoc
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
> Changes in fantomCX
* [[#v300|Version 3.01]]
* [[#v302|Version 3.02]]
* [[#v301|Version 3.01]]
* [[#v300|Version 3.00]]
* [[#v202|Version 2.02]]
* [[#v201|Version 2.01]]
* [[#v200|Version 2.00]]

---

| Version<a name='v301'></a> | Kind | Description | Hint
| 3.01 | Fix | ftImageMng.LoadImage:ftImage(path:String, frameWidth:Int, frameHeight:Int, frameCount:Int, flags:Int=Image.Filter). | As it discarded the loaded image.
| Version<a name='v302'></a> | Kind | Description | Hint
| 3.02 | New | [[ftEngine.ShakeCamera]]:Void(_factor:Float) | Shakes the camera with an random value.
| -<a name='v301'></a> | - | - | -
| 3.01 | Fix | ftImageMng.LoadImage:ftImage(path:String, frameWidth:Int, frameHeight:Int, frameCount:Int, flags:Int=Image.Filter) | As it discarded the loaded image.
| | Fix | Tiled Maps | Fixed various data problems regarding the Tiled files.
| | Mod | Documentation | Modded the docs to work with the new MakeDocs tool.
| -<a name='v300'></a> | - | - | -
Expand All @@ -19,7 +22,7 @@
| | Mod | ftGuiListview.Render | To render assigned item images.
| | Mod | Cleaned up and changed code base. |
| -<a name='v202'></a> | - | - | -
| 2.02 | New | ftObject.SetImageScale9:Void (top:Float, bottom:Float, left:Float, bottom:Float) | to support 9-slice image scaling.
| 2.02 | New | ftObject.SetImageScale9]]:Void (top:Float, bottom:Float, left:Float, bottom:Float) | to support 9-slice image scaling.
| | New | ftLayer.ActivateTouchEnterExitEvent (onOff:Bool = True) | to activate the call of the following events.
| | New | ftEngine.OnObjectTouchEnter (obj:ftObject, touchId:Int) |
| | New | ftEngine.OnObjectTouchExit (obj:ftObject, touchId:Int) |
Expand Down
15 changes: 15 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Version 3.02

*New functionalities*

- Added ftEngine.ShakeCamera:Void(_factor:Float)

*Fixes*

- tba

*Modifikations*

- tba

-----------------------------------------------------------------------------
Version 3.01

*Fixes*
Expand Down
16 changes: 13 additions & 3 deletions cerberusdoc/cftEngine.cerberusdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ Method OnUpdate:Int()
End

</pre>
Links: [[SetCamX]], [[SetCamY]], [[GetCam]], [[GetCamX]], [[GetCamY]]
Links: [[SetCamX]], [[SetCamY]], [[GetCam]], [[GetCamX]], [[GetCamY]], [[ShakeCamera]]

# Method SetCamX:Void(x:Float, relative:Int = False)

Expand Down Expand Up @@ -1538,7 +1538,7 @@ Method OnUpdate:Int()
End

</pre>
Links: [[SetCam]], [[SetCamY]], [[GetCam]], [[GetCamX]], [[GetCamY]]
Links: [[SetCam]], [[SetCamY]], [[GetCam]], [[GetCamX]], [[GetCamY]], [[ShakeCamera]]

# Method SetCamY:Void(y:Float, relative:Int = False)

Expand Down Expand Up @@ -1574,7 +1574,7 @@ Method OnUpdate:Int()
End

</pre>
Links: [[SetCam]], [[SetCamX]], [[GetCam]], [[GetCamX]], [[GetCamY]]
Links: [[SetCam]], [[SetCamX]], [[GetCam]], [[GetCamX]], [[GetCamY]], [[ShakeCamera]]

# Method SetCanvas:Void(canvas:Canvas)

Expand Down Expand Up @@ -1783,6 +1783,16 @@ Internally it will call the <b>ftEngine.OnObjectSort</b> method. Override this m

Links: [[OnObjectSort]]

# Method ShakeCamera:Void(_factor:Float, _durance:Float)

Shakes the camera.

*Details*

The camera is shaked with an random value based on the given @_factor and for the @durance set in milliseconds.

Links: [[SetCam]], [[SetCamX]], [[SetCamY]]

# Method SortObjects:Void(layer:ftLayer)

Sort the objects inside a layer.
Expand Down
59 changes: 40 additions & 19 deletions cftEngine.cxs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Class ftEngine

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
Expand Down Expand Up @@ -1850,21 +1854,21 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
'seeAlso:GetCamX,GetCamY,SetCam,SetCamX,SetCamY
Method GetCam:Float[] ()
Local retX:Float, retY:Float
retX = Self.camX
retY = Self.camY
retX = Self.camX + Self.camOffX
retY = Self.camY + Self.camOffY
Return [retX, retY]
End
'-----------------------------------------------------------------------------
'summery:Returns the cameras X coordinate.
'seeAlso:GetCam,GetCamY,SetCam,SetCamX,SetCamY
Method GetCamX:Float ()
Return Self.camX
Return Self.camX + Self.camOffX
End
'-----------------------------------------------------------------------------
'summery:Returns the cameras Y coordinate.
'seeAlso:GetCam,GetCamX,SetCam,SetCamX,SetCamY
Method GetCamY:Float ()
Return Self.camY
Return Self.camY + Self.camOffY
End
'------------------------------------------
'changes:2.0:New command
Expand Down Expand Up @@ -1947,7 +1951,7 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
Method GetLocalX:Float(wordXPos:Float, withCam:Bool = True)
Local ret:Float
If withCam = True Then
ret = Self.autofitX + (wordXPos - Self.camX) * Self.scaleX
ret = Self.autofitX + (wordXPos - Self.camX - Self.camOffX) * Self.scaleX
Else
ret = Self.autofitX + (wordXPos) * Self.scaleX
Endif
Expand All @@ -1961,8 +1965,8 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
Local retX:Float
Local retY:Float
If withCam = True Then
retX = Self.autofitX + (wordXPos - Self.camX) * Self.scaleX
retY = Self.autofitY + (wordYPos - Self.camY) * Self.scaleY
retX = Self.autofitX + (wordXPos - Self.camX - Self.camOffX) * Self.scaleX
retY = Self.autofitY + (wordYPos - Self.camY - Self.camOffY) * Self.scaleY
Else
retX = Self.autofitX + (wordXPos) * Self.scaleX
retY = Self.autofitY + (wordYPos) * Self.scaleY
Expand All @@ -1976,7 +1980,7 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
Method GetLocalY:Float(wordYPos:Float, withCam:Bool = True)
Local ret:Float
If withCam = True Then
ret = Self.autofitY + (wordYPos - Self.camY) * Self.scaleY
ret = Self.autofitY + (wordYPos - Self.camY - Self.camOffY) * Self.scaleY
Else
ret = Self.autofitY + (wordYPos) * Self.scaleY
Endif
Expand Down Expand Up @@ -2122,7 +2126,7 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
Method GetWorldX:Float(localXPos:Float, withCam:Bool = True)
Local ret:Float
If withCam = True
ret = (localXPos - Self.autofitX) / Self.scaleX + Self.camX
ret = (localXPos - Self.autofitX) / Self.scaleX + Self.camX + Self.camOffX
Else
ret = (localXPos - Self.autofitX) / Self.scaleX
Endif
Expand Down Expand Up @@ -2151,7 +2155,7 @@ When the timer fires it will call OnTimer. A repeatCount of -1 will let the time
Method GetWorldY:Float(localYPos:Float, withCam:Bool = True)
Local ret:Float
If withCam = True
ret = (localYPos - Self.autofitY) / Self.scaleY + Self.camY
ret = (localYPos - Self.autofitY) / Self.scaleY + Self.camY + Self.camOffY
Else
ret = (localYPos - Self.autofitY) / Self.scaleY
Endif
Expand Down Expand Up @@ -2699,11 +2703,11 @@ Self.currentCanvas.SetScissor( sx, sy ,sw , sh )
'seeAlso:SetCamX,SetCamY,GetCam,GetCamX,GetCamY
Method SetCam:Void (x:Float, y:Float, relative:Int = False )
If relative = True
camX = camX + x
camY = camY + y
camX = camX + x - Self.camOffX
camY = camY + y - Self.camOffY
Else
camX = x
camY = y
camX = x - Self.camOffX
camY = y - Self.camOffY
Endif
'Self.currCamera.SetPos(Self.camX, Self.camY)
End
Expand All @@ -2718,9 +2722,9 @@ Self.currentCanvas.SetScissor( sx, sy ,sw , sh )
'seeAlso:SetCam,SetCamY,GetCam,GetCamX,GetCamY
Method SetCamX:Void (x:Float, relative:Int = False )
If relative = True
camX = camX + x
camX = camX + x - Self.camOffX
Else
camX = x
camX = x - Self.camOffX
Endif
'Self.currCamera.SetPosX(Self.camX)
End
Expand All @@ -2735,9 +2739,9 @@ Self.currentCanvas.SetScissor( sx, sy ,sw , sh )
'seeAlso:SetCam,SetCamX,GetCam,GetCamX,GetCamY
Method SetCamY:Void (y:Float, relative:Int = False )
If relative = True
camY = camY + y
camY = camY + y - Self.camOffY
Else
camY = y
camY = y - Self.camOffY
Endif
'Self.currCamera.SetPosY(Self.camY)
End
Expand Down Expand Up @@ -2980,6 +2984,15 @@ Lower values than 1.0 slow down the engine, bigger values speed it up.
End
'------------------------------------------
#Rem
'summery:Shakes the Camera with an random value based on the give _factor and _durance.
#End
'seeAlso:...
Method ShakeCamera:Void(_factor:Float, _durance:Float)
Self.camShakeF = _factor
Self.camShakeD = _durance / 60.0
End
'------------------------------------------
#Rem
'summery:Sort the objects of all layer.
'Internally it will call the [b]ftEngine.OnObjectSort[/b] method. Override this method with your on comparison algorythm.
#End
Expand Down Expand Up @@ -3024,7 +3037,7 @@ Lower values than 1.0 slow down the engine, bigger values speed it up.
'For Local layer := Eachin layerList
For Local layer := Eachin layerList.Backwards()
If layer.isGUI = True Then
If layer.isActive Then layer.TouchCheck(px-Self.camX, py-Self.camY, touchID)
If layer.isActive Then layer.TouchCheck(px-Self.camX - Self.camOffX, py-Self.camY - Self.camOffY, touchID)
Else
If layer.isActive Then layer.TouchCheck(px, py, touchID)
Endif
Expand Down Expand Up @@ -3056,6 +3069,14 @@ Lower values than 1.0 slow down the engine, bigger values speed it up.
For Local timer:ftTimer = Eachin timerList.Backwards()
timer.Update()
Next
If Self.camShakeD > 0.0
Self.camOffX = Rnd(-Self.camShakeF, Self.camShakeF)
Self.camOffY = Rnd(-Self.camShakeF, Self.camShakeF)
Self.camShakeD -= speed
Else
Self.camOffX = 0.0
Self.camOffY = 0.0
End

For Local layer := Eachin layerList
If layer.isActive Then layer.Update(speed)
Expand Down
6 changes: 3 additions & 3 deletions cftLayer.cxs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Class ftLayer
For Local obj := Eachin objList.Backwards()
If obj.GetActive()=True Then
If Self.isGUI=True Then
If obj._IsObjAt(x-Self.engine.camX,y-Self.engine.camY) Then
If obj._IsObjAt(x-Self.engine.camX - Self.engine.camOffX,y-Self.engine.camY - Self.engine.camOffY) Then
Return obj
Endif
Else
Expand Down Expand Up @@ -389,9 +389,9 @@ Class ftLayer
Else
If obj.isVisible And obj.isActive And obj.parentObj = Null
If obj.type = ftEngine.otGUI
ftGuiMng(obj).Render(Self.xPos-engine.camX, Self.yPos-engine.camY)
ftGuiMng(obj).Render(Self.xPos-engine.camX - engine.camOffX, Self.yPos-engine.camY - engine.camOffY)
Else
obj.Render(Self.xPos-engine.camX, Self.yPos-engine.camY)
obj.Render(Self.xPos-engine.camX - engine.camOffX, Self.yPos-engine.camY - engine.camOffY)
Endif
Endif
Endif
Expand Down
4 changes: 2 additions & 2 deletions cftObject.cxs
Original file line number Diff line number Diff line change
Expand Up @@ -2448,8 +2448,8 @@ A value of 0 will disable the collision, a value between 1 and 32 will set the c
Local _cw:Float = engine.GetCanvasWidth()
Local _ch:Float = engine.GetCanvasHeight()

Local xoff:Float = Self.layer.xPos-Self.engine.camX
Local yoff:Float = Self.layer.yPos-Self.engine.camY
Local xoff:Float = Self.layer.xPos-Self.engine.camX - Self.engine.camOffX
Local yoff:Float = Self.layer.yPos-Self.engine.camY - Self.engine.camOffY

tlW = Self.tileMap.tileSizeX * Self.scaleX
tlH = Self.tileMap.tileSizeY * Self.scaleY
Expand Down
8 changes: 4 additions & 4 deletions cftTileMap.cxs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ Class ftTileMap
Local _cw:Float = obj.engine.GetCanvasWidth()
Local _ch:Float = obj.engine.GetCanvasHeight()

Local xoff:Float = obj.layer.xPos-obj.engine.camX
Local yoff:Float = obj.layer.yPos-obj.engine.camY
Local xoff:Float = obj.layer.xPos-obj.engine.camX - obj.engine.camOffX
Local yoff:Float = obj.layer.yPos-obj.engine.camY - obj.engine.camOffY

tlW = Self.tileSizeX * obj.scaleX
tlH = Self.tileSizeY * obj.scaleY
Expand Down Expand Up @@ -381,8 +381,8 @@ It returns -1 if there is no tile.
Local _cw:Float = obj.engine.GetCanvasWidth()
Local _ch:Float = obj.engine.GetCanvasHeight()

Local xoff:Float = obj.layer.xPos-obj.engine.camX
Local yoff:Float = obj.layer.yPos-obj.engine.camY
Local xoff:Float = obj.layer.xPos-obj.engine.camX - obj.engine.camOffX
Local yoff:Float = obj.layer.yPos-obj.engine.camY - obj.engine.camOffY

tlW = Self.tileSizeX * obj.scaleX
tlH = Self.tileSizeY * obj.scaleY
Expand Down

0 comments on commit becd581

Please sign in to comment.