### Install and Setup Flixel Tools Source: https://haxeflixel.com/documentation/upgrade-guide-3-x Install the new Flixel command-line tools from haxelib. Run the setup command to configure them for your project. ```bash haxelib install flixel-tools haxelib run flixel-tools setup ``` -------------------------------- ### Setup Additional Libraries with Lime Source: https://haxeflixel.com/documentation/install-haxeflixel Installs additional libraries such as addons, UI components, demos, and templates in a single step. This command requires Lime to be installed. ```bash haxelib run lime setup flixel ``` -------------------------------- ### Install Haxelib Library Source: https://haxeflixel.com/documentation/using-haxelib Installs a Haxelib library from the official repository. Replace `` with the name of the library you want to install. ```bash haxelib install ``` -------------------------------- ### Setup flixel-tools Source: https://haxeflixel.com/documentation/flixel-tools Run the setup command for flixel-tools to initialize it for use. This allows the `flixel` alias to be recognized in your console. ```bash haxelib run flixel-tools setup ``` -------------------------------- ### Install flixel-addons Source: https://haxeflixel.com/documentation/flixel-addons Use this command to install the flixel-addons library via haxelib. Ensure you have haxelib set up correctly. ```bash haxelib install flixel-addons ``` -------------------------------- ### Install Flixel Tools Source: https://haxeflixel.com/documentation/install-haxeflixel Installs flixel-tools, which are necessary for project templates and other development utilities. This involves two steps: installing the package and then running its setup command. ```bash haxelib install flixel-tools ``` ```bash haxelib run flixel-tools setup ``` -------------------------------- ### Install Haxelib Library from Git Source: https://haxeflixel.com/documentation/using-haxelib Installs a Haxelib library directly from a Git repository. Specify the library name, the Git URL, and optionally a branch name. ```bash haxelib git ``` -------------------------------- ### Start a FlxTimer Source: https://haxeflixel.com/documentation/cheat-sheet Create and start a new FlxTimer. Specify the duration in seconds, the callback function, and the number of loops. ```haxe // time (seconds), callback, loops new FlxTimer().start(10.0, myCallback, 3); ``` -------------------------------- ### Sprite Tween with Options Source: https://haxeflixel.com/documentation/flxtween This example demonstrates how to tween a sprite's position with various options including type, easing, onComplete callback, start delay, and loop delay. ```haxe public function new() { super(); // set up sprite sprite.x = 200; sprite.y = 200; FlxTween.tween(sprite, { x: 600, y: 800 }, 2, { type: FlxTween.PINGPONG, ease: FlxEase.quadInOut, onComplete: changeColor, startDelay: 1, loopDelay: 2 }); } function changeColor(tween:FlxTween):Void { // change the color of the sprite here } ``` -------------------------------- ### Install Additional Flixel Libraries from GitHub Source: https://haxeflixel.com/documentation/install-development-flixel Install other development versions of Flixel libraries like flixel-demos, flixel-addons, and flixel-ui from their respective GitHub repositories. These commands also enable the 'development directory' for each library. ```bash haxelib git flixel-demos https://github.com/HaxeFlixel/flixel-demos ``` ```bash haxelib git flixel-addons https://github.com/HaxeFlixel/flixel-addons ``` ```bash haxelib git flixel-ui https://github.com/HaxeFlixel/flixel-ui ``` -------------------------------- ### Example Game State with Player and Tilemap Source: https://haxeflixel.com/documentation/flxstate An example of a HaxeFlixel game state that includes a player sprite with physics and a tilemap for the level. Player movement is controlled via keyboard input, and jumping is implemented with a spacebar press. Remember to manage asset loading and ensure 'assets/player.png' and 'assets/level.csv' exist. ```haxe package; import flixel.tile.FlxTilemap; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.graphics.FlxGraphic; class FlxExampleState extends FlxState { var wizard:FlxSprite; var level:FlxTilemap; override public function create():Void { //create a main player wizard = new FlxSprite(200, 200, 'assets/player.png'); wizard.maxVelocity.set(80, 200); wizard.acceleration.y = 200; // gravity wizard.drag.x = wizard.maxVelocity.x * 4; add(wizard); //create a tilemap level level = new FlxTilemap(); level.loadMap('assets/level.csv', FlxGraphic.fromClass(GraphicAuto), 0, 0, AUTO); add(level); } override public function update(elapsed:Float):Void { //control the player with keyboard wizard.acceleration.x = 0; if (FlxG.keys.pressed.LEFT) { wizard.acceleration.x = -wizard.maxVelocity.x * 4; } if (FlxG.keys.pressed.RIGHT) { wizard.acceleration.x = wizard.maxVelocity.x * 4; } if (FlxG.keys.justPressed.SPACE && wizard.isTouching(FLOOR)) { wizard.velocity.y = -wizard.maxVelocity.y / 2; } super.update(elapsed); } } ``` -------------------------------- ### Install Flixel from GitHub Source: https://haxeflixel.com/documentation/install-development-flixel Use this command to install the latest development version of Flixel from its GitHub repository. This command enables the 'development directory' for the library. ```bash haxelib git flixel https://github.com/HaxeFlixel/flixel ``` -------------------------------- ### Setup Lime for Different Platforms Source: https://haxeflixel.com/documentation/haxeflixel-targets Use these commands to set up the necessary SDKs and system configurations for targeting specific platforms with Lime, which is used by HaxeFlixel. ```bash lime setup windows ``` ```bash lime setup mac ``` ```bash lime setup android ``` -------------------------------- ### Update FlxTimer Construction Source: https://haxeflixel.com/documentation/upgrade-guide-4-0-0 In HaxeFlixel 4.0.0, `FlxTimer` instances must be started explicitly using the `start()` method after construction. ```haxe // 3.3.x new FlxTimer(time, onComplete, loops); ``` ```haxe // 4.0.0 new FlxTimer().start(time, onComplete, loops); ``` -------------------------------- ### Install flixel-tools Source: https://haxeflixel.com/documentation/flixel-tools Install the flixel-tools package using haxelib. This command makes the flixel command-line alias available. ```bash haxelib install flixel-tools ``` -------------------------------- ### Install Older HaxeFlixel Versions (<= 5.9.0) Source: https://haxeflixel.com/documentation/install-haxeflixel For HaxeFlixel versions 5.9.0 and below, Lime and OpenFL must be installed explicitly before installing HaxeFlixel. ```bash haxelib install openfl ``` ```bash haxelib install lime ``` -------------------------------- ### Include Haxelib in Project Source: https://haxeflixel.com/documentation/using-haxelib Adds an installed Haxelib library to your HaxeFlixel project by referencing it in the `project.xml` file. Replace `` with the name of the library. ```xml ``` -------------------------------- ### Install Lime Command Source: https://haxeflixel.com/documentation/install-haxeflixel Installs the Lime command-line tool, which provides convenient access to Lime functionalities. This command makes 'lime' an alias for 'haxelib run lime'. ```bash haxelib run lime setup ``` -------------------------------- ### Example Action Set JSON Source: https://haxeflixel.com/documentation/actions An example of how action sets can be represented in JSON format, including multiple sets with their respective analog and digital actions. ```json { "actionSets" : [ { "name" : "SomeSet", "analogActions" : [ "some_analog_action_1", "some_analog_action_2" ], "digitalActions" : [ "some_digital_action_1", "some_digital_action_2" ] }, { "name" : "AnotherSet", "analogActions" : [ "another_analog_action_1", "another_analog_action_2" ], "digitalActions" : [ "another_digital_action_1", "another_digital_action_2" ] } ] } ``` -------------------------------- ### Conditional Compilation Example Source: https://haxeflixel.com/documentation/haxeflixel-conditionals Use conditional compilation to include platform-specific input controls. This example shows how to enable keyboard and mouse controls for web or desktop, gamepad controls for desktop, and touch controls for mobile. ```haxe #if (web || desktop) keyboardControls(); mouseControls(); #end #if desktop gamepadControls(); #end #if mobile touchControls(); #end ``` -------------------------------- ### Install Latest Stable HaxeFlixel Source: https://haxeflixel.com/documentation/install-haxeflixel Installs the latest stable version of HaxeFlixel and its dependencies, Lime and OpenFL. This is the recommended method for most users. ```bash haxelib install flixel ``` -------------------------------- ### FlxState - Important Methods Source: https://haxeflixel.com/documentation/flxstate Key methods within FlxState for managing game states, including setup, object management, and frame updates. ```APIDOC ## FlxState Methods ### create() This method is called before the state begins rendering. It is the ideal place to set up and create all objects for the current state, such as level tilemaps, player sprites, and initial enemies. ### add(object:FlxBasic) Adds sprites, tilemaps, and other game objects to the state for rendering. This functions similarly to OpenFL's `addChild()` method. ### remove(object:FlxBasic) Removes sprites and other objects that were previously added to the state. Removed objects are not destroyed and can be added back later. For objects no longer needed, consider freeing memory by setting them to null. ### update(elapsed:Float) This method is executed on every frame of the game. It is used for handling input controls, triggering movement, and implementing most gameplay logic. ``` -------------------------------- ### Update FlxTween and FlxTimer Usage Source: https://haxeflixel.com/documentation/upgrade-guide-3-x Pooling has been removed from FlxTimer and FlxPath. Use `new FlxTimer()` or `new FlxPath()` instead of `start()`, and `start()` instead of `run()`. ```haxe start() run() ``` ```haxe new FlxTimer() / FlxPath() start() ``` -------------------------------- ### Configure Initial Game State with Fullscreen Preference Source: https://haxeflixel.com/documentation/multiple-platforms Modify the main game initialization to load the saved fullscreen preference before creating the FlxGame instance. This ensures the game starts in the correct display mode on desktop. ```haxe var startFullscreen:Bool = false; var save:FlxSave = new FlxSave(); save.bind("TurnBasedRPG"); #if desktop if (save.data.fullscreen != null) { startFullscreen = save.data.fullscreen; } #end super(); addChild(new FlxGame(320, 240, MenuState, 1, 60, 60, false, startFullscreen)); if (save.data.volume != null) { FlxG.sound.volume = save.data.volume; } save.close(); ``` -------------------------------- ### Creating a Basic Tween Source: https://haxeflixel.com/documentation/flxtween This example demonstrates how to create a simple tween to move a FlxSprite to a target position over a specified duration. ```APIDOC ## FlxTween.tween() ### Description Creates a tween to interpolate properties of an object. ### Method `FlxTween.tween(object, properties, duration)` ### Parameters - **object** (Object) - The object whose properties will be tweened. - **properties** (Map) - A map of property names to their target values. - **duration** (Float) - The duration of the tween in seconds. ### Request Example ```haxe sprite.x = 200; sprite.y = 200; FlxTween.tween(sprite, { x: 600, y: 800 }, 2); ``` ### Response Returns an `FlxTween` object that can be used to control the tween. ``` -------------------------------- ### FlxSprite Renaming Examples Source: https://haxeflixel.com/documentation/upgrade-guide-3-x Illustrates renamed methods and properties in `FlxSprite` for improved API consistency. ```haxe loadGraphicFromSprite(); setGraphicSize(); bakedRotationAngle; overlapsPoint(); loadGraphicFromTexture(); loadRotatedGraphicFromTexture(); setColorTransform(); ``` -------------------------------- ### Shader Syntax with OpenFL 3.6.1 + Next Source: https://haxeflixel.com/documentation/upgrade-guide-4-0-0 Example of a custom shader class using OpenFL 3.6.1 + Next syntax. This is for reference when comparing to OpenFL 8 syntax. ```haxe import openfl.display.Shader; class Invert extends Shader { @fragment var fragment = ' void main() { vec4 color = texture2D(${Shader.uSampler}, ${Shader.vTexCoord}); gl_FragColor = vec4((1.0 - color.r) * color.a, (1.0 - color.g) * color.a, (1.0 - color.b) * color.a, color.a); } '; public function new() { super(); } } ``` -------------------------------- ### Play Looping Background Music in HaxeFlixel Source: https://haxeflixel.com/documentation/sound-and-music Add this to the `create()` function of your `MenuState` to start background music. It checks if music is already playing to avoid restarting. ```haxe if (FlxG.sound.music == null) // don't restart the music if it's already playing { FlxG.sound.playMusic(AssetPaths.HaxeFlixel_Tutorial_Game__ogg, 1, true); } ``` -------------------------------- ### FlxTween Start Delay Option Source: https://haxeflixel.com/documentation/cheat-sheet Specify a delay in seconds before the tween begins its animation. ```haxe {startDelay: 2.0} // 2 seconds ``` -------------------------------- ### Start Combat Sequence in Haxe Source: https://haxeflixel.com/documentation/ui-and-combat Sets up the combat state by activating the `inCombat` flag, deactivating player and enemies, and initializing the CombatHUD. This function is called by `playerTouchEnemy`. ```haxe function startCombat(enemy:Enemy) { inCombat = true; player.active = false; enemies.active = false; combatHud.initCombat(health, enemy); } ``` -------------------------------- ### Compiling and Testing Neko Target Source: https://haxeflixel.com/documentation/neko This command compiles and tests your project using the Neko target. Ensure you have the Neko target installed via Lime. ```bash lime test neko ``` -------------------------------- ### Shader Syntax with OpenFL 8 Source: https://haxeflixel.com/documentation/upgrade-guide-4-0-0 Example of a custom shader class using OpenFL 8 syntax. Note the use of `flixel.system.FlxAssets.FlxShader`, `@:glFragmentSource`, and updated attribute names. ```haxe import flixel.system.FlxAssets.FlxShader; class Invert extends FlxShader { @:glFragmentSource(' #pragma header void main() { vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv); gl_FragColor = vec4((1.0 - color.r) * color.a, (1.0 - color.g) * color.a, (1.0 - color.b) * color.a, color.a); }') public function new() { super(); } } ``` -------------------------------- ### Create a new demo project Source: https://haxeflixel.com/documentation/flixel-tools Use the `create` command to generate a new demo project. If no name or number is provided, it will list available demos and prompt for a selection. ```bash flixel create ``` -------------------------------- ### Create Project from Demo with VSCode Configuration Source: https://haxeflixel.com/documentation/visual-studio-code Generate a new project based on an existing demo, automatically configuring it for VSCode. ```bash flixel create -ide vscode ``` -------------------------------- ### Check Universal Gamepad Input Source: https://haxeflixel.com/documentation/gamepads Example of checking for gamepad button presses and analog stick movement using the universal gamepad API. Ensure to check if the gamepad object is not null as it can be null if no active gamepad is connected. ```haxe import flixel.FlxG; import flixel.FlxState; import flixel.input.gamepad.FlxGamepad; class PlayState extends FlxState { override public function update(elapsed:Float):Void { super.update(elapsed); // Important: can be null if there's no active gamepad yet! var gamepad:FlxGamepad = FlxG.gamepads.lastActive; if (gamepad != null) { updateGamepadInput(gamepad); } } function updateGamepadInput(gamepad:FlxGamepad):Void { if (gamepad.pressed.A) { trace("The bottom face button of the controller is pressed."); } if (gamepad.analog.justMoved.LEFT_STICK_X) { trace("The x axis of the left analog stick of the controller has been moved."); } } } ``` -------------------------------- ### Verify flixel-addons Installation Source: https://haxeflixel.com/documentation/flixel-addons After installation, you can verify that flixel-addons is recognized by haxelib using this command. ```bash haxelib list ``` -------------------------------- ### Upgrade Haxelib Libraries Source: https://haxeflixel.com/documentation/using-haxelib Updates all installed Haxelib libraries, including those installed from Git, to their latest available versions. ```bash haxelib upgrade ``` -------------------------------- ### Configure Desktop-Specific Window Settings Source: https://haxeflixel.com/documentation/desktop-targets Enable hardware acceleration and shaders for the C++ target. VSync and antialiasing can also be configured. ```xml ``` ```xml ``` ```xml || ``` -------------------------------- ### Project XML Window Settings Source: https://haxeflixel.com/documentation/android Configure window properties like resolution and background color in the project.xml file. A width or height of 0 uses the full display resolution. ```xml ``` -------------------------------- ### Create New Project with VSCode Configuration Source: https://haxeflixel.com/documentation/visual-studio-code Use the 'flixel template' command to create a new HaxeFlixel project with VSCode configuration files included. ```bash flixel template -n "VSCodeTest" -ide vscode ``` -------------------------------- ### Initialize MenuState UI Elements Source: https://haxeflixel.com/documentation/game-over-menu In the MenuState's create function, instantiate and configure the title text and options button. Position them appropriately alongside the existing play button to create a more complete menu interface. ```haxe titleText = new FlxText(20, 0, 0, "HaxeFlixel\nTutorial\nGame", 22); titleText.alignment = CENTER; titleText.screenCenter(X); add(titleText); playButton = new FlxButton(0, 0, "Play", clickPlay); playButton.x = (FlxG.width / 2) - playButton.width - 10; playButton.y = FlxG.height - playButton.height - 10; add(playButton); optionsButton = new FlxButton(0, 0, "Options", clickOptions); optionsButton.x = (FlxG.width / 2) + 10; optionsButton.y = FlxG.height - optionsButton.height - 10; add(optionsButton); ``` -------------------------------- ### Import FlxTween Source: https://haxeflixel.com/documentation/cheat-sheet Import the FlxTween and FlxEase classes for creating animations and transitions. ```haxe import flixel.tweens.FlxTween; import flixel.tweens.FlxEase; ``` -------------------------------- ### Compile and Test Desktop Targets Source: https://haxeflixel.com/documentation/desktop-targets Use the 'lime test' command to compile and automatically launch your application for the specified desktop platform. ```bash lime test windows ``` ```bash lime test mac ``` ```bash lime test linux -64 ``` -------------------------------- ### Initialize Fullscreen Button on Desktop Source: https://haxeflixel.com/documentation/multiple-platforms Create and add a fullscreen toggle button to the OptionsState when compiling for desktop. The button's text reflects the current fullscreen state. ```haxe #if desktop fullscreenButton = new FlxButton(0, volumeBar.y + volumeBar.height + 8, FlxG.fullscreen ? "FULLSCREEN" : "WINDOWED", clickFullscreen); fullscreenButton.screenCenter(X); add(fullscreenButton); #end ``` -------------------------------- ### Import FlxTimer Source: https://haxeflixel.com/documentation/cheat-sheet Import the FlxTimer class for creating timed events. ```haxe import flixel.util.FlxTimer; ``` -------------------------------- ### Add FlxText to PlayState Source: https://haxeflixel.com/documentation/creating-a-new-project Add this code to the `create()` function in your `PlayState.hx` file to display 'Hello, World!' on the screen. Ensure `flixel.text.FlxText` is imported. ```haxe var text = new FlxText(10, 10, 100, "Hello, World!"); add(text); ``` -------------------------------- ### Initialize and Add Player in PlayState Source: https://haxeflixel.com/documentation/groundwork Creates a new Player instance at position (20, 20) and adds it to the PlayState. This should be done before super.create(). ```haxe player = new Player(20, 20); add(player); ``` -------------------------------- ### FlxSprite Initialization and Graphic Loading Source: https://haxeflixel.com/documentation/flxsprite Demonstrates how to create a new FlxSprite and load a graphic from a file using loadGraphic(). ```APIDOC ## loadGraphic() ### Description This method is the easiest way to use a single image for your FlxSprite. Using the OpenFL asset system defined in the project xml file you simply have to define a path to your image and the compiler will do the rest. ### Method loadGraphic ### Parameters - **Graphic Path** (string) - Path to the image asset. ### Request Example ```Haxe var player = new FlxSprite(); player.loadGraphic("assets/player.png"); add(player); ``` ``` -------------------------------- ### Get Touch Position Source: https://haxeflixel.com/documentation/cheat-sheet Retrieve the touch coordinates, either relative to the world space or the screen. ```haxe // Relative to world space touch.x; touch.y; // Relative to screen touch.screenX; touch.screenY; ``` -------------------------------- ### Create New HaxeFlixel Project Source: https://haxeflixel.com/documentation/hello-world Use the 'flixel tpl' command to generate a new HaxeFlixel project structure. Ensure you are in the desired parent directory before running. ```bash cd C:\\Users\\\\Projects flixel tpl -n "HelloWorld" ``` -------------------------------- ### FlxSprite Size Properties Source: https://haxeflixel.com/documentation/flxsprite Details how to get and set the width and height of a FlxSprite's hitbox. ```APIDOC #### Size: width, height ### Description Automatically set in `loadGraphic()` or `makeGraphic()`, changing this will only affect the hitbox of this sprite, use `scale` to change the graphic's size. ### Example ```Haxe // get var getWidth = whiteSquare.width; // set whiteSquare.width = 100; whiteSquare.height = 100; ``` ``` -------------------------------- ### Cancelling a Tween Source: https://haxeflixel.com/documentation/flxtween This example shows how to cancel an active tween, for instance, when a specific user input is detected. ```APIDOC ## FlxTween.cancel() ### Description Cancels an active tween. ### Method `tween.cancel()` ### Parameters None ### Request Example ```haxe var tween:FlxTween; public function new() { super(); // set up sprite tween = FlxTween.tween(sprite, { x:600, y:800 }, 2); } override public function update(elapsed:Float) { ssuper.update(elapsed); if (FlxG.keys.justPressed.SPACE) tween.cancel(); } ``` ``` -------------------------------- ### Configure Game Size and Camera Follow Source: https://haxeflixel.com/documentation/zoom-and-cameras Adjust the game's width and height in the FlxGame constructor and configure the camera to follow the player in the PlayState's create function. The lerp value helps smooth camera movement. ```haxe FlxG.camera.follow(player, TOPDOWN, 1); ``` -------------------------------- ### Set Haxelib Library Version Source: https://haxeflixel.com/documentation/using-haxelib Changes the active version of an installed Haxelib library. Use this when you need to switch to a specific version. ```bash haxelib set ``` -------------------------------- ### Create a new project from a template Source: https://haxeflixel.com/documentation/flixel-tools Generate a new project using the default template with the `template` command. Any folder within `flixel-templates` can be used as a custom template. ```bash flixel tpl -n ``` ```bash flixel tpl ``` -------------------------------- ### Play Combat Music Source: https://haxeflixel.com/documentation/sound-and-music Plays the main combat music. This is typically called when entering the combat phase, for example, in an initCombat() method. ```haxe combatSound.play(); ``` -------------------------------- ### Use Flixel Command Line Tools Source: https://haxeflixel.com/documentation/upgrade-guide-3-x Access Flixel commands directly using 'flixel'. Use 'flixel help' for general assistance or 'flixel help template' for template-specific options. ```bash flixel help //see the new template tool options with: flixel help template //Shorthand version to create a template with a custom name flixel tpl -n "CustomProject" ``` -------------------------------- ### Update FlxPath Path Assignment Source: https://haxeflixel.com/documentation/upgrade-guide-4-0-0 In HaxeFlixel 4.0.0, `FlxPath` is now assigned to an `FlxObject`'s `path` property instead of being started directly with the object. ```haxe // 3.3.x var path = new FlxPath().start(object, points); ``` ```haxe // 4.0.0 object.path = new FlxPath().start(points); ``` -------------------------------- ### Initialize and Add Coin Group Source: https://haxeflixel.com/documentation/pickups Initialize the coin group and add it to the state in the create() method. This should be done after adding walls and before initializing the player. ```haxe coins = new FlxTypedGroup(); add(coins); ``` -------------------------------- ### Create Player Class Extending FlxSprite Source: https://haxeflixel.com/documentation/groundwork Defines a basic Player class that extends FlxSprite. Use this as a starting point for your player character. ```haxe package; import flixel.FlxSprite; class Player extends FlxSprite { public function new(x:Float = 0, y:Float = 0) { super(x, y); } } ``` -------------------------------- ### Fade Camera In Source: https://haxeflixel.com/documentation/polish Use this to fade the camera in, typically at the start of a state or screen. It takes the color, duration, and a boolean indicating if it's a fade-in. ```haxe FlxG.camera.fade(FlxColor.BLACK, 0.33, true); ``` -------------------------------- ### Create New HaxeFlixel Project Source: https://haxeflixel.com/documentation/creating-a-new-project Use this command to generate a new HaxeFlixel project with the blank template and open it in VSCode. Replace 'TurnBasedRPG' with your desired project name. ```bash flixel tpl -n "TurnBasedRPG" -ide vscode ``` -------------------------------- ### Get Mouse Screen Position Source: https://haxeflixel.com/documentation/mouse Access the `x` and `y` coordinates of the mouse relative to the game screen. `getScreenPosition()` returns these coordinates as a `FlxPoint` object. ```haxe FlxG.mouse.screenX FlxG.mouse.screenY FlxG.mouse.getScreenPosition(); // returns screenX / screenY as a FlxPoint ``` -------------------------------- ### Add FlxText to PlayState Source: https://haxeflixel.com/documentation/hello-world Integrate 'Hello World' text into your HaxeFlixel game by adding FlxText to the create() function of your PlayState. This centers the text and sets its font size. ```haxe package; import flixel.FlxState; class PlayState extends FlxState { override public function create() { super.create(); } override public function update(elapsed:Float) { super.update(elapsed); } } ``` ```haxe override public function create() { super.create(); var text = new flixel.text.FlxText(0, 0, 0, "Hello World", 64); text.screenCenter(); add(text); } ``` -------------------------------- ### Get Mouse World Position Source: https://haxeflixel.com/documentation/mouse Access the absolute `x` and `y` coordinates of the mouse in the game world. `getWorldPosition()` returns these coordinates as a `FlxPoint` object. ```haxe FlxG.mouse.x FlxG.mouse.y FlxG.mouse.getWorldPosition(); // returns x / y as a FlxPoint ``` -------------------------------- ### Load and Configure Enemy Footstep Sound in HaxeFlixel Source: https://haxeflixel.com/documentation/sound-and-music Load the footstep sound in the enemy's constructor with a reduced volume (0.4) and set up proximity-based audio. This prevents the sound from being too loud when multiple enemies are present. ```haxe stepSound = FlxG.sound.load(AssetPaths.step__wav, 0.4); stepSound.proximity(x, y, FlxG.camera.target, FlxG.width * 0.6); ``` -------------------------------- ### Get Mouse Wheel Delta Source: https://haxeflixel.com/documentation/cheat-sheet Access the current delta value of the mouse wheel. Positive for scroll up, negative for scroll down, zero if no scroll. ```haxe FlxG.mouse.wheel; ``` -------------------------------- ### Get and Set Sprite Dimensions Source: https://haxeflixel.com/documentation/flxsprite Retrieve or modify the width and height of a sprite's hitbox. Note that this does not change the visual size of the graphic. ```haxe // get var getWidth = whiteSquare.width; // set whiteSquare.width = 100; whiteSquare.height = 100; ``` -------------------------------- ### Adding a FlxCamera using FrontEnds Source: https://haxeflixel.com/documentation/upgrade-guide-3-x Camera management has been moved to the 'cameras' frontend. Use FlxG.cameras.add() to add a FlxCamera, replacing the older FlxG.addCamera() method. ```haxe FlxG.cameras.add(camera:FlxCamera); ``` -------------------------------- ### Import FlxSignal Source: https://haxeflixel.com/documentation/cheat-sheet Import the FlxSignal class for event handling. ```haxe import flixel.util.FlxSignal; ``` -------------------------------- ### Create FlxSignal Instances Source: https://haxeflixel.com/documentation/cheat-sheet Instantiate FlxSignal for events without data, or FlxTypedSignal for events with specific data types. ```haxe // for signals that don't need data, use FlxSignal var signal = new FlxSignal(); // for signals that need data, use FlxTypedSignal with the correct function type var stringSignal = new FlxTypedSignalVoid>(); ``` -------------------------------- ### Register Custom Console Command Source: https://haxeflixel.com/documentation/debugger Registers a Haxe function as a console command. This example spawns an enemy at the mouse position when the 'spawnEnemy' command is executed. ```haxe // in PlayState#create() FlxG.console.registerFunction("spawnEnemy", function() { var mousePos = FlxG.mouse.getWorldPosition(); var enemy = _enemies.recycle(Enemy); enemy.init(Std.int(mousePos.x), Std.int(mousePos.y), _enemyBullets, _bigGibs, _player); }); ``` -------------------------------- ### Checking Action Triggers in Update Loop Source: https://haxeflixel.com/documentation/actions Example of how to check the 'triggered' property of actions within the game's update loop to execute corresponding functions. ```haxe function updateLoop() { if (jump.triggered) doJump(); if (shoot.triggered) doShoot(); } ``` -------------------------------- ### Shake Camera on Player Hurt Source: https://haxeflixel.com/documentation/polish Add a brief screen shake effect when the player gets hurt to provide visual feedback. This is called after a flash effect. ```haxe FlxG.camera.shake(0.01, 0.2); ``` -------------------------------- ### Switching FlxStates Source: https://haxeflixel.com/documentation/cheat-sheet Transitions the game to a new state using `FlxG.switchState()`. Ensure the new state is instantiated. ```haxe FlxG.switchState(new MyState()); HAXE ``` -------------------------------- ### Update HaxeFlixel Source: https://haxeflixel.com/documentation/install-haxeflixel Updates an existing installation of HaxeFlixel to the latest available version. To update other libraries like 'flixel-addons', simply replace 'flixel' with the desired library name. ```bash haxelib update flixel ``` -------------------------------- ### FlxText Formatting and Styling Source: https://haxeflixel.com/documentation/cheat-sheet Imports necessary classes for text display and color manipulation. Use `setFormat` for font, size, color, and alignment, and `setBorderStyle` for outline effects. ```haxe import flixel.text.FlxText; import flixel.util.FlxColor; HAXE ``` ```haxe myText = new FlxText(0, 0, 500); // x, y, width myText.text = "Hello World"; myText.setFormat("assets/font.ttf", 20, FlxColor.WHITE, CENTER); myText.setBorderStyle(OUTLINE, FlxColor.RED, 1); HAXE ``` -------------------------------- ### Configure VSCode for Multiple Projects Source: https://haxeflixel.com/documentation/visual-studio-code Apply VSCode configuration files to an entire directory of projects, such as flixel-demos. ```bash flixel configure C:\HaxeToolkit\haxe\lib\flixel-demos\git -ide vscode ``` -------------------------------- ### Recycle an Object from a Typed Group Source: https://haxeflixel.com/documentation/flxgroup Retrieve an available instance of a specific class from a typed group for reuse. This is commonly used in object pooling to get a bullet instance. ```haxe var bullet = bullets.recycle(Bullet); HAXE ``` -------------------------------- ### Get and Release FlxPoint from Pool Source: https://haxeflixel.com/documentation/cheat-sheet Obtain a FlxPoint from the pool for temporary use and release it back when done to allow for reuse. This is useful for managing tile sizes or other temporary point data. ```haxe var tileSize = FlxPoint.get(16, 16); var actionTileset = FlxTileFrames.fromGraphic(FlxG.bitmap.add("assets/images/ui/actions.png"), tileSize); // release it back in pool to reuse tileSize.put(); ``` -------------------------------- ### Create and Load a Sprite Source: https://haxeflixel.com/documentation/flxsprite Instantiate a FlxSprite and load a graphic from a file path. Add the sprite to the game. ```haxe var player = new FlxSprite(); player.loadGraphic("assets/player.png"); add(player); ``` -------------------------------- ### Move Sprite with FlxTween Source: https://haxeflixel.com/documentation/flxtween Use FlxTween.tween to animate sprite properties like x and y coordinates. The method assumes current values are the starting point and interpolates to the target values over a specified duration. ```haxe sprite.x = 200; sprite.y = 200; FlxTween.tween(sprite, { x: 600, y: 800 }, 2); ``` -------------------------------- ### Add VSCode Configuration to Existing Project Source: https://haxeflixel.com/documentation/visual-studio-code Integrate VSCode project settings into a current directory project using 'flixel configure'. ```bash flixel configure . -ide vscode ``` -------------------------------- ### Cancel FlxTween Animation Source: https://haxeflixel.com/documentation/flxtween Store the FlxTween object returned by FlxTween.tween to control its lifecycle. Call the cancel() method on the tween object to stop the animation prematurely, for example, in response to player input. ```haxe var tween:FlxTween; public function new() { super(); // set up sprite tween = FlxTween.tween(sprite, { x:600, y:800 }, 2); } override public function update(elapsed:Float) { super.update(elapsed); if (FlxG.keys.justPressed.SPACE) tween.cancel(); } ``` -------------------------------- ### Load Sprite with Animation Frames Source: https://haxeflixel.com/documentation/flxsprite Load a spritesheet, specifying frame dimensions, and then set up and play an animation. The `true` argument indicates a spritesheet. ```haxe player.loadGraphic("assets/player.png", true, 32, 36); player.animation.add("walk", [0, 1, 0, 2], 5, true); player.animation.play("walk"); ``` -------------------------------- ### Update Camera Follow Lead Source: https://haxeflixel.com/documentation/upgrade-guide-3-x The `FlxG.camera.followAdjust` method has been replaced by `FlxG.cameras.followLead.set`. ```haxe FlxG.camera.followAdjust(4, 5); ``` ```haxe FlxG.cameras.followLead.set(4, 5); ``` -------------------------------- ### Load Stored Volume on Game Start Source: https://haxeflixel.com/documentation/game-over-menu This code snippet initializes FlxSave, binds it to a specific save file, checks for a stored volume, applies it if found, and then closes the save. It's used to ensure the game remembers the user's volume preferences. ```haxe var save = new FlxSave(); save.bind("TurnBasedRPG"); if (save.data.volume != null) { FlxG.sound.volume = save.data.volume; } save.close(); ``` -------------------------------- ### Compile HaxeFlixel Project Source: https://haxeflixel.com/documentation/hello-world Compile and test your HaxeFlixel project for HTML5, Neko, HashLink, and Flash using the 'lime test' command. Navigate to the project directory first. ```bash cd HelloWorld lime test html5 lime test hl lime test neko lime test flash ``` -------------------------------- ### Detect Mouse Wheel Scrolling Source: https://haxeflixel.com/documentation/mouse Check the `wheel` property for changes in mouse wheel activity. A positive value indicates scrolling up, a negative value indicates scrolling down, and 0 means no scroll in the current frame. This example shows zooming the camera based on wheel movement. ```haxe if (FlxG.mouse.wheel != 0) { // Mouse wheel logic goes here, for example zooming in / out: FlxG.camera.zoom += (FlxG.mouse.wheel / 10); } ``` -------------------------------- ### Configuring Asset Loading for Sound Source: https://haxeflixel.com/documentation/cheat-sheet Modifies the `Project.xml` to handle sound file formats based on the target platform. Excludes OGG for Flash and MP3 for other platforms. ```xml XML ``` -------------------------------- ### Enable Flixel Record System Source: https://haxeflixel.com/documentation/haxeflixel-conditionals Enable HaxeFlixel's recording and playback feature by adding this node to your Project XML file. This feature captures mouse and keyboard input. ```xml ``` -------------------------------- ### Initialize Directional Input Variables Source: https://haxeflixel.com/documentation/groundwork Initializes boolean variables to track player input for up, down, left, and right movement. ```haxe var up:Bool = false; var down:Bool = false; var left:Bool = false; var right:Bool = false; ``` -------------------------------- ### Update SubState Handling Source: https://haxeflixel.com/documentation/upgrade-guide-3-x The `FlxState.setSubState` method has been renamed to `FlxState.openSubState`. ```haxe FlxState.setSubState() ``` ```haxe FlxState.openSubState() ``` -------------------------------- ### Update FlxTween MultiVar Delay Source: https://haxeflixel.com/documentation/upgrade-guide-3-x The `delay` parameter in `FlxTween.multiVar` has been renamed to `startDelay`. ```haxe FlxTween.multiVar(object, vars, duration, { delay: 1}); ``` ```haxe FlxTween.multiVar(object, vars, duration, { startDelay: 1}); ``` -------------------------------- ### Define MenuState Class in HaxeFlixel Source: https://haxeflixel.com/documentation/groundwork This snippet defines the basic structure for a MenuState in HaxeFlixel. It extends FlxState and serves as the entry point for the game's menu. ```haxe class MenuState extends FlxState { HAXE ``` -------------------------------- ### Load Footstep Sound in HaxeFlixel Player Constructor Source: https://haxeflixel.com/documentation/sound-and-music Load the footstep sound effect in the player's constructor using `FlxG.sound.load`. ```haxe stepSound = FlxG.sound.load(AssetPaths.step__wav); ```