FantomEngine Setting Background Image?
Monkey Targets Forums/Android/FantomEngine Setting Background Image?
| ||
Hi i cant work out how to set a background image? |
| ||
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. |
| ||
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] |
| ||
How to make a cyclically repeating background? |
| ||
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. |
| ||
MikeHart wrote: Short answer: Thks. I hate to register again and again :) |
| ||
To bad then. Have a nice day. |