HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Tutorials
  • Back to HaxeFlixel.com
  • Basics
    • Screen
    • Adding
  • Objects
    • Alive
    • Health
  • Sprites
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
  • Text
    • FlxText
    • FlxBitmapText
  • Movement
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
  • Groups
    • Basic Group
    • Typed Group
    • Recycling
  • Tiling
    • Tileblock
    • Tilemap
  • Overlap
    • Simple Overlap
    • Overlap Callbacks
  • Collision
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
  • Camera
    • Flash
    • Fade
    • Shake
    • Follow
  • Input
    • Basics
    • Keyboard
    • Mouse
    • Button
  • Sound
    • FlxSound

Screen

To get the screen’s dimensions, use width and height. These are useful for positioning objects.

screenWidth = FlxG.width;
screenHeight = FlxG.height;

Demonstration

Source

source/PlayState.hx

package;

import flixel.FlxG;
import flixel.FlxState;
import flixel.text.FlxText;

class PlayState extends FlxState
{
    override public function create()
    {
        super.create();

        var text = new FlxText(0, 0, FlxG.width,
            "The Screen's dimensions are " + FlxG.width + "x" + FlxG.height);
        text.alignment = FlxTextAlign.CENTER;
        text.setBorderStyle(FlxTextBorderStyle.SHADOW, 0xff333333);
        text.scale.set(1.5, 1.5);
        text.y = FlxG.height / 2 - text.height / 2;
        add(text);
    }
}
View Source on GitHub

Tags

screen basics
  1. Home
  2. Basics
  3. Screen
Powered By HaxeFlixel Logo HaxeFlixel