I am developing a prototype for a game in Flixel in which a character floats upward continually to traverse the level. I would like to have a "tall" layout for levels and set the FlxG.camera to follow the character as he floats upward. My issue is in understanding the proper use of FlxG.camera. I have my game constructor coded as follows:

package
{
import flash.display.Sprite;
import org.flixel.*;

[SWF(width="640",height="480",backgroundColor="#000000")]
public class MyGame extends FlxGame
{
public function MyGame()
{
super(320,240,PlayState,2);
forceDebugger = true;
}
}
}


In the override of create() in the PlayState.as file I attempt to set the camera to follow the player as follows:

public var TheClimber:BalloonHero;

override public function create():void
{
/*set background color*/
FlxG.bgColor = FlxG.BLUE;

/*Set data for player*/
TheClimber = new BalloonHero(FlxG.width/2-5,480);

//which will automatically set the boundaries of the world.
FlxG.camera.setBounds(0,1280,640,1280,true);
FlxG.camera.follow(TheClimber,FlxCamera.STYLE_PLATFORMER);

}


I assumed this would set the camera bounds to twice the height of the SWF background(i.e. the FlxG height) and then scroll the background along with the specified FlxObject(TheClimber in this case) until it had reached the height of the game. However, I must be going about it incorrectly because when the zoom is 2 and the game height 720 the camera starts at the top of the screen with the player character not visible at the bottom of the game height. Is there a way to start with the camera/game focused on the bottom of the game object(FlxG.height) ? Or am I going about this the wrong way and have other issues with the way I am using the camera? Thanks in advance.

You don't set the world size with:

public function MyGame()
{
super(320,720,PlayState,2);
}


That is setting the size of the screen Flixel will draw onto. If you want a zoom level of 2 you should have super(320, 240, PlayState, 2).

You should check out the source for Mode to see how to create a world larger than the screen. What happens in Mode is that the world size is set to 640x640 and the player, blocks and enemies are added in that world space.

The create() and generateLevel() methods are where most of this happens.

• Thank you for the advice. I have looked at his code and he successfully achieves an effect similar to what I would like, however I just can't seem to get it to function correctly. I adjusted my code to set the screen size for flixel accordingly, and set the camera to follow as shown in his demo: /*Add camera and set it to follow The Climber*/ //which will automatically set the boundaries of the world. FlxG.camera.setBounds(0,1280,640,1280,true); FlxG.camera.follow(TheClimber,FlxCamera.STYLE_PLATFORMER); Except in reverse, since I want the character to start at the bottom. – Christian Jan 31 '13 at 3:00
• FlxG.camera.setBounds(0,1280,640,1280,true); should be FlxG.camera.setBounds(0,0,640,1280,true);. The world will always have be 0,0 for the top left in Flixel. If you want your player to start at the bottom just make his start position something like 320, 1200. – NoobsArePeople2 Jan 31 '13 at 3:39
• Oh wow, stupid mistake on my part. Thank you for the update though,I am at work now but I am super excited to try this when I get home. – Christian Jan 31 '13 at 18:05

I don't know if you've gotten your answer im quite new to flixel and as3 myself , but ill tell you what i have i got my code open right now .. I see i put FlxG.camera.follow(player, FlxCamera.STYLE_PLATFORMER); FlxG.camera.setBounds(0, 0, map.width - 16, map.height); FlxG.worldBounds = new FlxRect(0, 0, map.width - 16, map.height); Background.scrollFactor = new FlxPoint();

These are the codee for my camera .. The scroll factor is so the background doesnt leave the screen when you move the world bounds is so your player doesnt fall through the floor when he goes to far and the camera.setbounds is so the camera doesnt go off screen this is what i just learned about yesterday so im not a professional or anything. . you should use the flixel tutorial on newgrounds its sort of like playing a game when you learn it but it helps alot