FantomEngine Setting Background Image?

Monkey Targets Forums/Android/FantomEngine Setting Background Image?

Xyloman(Posted 2012) [#1]
Hi i cant work out how to set a background image?


MikeHart(Posted 2012) [#2]
Several ways to do it.

1) If you are working with just one layer, then load your background image as the first image.

2) With several layers, you use the default layer as the background layer and assign your background image to that one. Every other layer is created "above" your background layer.


MikeHart(Posted 2012) [#3]
Here is a small example on hour to setup two layers:

[monkeycode]Class game Extends App
' Create a field to store the instance of the engine class, which is an instance
' of the ftEngine class itself
Field eng:engine

' Create a field that stores the state of an app being suspended or not
Field isSuspended:Bool = False

' Create two fields for both layers
Field backgroundLayer:ftLayer
Field foregroundLayer:ftLayer

'------------------------------------------
Method OnCreate:Int()
' Set the update rate of Mojo's OnUpdate events to 60 FPS
SetUpdateRate(60)

' Create an instance of the fantomEngine, which was created via the engine class
eng = New engine

' Get the first layer of the engine
backgroundLayer = eng.GetDefaultLayer()

' Create a new layer for the foreground
foregroundLayer = eng.CreateLayer()

' Load background image
Local bgimg := eng.CreateImage("bgImage.png",eng.GetCanvasWidth()/2, eng.GetCanvasHeight()/2)
bgimg.SetLayer(backgroundLayer)

Return 0
End
'....
[/monkeycode]


nikoniko(Posted 2014) [#4]
How to make a cyclically repeating background?


MikeHart(Posted 2014) [#5]
Again, for faster support, please post in my forum.

Short answer:
1) Tile your background
2) Move the tiles each frame.
3) Once they are out of view, move them back to a starting position.


nikoniko(Posted 2014) [#6]
MikeHart wrote:
Short answer:


Thks. I hate to register again and again :)


MikeHart(Posted 2014) [#7]
To bad then. Have a nice day.