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

Adding

A FlxObject will not appear on the screen, until it has been added to the current FlxState (or a child of the current state).

The order a FlxObject is added determines their order within that object’s members. Typically, each FlxObject is drawn, and updated, depending on this order, with all the children of an object being updated/drawn when their parent is.

// add object to the current state
add(object);

Demonstration

Source

source/PlayState.hx

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;

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

        var box = new FlxSprite("assets/bigbox.png");
        box.screenCenter();

        var sprite = new FlxSprite("assets/sprite.png");
        sprite.screenCenter();

        add(box);
        add(sprite);
    }
}
View Source on GitHub

See Also

  • States
  • Groups

Tags

basics
  1. Home
  2. Basics
  3. Adding
Powered By HaxeFlixel Logo HaxeFlixel