Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);


            /*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);

            /*add player to the game*/
            add(TheClimber);
        }

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.