### Haxe Trace Example Source: https://github.com/haxeflixel/flixel/wiki/Contribution-Guide A basic example demonstrating how to use the 'trace' function in Haxe to output messages. This is often used for debugging. ```haxe trace("Hello, world!"); ``` -------------------------------- ### Create a Game State with FlxState Source: https://context7.com/haxeflixel/flixel/llms.txt Extend FlxState to create game screens. Override create() for setup and update() for per-frame logic. Use FlxG.switchState to transition between states. ```haxe import flixel.FlxState; import flixel.FlxG; import flixel.FlxSprite; import flixel.text.FlxText; import flixel.util.FlxColor; class PlayState extends FlxState { var player:FlxSprite; var scoreText:FlxText; var score:Int = 0; override public function create():Void { super.create(); bgColor = FlxColor.GRAY; player = new FlxSprite(100, 200); player.makeGraphic(32, 32, FlxColor.RED); add(player); scoreText = new FlxText(10, 10, 200, "Score: 0", 16); add(scoreText); } override public function update(elapsed:Float):Void { super.update(elapsed); scoreText.text = "Score: " + score; if (FlxG.keys.justPressed.ESCAPE) FlxG.switchState(MenuState.new); } } ``` -------------------------------- ### FlxAxes Bit Flags Example Source: https://github.com/haxeflixel/flixel/wiki/Flixel-5.0.0-Migration-guide Demonstrates the new bit flag values for FlxAxes. Use these for bitwise checks instead of the match method. ```haxe var X = 0x01; var Y = 0x10; var XY = 0x11; var NONE = 0x00; ``` -------------------------------- ### FlxGame Constructor: Original with Zoom Source: https://github.com/haxeflixel/flixel/wiki/Flixel-5.0.0-Migration-guide Example of the FlxGame constructor signature before Flixel 5.0.0, including the zoom argument that has since been removed. ```haxe new FlxGame( stage.stageWidth / 2, // width stage.stageHeight / 2, // height MenuState, // initial state 2, // zoom 60, // update framerate 60 // draw framerate ); ``` -------------------------------- ### Circular Motion with FlxTween Source: https://context7.com/haxeflixel/flixel/llms.txt Animate an object in a circular path using FlxTween.circularMotion. Parameters include center coordinates, radius, start angle, and direction. ```haxe // Circular motion FlxTween.circularMotion(enemy, 200, 200, 80, 0, true, 4.0, { type: LOOPING }); ``` -------------------------------- ### Initialize FlxGame Entry Point Source: https://context7.com/haxeflixel/flixel/llms.txt Instantiate FlxGame in your Main.hx to initialize the HaxeFlixel engine and set the initial game state. This is the root of your game. ```haxe import openfl.display.Sprite; import flixel.FlxGame; class Main extends Sprite { public function new() { super(); // FlxGame(gameWidth, gameHeight, initialState, updateFramerate, drawFramerate, skipSplash) addChild(new FlxGame(640, 480, PlayState.new, 60, 60, true)); } } ``` -------------------------------- ### Configure HTML5 Backend Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Set the HTML5 backend before including flixel. Use 'new-backend' for the latest implementation. ```haxe ``` -------------------------------- ### FlxG openURL() Enhancement Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog The openURL() function now automatically prepends 'http://' if the URL is missing the scheme. ```haxe FlxG.openURL() ``` -------------------------------- ### Basic FlxText for Labels Source: https://context7.com/haxeflixel/flixel/llms.txt Creates a basic text label with specified position, text content, and font size. The label automatically adjusts its width if the third parameter is 0. ```haxe import flixel.text.FlxText; import flixel.util.FlxColor; // Basic label, auto-sized var label = new FlxText(20, 20, 0, "Hello, HaxeFlixel!", 24); label.color = FlxColor.WHITE; add(label); ``` -------------------------------- ### Loading and Controlling Sounds Manually Source: https://context7.com/haxeflixel/flixel/llms.txt Load sounds using FlxG.sound.load for manual playback control and event handling like onComplete callbacks. ```haxe // Load a sound for manual control var explosion = FlxG.sound.load("assets/sounds/explosion.ogg"); explosion.onComplete = function() trace("boom done"); explosion.play(); ``` -------------------------------- ### FlxMath for Clamping and Interpolation Source: https://context7.com/haxeflixel/flixel/llms.txt Shows how to use FlxMath for clamping values within a range and performing linear interpolation between two numbers. Useful for game logic like health management and smooth movement. ```haxe import flixel.math.FlxMath; import flixel.math.FlxPoint; // Clamp a value to a range var hp = FlxMath.bound(newHp, 0, 100); // Linear interpolation var smoothX = FlxMath.lerp(current.x, target.x, 0.1); ``` -------------------------------- ### FlxColor Utility Functions Source: https://context7.com/haxeflixel/flixel/llms.txt Demonstrates various ways to create, manipulate, and convert colors using FlxColor, including named constants, RGB/HSL/String conversions, channel access, interpolation, inversion, and string formatting. ```haxe import flixel.util.FlxColor; // Named constants var red = FlxColor.RED; // 0xFFFF0000 var clear = FlxColor.TRANSPARENT; // From hex / components var c1 = FlxColor.fromRGB(255, 128, 0); // opaque orange var c2 = FlxColor.fromHSL(120, 1.0, 0.5); // pure green via HSL var c3 = FlxColor.fromString("PURPLE"); var c4:FlxColor = 0xFF00BFFF; // direct Int literal // Channel access c1.red = 200; c1.alpha = 180; trace(c1.hue, c1.saturation, c1.brightness); // Interpolation var mid = FlxColor.interpolate(FlxColor.RED, FlxColor.BLUE, 0.5); // purple // Invert / complement var inv = FlxColor.invert(FlxColor.GREEN); // 0xFFFF00FF (magenta) // To string trace(FlxColor.RED.toHexString()); // "FFFF0000" trace(FlxColor.RED.toWebString()); // "#FF0000" ``` -------------------------------- ### FlxKeyboard Key Detection Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Added firstPressed(), firstJustPressed(), and firstJustReleased() for detecting initial key states. Includes workarounds for native target key issues. ```haxe FlxKey.NUMPADMULTIPLY ``` ```haxe firstPressed() ``` ```haxe firstJustPressed() ``` ```haxe firstJustReleased() ``` -------------------------------- ### Create and Configure FlxEmitter for Particle Effects Source: https://context7.com/haxeflixel/flixel/llms.txt Demonstrates creating a particle emitter, configuring its properties like speed, lifespan, scale, and color, and launching it for visual effects. Use for explosions, rain, fire, or smoke. ```haxe import flixel.effects.particles.FlxEmitter; import flixel.util.FlxColor; // Create an explosion emitter var emitter = new FlxEmitter(); // Option A: coloured squares emitter.makeParticles(4, 4, FlxColor.ORANGE, 40); // Option B: image particles from a sprite sheet // emitter.loadParticles("assets/images/sparks.png", 50, 0, true); // Configure ranges emitter.speed.set(50, 200); emitter.lifespan.set(0.4, 1.2); emitter.alpha.set(1.0, 1.0, 0.0, 0.0); // fade out over lifetime emitter.scale.set(1.0, 1.0, 0.2, 0.2); // shrink over lifetime emitter.color.set(FlxColor.YELLOW, FlxColor.RED); emitter.acceleration.set(0, 0, 0, 200); // gravity emitter.launchMode = FlxEmitterMode.CIRCLE; add(emitter); // One-shot burst (e.g. on enemy death) emitter.setPosition(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2); emitter.start(true, 0, 30); // explode=true, lifespan ignored, quantity=30 // Continuous stream (e.g. torch flame) // emitter.start(false, 0.05); // explode=false, frequency=0.05 s ``` -------------------------------- ### FlxText - Text Rendering Source: https://context7.com/haxeflixel/flixel/llms.txt Shows how to create and style text objects, including word wrapping, alignment, and multi-format text. ```APIDOC ## FlxText — Text Rendering `FlxText` extends `FlxSprite` to display text. It supports embedded and system fonts, multiple format ranges, word-wrap, alignment, borders, and shadows. ```haxe import flixel.text.FlxText; import flixel.util.FlxColor; // Basic label, auto-sized var label = new FlxText(20, 20, 0, "Hello, HaxeFlixel!", 24); label.color = FlxColor.WHITE; add(label); // Fixed-width with word wrap var description = new FlxText(50, 100, 300, "Some long text that wraps.", 16); description.wordWrap = true; description.alignment = CENTER; add(description); // Multi-format ranges var richText = new FlxText(50, 200, 400, ""); richText.text = "WARNING: low health!"; richText.setFormat(null, 20, FlxColor.WHITE); // default style richText.addFormat(new FlxTextFormat(FlxColor.RED), 0, 7); // "WARNING" in red // Drop shadow / border richText.setBorderStyle(FlxTextBorderStyle.SHADOW, FlxColor.BLACK, 2, 1); add(richText); // Changing text dynamically each frame override public function update(elapsed:Float) { super.update(elapsed); label.text = "FPS: " + Math.round(1 / elapsed); } ``` ``` -------------------------------- ### Manage Game State and Services with FlxG Source: https://context7.com/haxeflixel/flixel/llms.txt Use FlxG for global game management, including state transitions, window resizing, collision detection, logging, and random number generation. Ensure necessary imports are included. ```haxe import flixel.FlxG; // State management FlxG.switchState(GameOverState.new); FlxG.resetState(); // re-create current state FlxG.resetGame(); // restart from the very beginning // Screen / window trace(FlxG.width); // game width in pixels trace(FlxG.height); // game height FlxG.resizeWindow(1280, 720); // desktop only // Overlap & collision (world-space, quadtree-accelerated) FlxG.overlap(playerGroup, enemyGroup, function(p, e) { cast(p, Player).takeDamage(10); e.kill(); }); FlxG.collide(playerGroup, wallTilemap); // Pixel-perfect sprite collision (slower, use sparingly) if (FlxG.pixelPerfectOverlap(sword, enemy, 128)) enemy.kill(); // Logging FlxG.log.add("hello"); FlxG.log.warn("watch out"); FlxG.log.error("something broke"); // Random numbers var roll = FlxG.random.int(1, 6); var chance = FlxG.random.float(0, 1.0); var item = FlxG.random.getObject(["sword", "shield", "potion"]); ``` -------------------------------- ### FlxEmitter - Particle Systems Source: https://context7.com/haxeflixel/flixel/llms.txt Demonstrates the creation and configuration of particle emitters for visual effects like explosions and rain. ```APIDOC ## FlxEmitter — Particle Systems `FlxEmitter` (alias for `FlxTypedEmitter`) is a lightweight, pooled particle emitter for explosions, rain, fire, smoke, and other visual effects. ```haxe import flixel.effects.particles.FlxEmitter; import flixel.util.FlxColor; // Create an explosion emitter var emitter = new FlxEmitter(); // Option A: coloured squares emitter.makeParticles(4, 4, FlxColor.ORANGE, 40); // Option B: image particles from a sprite sheet // emitter.loadParticles("assets/images/sparks.png", 50, 0, true); // Configure ranges emitter.speed.set(50, 200); emitter.lifespan.set(0.4, 1.2); emitter.alpha.set(1.0, 1.0, 0.0, 0.0); // fade out over lifetime emitter.scale.set(1.0, 1.0, 0.2, 0.2); // shrink over lifetime emitter.color.set(FlxColor.YELLOW, FlxColor.RED); emitter.acceleration.set(0, 0, 0, 200); // gravity emitter.launchMode = FlxEmitterMode.CIRCLE; add(emitter); // One-shot burst (e.g. on enemy death) emitter.setPosition(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2); emitter.start(true, 0, 30); // explode=true, lifespan ignored, quantity=30 // Continuous stream (e.g. torch flame) // emitter.start(false, 0.05); // explode=false, frequency=0.05 s ``` ``` -------------------------------- ### Manage Cameras and Viewports with FlxCamera Source: https://context7.com/haxeflixel/flixel/llms.txt Configure cameras for rendering, including zoom, background color, following game objects with dead zones, setting scroll bounds, and applying visual effects like flashes, fades, and shakes. Supports multiple cameras for split-screen. ```haxe import flixel.FlxCamera; import flixel.FlxG; // Default camera (always exists at FlxG.camera) FlxG.camera.zoom = 2.0; FlxG.camera.bgColor = 0xFF1a1a2e; // Follow the player with a platformer-style dead-zone FlxG.camera.follow(player, FlxCameraFollowStyle.PLATFORMER, 0.15); FlxG.camera.setScrollBoundsRect(0, 0, levelWidth, levelHeight); // Camera effects FlxG.camera.flash(0xFFFFFFFF, 0.3); // white flash for 0.3 s FlxG.camera.fade(0xFF000000, 1.0, false, function() { FlxG.switchState(NextLevel.new); // fade to black then switch }); FlxG.camera.shake(0.02, 0.5); // intensity 2%, duration 0.5 s // Split-screen: add a second camera for player 2 var cam2 = new FlxCamera(320, 0, 320, 480); cam2.follow(player2); FlxG.cameras.add(cam2); // Make a specific sprite render only on one camera mySprite.cameras = [cam2]; ``` -------------------------------- ### FlxText Shadow and Sizing Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Added shadowOffset and autoSize properties. Fixed issues with widthInc/heightInc in addFilter() and fieldWidth for accurate text display. ```haxe FlxText.shadowOffset ``` ```haxe FlxText.autoSize ``` ```haxe addFilter() ``` ```haxe fieldWidth ``` -------------------------------- ### Creating and Managing Object Groups Source: https://context7.com/haxeflixel/flixel/llms.txt Use FlxTypedGroup to manage collections of game objects, enabling batch operations. Pre-allocating with a size improves performance. ```haxe import flixel.group.FlxGroup; import flixel.FlxSprite; class PlayState extends FlxState { var bullets:FlxTypedGroup; var enemies:FlxTypedGroup; override public function create():Void { super.create(); // Pre-allocate a pool of 20 bullets bullets = new FlxTypedGroup(20); for (i in 0...20) { var b = new FlxSprite(); b.makeGraphic(4, 12, 0xFFFFFF00); b.kill(); // start inactive bullets.add(b); } add(bullets); enemies = new FlxTypedGroup(); enemies.memberAdded.add(function(e) trace("enemy spawned")); add(enemies); } function fireBullet(x:Float, y:Float):Void { var b = bullets.recycle(FlxSprite); // reuse a dead bullet b.reset(x, y); b.velocity.y = -400; } override public function update(elapsed:Float):Void { super.update(elapsed); FlxG.collide(bullets, enemies, function(b, e) { b.kill(); cast(e, Enemy).takeDamage(1); }); } } ``` -------------------------------- ### FlxColor - Color Utilities Source: https://context7.com/haxeflixel/flixel/llms.txt Explains how to use FlxColor for color manipulation, including creating colors from various formats and accessing color channels. ```APIDOC ## FlxColor — Color Utilities `FlxColor` is an abstract over `Int` that provides ARGB, HSB, HSL, and CMYK color manipulation. It can be used anywhere an `Int` is accepted. ```haxe import flixel.util.FlxColor; // Named constants var red = FlxColor.RED; // 0xFFFF0000 var clear = FlxColor.TRANSPARENT; // From hex / components var c1 = FlxColor.fromRGB(255, 128, 0); // opaque orange var c2 = FlxColor.fromHSL(120, 1.0, 0.5); // pure green via HSL var c3 = FlxColor.fromString("PURPLE"); var c4:FlxColor = 0xFF00BFFF; // direct Int literal // Channel access c1.red = 200; c1.alpha = 180; trace(c1.hue, c1.saturation, c1.brightness); // Interpolation var mid = FlxColor.interpolate(FlxColor.RED, FlxColor.BLUE, 0.5); // purple // Invert / complement var inv = FlxColor.invert(FlxColor.GREEN); // 0xFFFF00FF (magenta) // To string trace(FlxColor.RED.toHexString()); // "FFFF0000" trace(FlxColor.RED.toWebString()); // "#FF0000" ``` ``` -------------------------------- ### Create Tile-Based Levels with FlxTilemap Source: https://context7.com/haxeflixel/flixel/llms.txt Load and manage tile-based levels using FlxTilemap, supporting loading from CSV data and tile-sheet images. Enables pathfinding on the map and collision detection with other game objects. ```haxe import flixel.tile.FlxTilemap; import flixel.math.FlxPoint; class LevelState extends FlxState { var map:FlxTilemap; override public function create():Void { super.create(); map = new FlxTilemap(); // Load from a CSV string (0 = empty, 1+ = solid tiles) var csv = "1,1,1,1,1\n1,0,0,0,1\n1,0,1,0,1\n1,0,0,0,1\n1,1,1,1,1"; map.loadMapFromCSV(csv, "assets/images/tiles.png", 32, 32); add(map); // Pathfinding on the tilemap var start = new FlxPoint(32, 32); var end = new FlxPoint(128, 96); var path = map.findPath(start, end); if (path != null) trace("path has " + path.length + " nodes"); } override public function update(elapsed:Float):Void { super.update(elapsed); // Collide player against the tilemap FlxG.collide(player, map); } } ``` -------------------------------- ### FlxButton: Creating UI Buttons Source: https://context7.com/haxeflixel/flixel/llms.txt Creates clickable buttons with text labels and customizable appearance. Supports custom graphics and sound effects. Use for menu navigation or triggering actions. ```haxe import flixel.ui.FlxButton; import flixel.util.FlxColor; class MenuState extends FlxState { override public function create():Void { super.create(); var playBtn = new FlxButton(200, 150, "Play", onPlay); playBtn.label.setFormat(null, 20, FlxColor.WHITE); // Load custom button graphic (3-frame horizontal strip: normal/hover/pressed) // playBtn.loadGraphic("assets/images/button.png", true, 120, 40); add(playBtn); var quitBtn = new FlxButton(200, 220, "Quit", function() { Sys.exit(0); }); add(quitBtn); } function onPlay():Void { FlxG.sound.play("assets/sounds/click.ogg"); FlxG.switchState(PlayState.new); } } ``` -------------------------------- ### FlxMath and FlxVelocity for Distance and Velocity Calculations Source: https://context7.com/haxeflixel/flixel/llms.txt Illustrates calculating the distance between two sprites using FlxMath and determining the velocity components (vx, vy) towards a given angle and speed, using both FlxMath and FlxVelocity. ```haxe import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.math.FlxVelocity; // Distance between two points var d = FlxMath.distanceBetween(playerSprite, enemySprite); // Velocity toward an angle var speed = 150.0; var angle = -45.0; // degrees var vx = FlxMath.velocity(speed, angle); // x-component // Or use FlxVelocity var vel = FlxVelocity.velocityFromAngle(angle, speed); ``` -------------------------------- ### FlxTilemap Scale and Raycasting Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Replaced scaleX and scaleY with a single FlxPoint scale. Removed rayHit(), with ray() now providing the same functionality. ```haxe FlxTilemap.ray() ``` -------------------------------- ### Debugger Tracker Window Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Use FlxG.debugger.track() to open a tracker window for an object. Add custom profiles with FlxG.debugger.addTrackerProfile(). ```haxe FlxG.debugger.track(Object); ``` ```haxe FlxG.debugger.addTrackerProfile() ``` ```haxe "track [object]" ``` -------------------------------- ### Playing Background Music with FlxG.sound Source: https://context7.com/haxeflixel/flixel/llms.txt Use FlxG.sound.playMusic to play background music. It supports volume control and looping. ```haxe // Loop background music FlxG.sound.playMusic("assets/music/theme.ogg", 0.6, true); ``` -------------------------------- ### FlxCamera - Cameras and Viewports Source: https://context7.com/haxeflixel/flixel/llms.txt Manages what portion of the game world is rendered and where on screen, supporting multiple cameras, following game objects, zooming, shaking, and fading. ```APIDOC ## FlxCamera - Cameras and Viewports `FlxCamera` controls what portion of the game world is rendered and where on screen. HaxeFlixel supports multiple cameras simultaneously. Cameras can follow game objects, be zoomed, shaken, flashed, faded, and scrolled. ```haxe import flixel.FlxCamera; import flixel.FlxG; // Default camera (always exists at FlxG.camera) FlxG.camera.zoom = 2.0; FlxG.camera.bgColor = 0xFF1a1a2e; // Follow the player with a platformer-style dead-zone FlxG.camera.follow(player, FlxCameraFollowStyle.PLATFORMER, 0.15); FlxG.camera.setScrollBoundsRect(0, 0, levelWidth, levelHeight); // Camera effects FlxG.camera.flash(0xFFFFFFFF, 0.3); // white flash for 0.3 s FlxG.camera.fade(0xFF000000, 1.0, false, function() { FlxG.switchState(NextLevel.new); // fade to black then switch }); FlxG.camera.shake(0.02, 0.5); // intensity 2%, duration 0.5 s // Split-screen: add a second camera for player 2 var cam2 = new FlxCamera(320, 0, 320, 480); cam2.follow(player2); FlxG.cameras.add(cam2); // Make a specific sprite render only on one camera mySprite.cameras = [cam2]; ``` ``` -------------------------------- ### FlxG - Global Game Services Source: https://context7.com/haxeflixel/flixel/llms.txt The FlxG static class provides access to all engine subsystems, including state management, screen dimensions, collision detection, logging, and random number generation. ```APIDOC ## FlxG - Global Game Services `FlxG` is the static hub that exposes all engine subsystems: cameras, sound, input, logging, random, bitmap cache, signals, assets, and state management. ```haxe import flixel.FlxG; // State management FlxG.switchState(GameOverState.new); FlxG.resetState(); // re-create current state FlxG.resetGame(); // restart from the very beginning // Screen / window trace(FlxG.width); // game width in pixels trace(FlxG.height); // game height FlxG.resizeWindow(1280, 720); // desktop only // Overlap & collision (world-space, quadtree-accelerated) FlxG.overlap(playerGroup, enemyGroup, function(p, e) { cast(p, Player).takeDamage(10); e.kill(); }); FlxG.collide(playerGroup, wallTilemap); // Pixel-perfect sprite collision (slower, use sparingly) if (FlxG.pixelPerfectOverlap(sword, enemy, 128)) enemy.kill(); // Logging FlxG.log.add("hello"); FlxG.log.warn("watch out"); FlxG.log.error("something broke"); // Random numbers var roll = FlxG.random.int(1, 6); var chance = FlxG.random.float(0, 1.0); var item = FlxG.random.getObject(["sword", "shield", "potion"]); ``` ``` -------------------------------- ### AssetPaths: Include and Exclude Arguments Source: https://github.com/haxeflixel/flixel/wiki/Flixel-5.0.0-Migration-guide The `filterExtensions` argument in `AssetPaths` has been removed and replaced with `include` and `exclude`. These new arguments accept an `EReg` or a wildcard string for more flexible file filtering. ```haxe // Exclude everything in a folder called "test", and any .ase files FlxAssets.buildFileReferences(folder, "assets", "images", null, "*/test/*|*.ase"); // Equivalent using EReg FlxAssets.buildFileReferences(folder, "assets", "images", null, ~/ oys\/|\.ase/); ``` -------------------------------- ### Playing Sound Effects with FlxG.sound Source: https://context7.com/haxeflixel/flixel/llms.txt Use FlxG.sound.play to play short sound effects. The second argument controls the volume. ```haxe import flixel.FlxG; // Play a one-shot sound effect FlxG.sound.play("assets/sounds/jump.ogg", 0.8); // volume = 0.8 ``` -------------------------------- ### FlxTilemap - Tile-Based Levels Source: https://context7.com/haxeflixel/flixel/llms.txt Renders tile-based levels from a 1-D integer array or CSV string and a tile-sheet image, integrating with the collision system and supporting auto-tiling. ```APIDOC ## FlxTilemap - Tile-Based Levels `FlxTilemap` renders large tile-based levels from a 1-D integer array (or a CSV string) plus a tile-sheet image. It integrates with the collision system and supports auto-tiling. ```haxe import flixel.tile.FlxTilemap; import flixel.math.FlxPoint; class LevelState extends FlxState { var map:FlxTilemap; override public function create():Void { super.create(); map = new FlxTilemap(); // Load from a CSV string (0 = empty, 1+ = solid tiles) var csv = "1,1,1,1,1\n1,0,0,0,1\n1,0,1,0,1\n1,0,0,0,1\n1,1,1,1,1"; map.loadMapFromCSV(csv, "assets/images/tiles.png", 32, 32); add(map); // Pathfinding on the tilemap var start = new FlxPoint(32, 32); var end = new FlxPoint(128, 96); var path = map.findPath(start, end); if (path != null) trace("path has " + path.length + " nodes"); } override public function update(elapsed:Float):Void { super.update(elapsed); // Collide player against the tilemap FlxG.collide(player, map); } } ``` ``` -------------------------------- ### 3-D Positional Audio Source: https://context7.com/haxeflixel/flixel/llms.txt Implement proximity-based panning for sounds using footstep.proximity, defining the sound source's position and maximum audible distance. ```haxe // 3-D positional audio (proximity panning) var footstep = FlxG.sound.load("assets/sounds/step.ogg"); footstep.proximity(npc.x, npc.y, player, 200); // maxDistance = 200 px footstep.play(true); // looped ``` -------------------------------- ### FlxMath - Math Utilities Source: https://context7.com/haxeflixel/flixel/llms.txt Details the game-focused math helpers provided by FlxMath, such as clamping, interpolation, angle conversions, and distance calculations. ```APIDOC ## FlxMath — Math Utilities `FlxMath` offers game-focused math helpers: clamping, lerp, wrapping, rounding, angle conversions, distance, overlap tests, and velocity helpers. ```haxe import flixel.math.FlxMath; import flixel.math.FlxPoint; // Clamp a value to a range var hp = FlxMath.bound(newHp, 0, 100); // Linear interpolation var smoothX = FlxMath.lerp(current.x, target.x, 0.1); // Wrap an angle into -180..180 var angle = FlxMath.wrapAngle(390); // returns 30 // Round to a given number of decimal places var rounded = FlxMath.roundDecimal(3.14159, 2); // 3.14 // Integer in range check if (FlxMath.inBounds(score, 0, 999)) trace("valid score"); // Distance between two points var d = FlxMath.distanceBetween(playerSprite, enemySprite); // Velocity toward an angle var speed = 150.0; var angle = -45.0; // degrees var vx = FlxMath.velocity(speed, angle); // x-component // Or use FlxVelocity import flixel.math.FlxVelocity; var vel = FlxVelocity.velocityFromAngle(angle, speed); ``` ``` -------------------------------- ### Create and Push New Feature Branch Source: https://github.com/haxeflixel/flixel/wiki/Contribution-Guide Creates a new local branch from the 'flixel:dev' branch and sets it up to track the corresponding branch on your remote fork. This is the recommended way to work on new features. ```git git checkout -B new-branch git push --set-upstream geo new-branch ``` -------------------------------- ### FlxTween Replacement Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog singleVar() and multiVar() have been replaced by the more performant tween() function. Removed SfxFader and Fader. ```haxe FlxTween.num() ``` ```haxe tween() ``` -------------------------------- ### FlxSpriteUtil bound() Method Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Introduced the bound() method in FlxSpriteUtil for sprite boundary manipulation. ```haxe FlxSpriteUtil.bound() ``` -------------------------------- ### FlxText with Multi-Format Ranges and Borders Source: https://context7.com/haxeflixel/flixel/llms.txt Applies different text styles to specific ranges within a FlxText object and adds a border or shadow effect. Requires setting the default format first, then adding specific range formats. ```haxe import flixel.text.FlxText; import flixel.util.FlxColor; // Multi-format ranges var richText = new FlxText(50, 200, 400, ""); richText.text = "WARNING: low health!"; richText.setFormat(null, 20, FlxColor.WHITE); // default style richText.addFormat(new FlxTextFormat(FlxColor.RED), 0, 7); // "WARNING" in red // Drop shadow / border richText.setBorderStyle(FlxTextBorderStyle.SHADOW, FlxColor.BLACK, 2, 1); add(richText); ``` -------------------------------- ### Master Volume and Muting Source: https://context7.com/haxeflixel/flixel/llms.txt Control the global master volume and mute all sounds using FlxG.sound.volume and FlxG.sound.muted. ```haxe // Volume / mute FlxG.sound.volume = 0.5; // master volume 0-1 FlxG.sound.muted = true; ``` -------------------------------- ### Screen Shake with FlxTween Source: https://context7.com/haxeflixel/flixel/llms.txt Implement a screen shake effect using FlxTween.shake, specifying the intensity and duration. Can be applied along specific axes. ```haxe // Screen-shake via tween FlxTween.shake(sprite, 0.05, 0.4, FlxAxes.X); ``` -------------------------------- ### FlxMath for Angle and Range Checks Source: https://context7.com/haxeflixel/flixel/llms.txt Demonstrates using FlxMath to wrap angles into a specific range (-180 to 180 degrees) and check if a value falls within a specified range. Also includes rounding to decimal places. ```haxe import flixel.math.FlxMath; import flixel.math.FlxPoint; // Wrap an angle into -180..180 var angle = FlxMath.wrapAngle(390); // returns 30 // Round to a given number of decimal places var rounded = FlxMath.roundDecimal(3.14159, 2); // 3.14 // Integer in range check if (FlxMath.inBounds(score, 0, 999)) trace("valid score"); ``` -------------------------------- ### Configure Physics and Collision with FlxObject Source: https://context7.com/haxeflixel/flixel/llms.txt Extend FlxObject (or FlxSprite) to define physics properties like mass, elasticity, drag, and max velocity. Configure collision behavior using allowCollisions flags. ```haxe import flixel.FlxObject; import flixel.FlxSprite; class Crate extends FlxSprite { public function new(x:Float, y:Float) { super(x, y); makeGraphic(32, 32, 0xFFa0522d); // Physics mass = 2.0; elasticity = 0.3; // 30% bounce drag.set(400, 0); maxVelocity.set(500, 800); // Collision — only collide from top and sides, not from below allowCollisions = FlxObject.UP | FlxObject.LEFT | FlxObject.RIGHT; } } // In your state's update(): // FlxG.collide(player, crateGroup); // resolves overlaps and applies momentum // FlxG.overlap(player, coinGroup, onCoinCollected); // detect-only, no separation ``` -------------------------------- ### Migrating FlxMouseEventManager Calls Source: https://github.com/haxeflixel/flixel/wiki/Flixel-5.0.0-Migration-guide Shows the change from static calls to FlxMouseEventManager to instance calls via FlxMouseEvent. Replace static calls like `FlxMouseEventManager.add(...)` with `FlxMouseEvent.add(...)`. ```haxe FlxMouseEvent.add(...); ``` -------------------------------- ### FlxDestroyUtil Safe Destruction Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Replaced FlxG.safeDestroy() with FlxDestroyUtil.destroy() for safer object destruction. ```haxe FlxDestroyUtil.destroy() ``` -------------------------------- ### FlxSound Time Variable Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog The FlxSound class now has a read-only 'time' variable. ```haxe FlxG.sound.soundTrayEnabled ``` -------------------------------- ### Test Function with GitHub Issue Reference Source: https://github.com/haxeflixel/flixel/blob/dev/tests/unit/README.md Use this pattern for test functions that address specific GitHub issues. The issue number is included as a comment. ```haxe @Test // #1203 function testColorWithAlphaComparison() ``` -------------------------------- ### FlxText with Word Wrap and Alignment Source: https://context7.com/haxeflixel/flixel/llms.txt Configures a FlxText object with a fixed width to enable word wrapping and text alignment. Useful for displaying longer descriptions or messages within a constrained area. ```haxe import flixel.text.FlxText; import flixel.util.FlxColor; // Fixed-width with word wrap var description = new FlxText(50, 100, 300, "Some long text that wraps.", 16); description.wordWrap = true; description.alignment = CENTER; add(description); ``` -------------------------------- ### Define a Player Sprite with FlxSprite Source: https://context7.com/haxeflixel/flixel/llms.txt Extend FlxSprite for visual game objects. Load graphics from assets, set visual properties, and configure physics. Use makeGraphic for solid colors. ```haxe import flixel.FlxSprite; import flixel.util.FlxColor; class Player extends FlxSprite { public function new(x:Float, y:Float) { super(x, y); // Load a sprite sheet: each frame is 48x48 pixels loadGraphic("assets/images/player.png", true, 48, 48); // Visual properties color = FlxColor.WHITE; alpha = 1.0; flipX = false; scale.set(1.5, 1.5); // 1.5× size (call updateHitbox() if collision needs updating) updateHitbox(); // Physics drag.set(800, 0); maxVelocity.set(300, 1000); // Solid-color alternative (no image file needed) // makeGraphic(32, 48, FlxColor.BLUE); } } // Programmatic pixel manipulation var s = new FlxSprite(); s.makeGraphic(64, 64, FlxColor.TRANSPARENT, true); // unique=true to allow pixel edits s.pixels.fillRect(new openfl.geom.Rectangle(8, 8, 48, 48), FlxColor.CYAN); ``` -------------------------------- ### FlxPath: Enemy Patrol Pathfinding Source: https://context7.com/haxeflixel/flixel/llms.txt Moves a sprite along a generated path through a tilemap. Requires a tilemap and start/end points to generate nodes. The path can be configured to loop. ```haxe import flixel.path.FlxPath; import flixel.math.FlxPoint; import flixel.tile.FlxTilemap; class PatrolEnemy extends FlxSprite { var path:FlxPath; public function new(tilemap:FlxTilemap, x:Float, y:Float) { super(x, y); makeGraphic(24, 24, 0xFFcc0000); // Build a path through the tilemap var start = new FlxPoint(x, y); var end = new FlxPoint(300, y); var nodes = tilemap.findPath(start, end); if (nodes != null) { path = new FlxPath(); path.start(this, nodes, 80, FlxPathType.LOOP_FORWARD); } } override public function update(elapsed:Float):Void { super.update(elapsed); // Flip sprite based on direction flipX = velocity.x < 0; } } ``` -------------------------------- ### Add Fork as Remote Source: https://github.com/haxeflixel/flixel/wiki/Contribution-Guide Adds your personal fork of the flixel repository as a new remote to your local clone. This is useful for managing contributions. ```git git remote add geo https://github.com/geokureli/flixel.git ``` -------------------------------- ### Pooling FlxPoint Usage Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Use FlxPoint.get() to obtain a pooled point and point.put() to recycle it. For passing points to Flixel functions, use FlxPoint.weak() to ensure automatic recycling. ```haxe var point = FlxPoint.get(); /* do stuff with point */ point.put(); // recycle point ``` ```haxe FlxPoint.weak() ``` -------------------------------- ### Control Sprite Animations with FlxAnimationController Source: https://context7.com/haxeflixel/flixel/llms.txt Manage sprite animations, including adding animations by frame indices or prefixes, setting playback speed and looping, and handling animation finish/loop signals. Animations are played back based on game logic. ```haxe import flixel.FlxSprite; class Hero extends FlxSprite { public function new() { super(); loadGraphic("assets/images/hero_sheet.png", true, 64, 64); // Add animations by frame indices (0-based) animation.add("idle", [0, 1, 2, 3], 8, true); animation.add("run", [4, 5, 6, 7, 8, 9], 12, true); animation.add("jump", [10, 11, 12], 10, false); animation.add("death", [13, 14, 15, 16], 8, false); // Atlas-based: add by frame name prefix // animation.addByPrefix("attack", "attack_", 24, false); // Signals (preferred over deprecated callbacks) animation.onFinish.add(function(name) { if (name == "death") kill(); }); animation.onLoop.add(function(name) { trace('$name looped'); }); animation.play("idle"); } override public function update(elapsed:Float):Void { super.update(elapsed); if (velocity.x != 0) animation.play("run"); else animation.play("idle"); // Pause / resume if (FlxG.keys.justPressed.P) animation.paused = !animation.paused; // Manual frame index // animation.frameIndex = 3; } } ``` -------------------------------- ### FlxObject Pixel Perfect Rendering Source: https://github.com/haxeflixel/flixel/wiki/Pre-4.0.0-Changelog Replaced forceComplexRender with pixelPerfectRender, which defaults to rounding coordinates for drawing, ensuring consistency across targets. ```haxe pixelPerfectRender ```