HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Back to HaxeFlixel.com
    • Screen
    • Adding
    • Alive
    • Health
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
    • FlxText
    • FlxBitmapText
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
    • Basic Group
    • Typed Group
    • Recycling
    • Sorting
    • Tileblock
    • Tilemap
    • Ray
    • tileProperties
    • Autotiles
    • Simple Overlap
    • Overlap Callbacks
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
    • Flash
    • Fade
    • Shake
    • Follow
    • scrollFactor
    • Basics
    • Keyboard
    • Gamepad
    • Mouse
    • Button
    • FlxSound
    • FlxState
    • FlxSubState
    • Tween
    • Angle
    • Color
    • Motion
    • Num
    • Callbacks
    • FlxTimer
    • FlxSignal
    • moveTowards
    • Distance
    • velocityFromAngle
    • timeScale
    • drawLine

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

View Source on GitHub

package;

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

class PlayState extends FlxState
{
	override public function create()
	{
		bgColor = 0;

		super.create();

		var text = new FlxText(0, 0, FlxG.width,
			"The Screen's dimensions\nare " + FlxG.width + "x" + FlxG.height + " pixels", 12);

		text.color = 0xff000000;
		text.alignment = FlxTextAlign.CENTER;
		text.setBorderStyle(FlxTextBorderStyle.SHADOW, 0xFF808080);
		text.screenCenter();
		add(text);
	}
}

Tags

screen basics
Powered By HaxeFlixel Logo HaxeFlixel