Skip to content

Instantly share code, notes, and snippets.

@larsiusprime
Created April 24, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsiusprime/3c165ab72408999b5516 to your computer and use it in GitHub Desktop.
Save larsiusprime/3c165ab72408999b5516 to your computer and use it in GitHub Desktop.
Reproduction case for Flixel BitmapData glitch with stamp()
package;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.Lib;
import flixel.FlxGame;
import flixel.FlxState;
class Main extends Sprite
{
var gameWidth:Int = 320; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
var gameHeight:Int = 240; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = MenuState; // The FlxState the game starts with.
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
var framerate:Int = 60; // How many frames per second the game should run at.
var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
// You can pretty much ignore everything from here on - your code should go in your states.
public static function main():Void
{
Lib.current.addChild(new Main());
}
public function new()
{
super();
if (stage != null)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function init(?E:Event):Void
{
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}
setupGame();
}
private function setupGame():Void
{
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;
if (zoom == -1)
{
var ratioX:Float = stageWidth / gameWidth;
var ratioY:Float = stageHeight / gameHeight;
zoom = Math.min(ratioX, ratioY);
gameWidth = Math.ceil(stageWidth / zoom);
gameHeight = Math.ceil(stageHeight / zoom);
}
addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
}
}
package;
import flixel.addons.ui.FlxUIButton;
import flixel.addons.ui.FlxUICheckBox;
import flixel.addons.ui.FlxUICursor;
import flixel.addons.ui.FlxUIState;
import flixel.addons.ui.FlxUIText;
import flixel.addons.ui.interfaces.IFlxUIWidget;
import flixel.FlxSprite;
import flixel.util.FlxColor;
import openfl.Assets;
import openfl.geom.Rectangle;
/**
* A FlxState which can be used for the game's menu.
*/
class MenuState extends FlxUIState
{
/**
* Function that is called up when to state is created to set it up.
*/
override public function create():Void
{
super.create();
var test = new FlxSprite();
test.makeGraphic(256, 100, FlxColor.RED);
test.graphic.bitmap.fillRect(new Rectangle(0, 50, 256, 50), FlxColor.BLUE);
var fs:FlxSprite = new FlxSprite(0, 0, "assets/openfl.png");
test.stamp(fs);
add(test);
}
}
<?xml version="1.0" encoding="utf-8"?>
<project>
<!------------------------------APPLICATION SETTINGS---------------------------->
<app title="Cursor" file="Cursor" main="Main" version="0.0.1" company="HaxeFlixel" />
<!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html file
<!--or you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"!-->
<app preloader="flixel.system.FlxPreloader" />
<!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2 -->
<set name="SWF_VERSION" value="11.8" />
<!--------------------------------WINDOW SETTINGS------------------------------->
<!--These window settings apply to all targets-->
<window width="640" height="480" fps="60" background="#000000" hardware="true" vsync="true" />
<!--Web-specific-->
<window if="web" orientation="portrait" />
<!--Desktop-specific-->
<window if="desktop" orientation="landscape" fullscreen="false" resizable="true" />
<!--Mobile-specific-->
<window if="mobile" orientation="landscape" fullscreen="true" width="0" height="0" />
<!--------------------------------PATHS SETTINGS-------------------------------->
<set name="BUILD_DIR" value="export" />
<classpath name="source" />
<assets path="assets" />
<!--------------------------------LIBRARIES------------------------------------->
<haxelib name="flixel"/>
<!--In case you want to use the addons package-->
<!--haxelib name="flixel-addons" /-->
<!--In case you want to use the ui package-->
<haxelib name="flixel-ui"/>
<!--In case you want to use nape with flixel-->
<!--haxelib name="nape" /-->
<!--------------------------------HAXEDEFINES----------------------------------->
<!--Enable the Flixel core recording system-->
<!--haxedef name="FLX_RECORD" /-->
<!--Disable the right and middle mouse buttons-->
<!--haxedef name="FLX_NO_MOUSE_ADVANCED" /-->
<!--Disable the Native cursor api for Flash target-->
<!--haxedef name="FLX_NO_NATIVE_CURSOR" /-->
<!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
<haxedef name="FLX_NO_MOUSE" if="mobile" />
<haxedef name="FLX_NO_KEYBOARD" if="mobile" />
<haxedef name="FLX_NO_TOUCH" if="desktop" />
<!--haxedef name="FLX_NO_GAMEPAD" /-->
<!--Disable the Flixel core sound tray-->
<!--haxedef name="FLX_NO_SOUND_TRAY" /-->
<!--Disable the Flixel sound management code-->
<!--haxedef name="FLX_NO_SOUND_SYSTEM" /-->
<!--Disable the Flixel core focus lost screen-->
<!--haxedef name="FLX_NO_FOCUS_LOST_SCREEN" /-->
<!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
<haxedef name="FLX_NO_DEBUG" unless="debug" />
<!--Enable this for Nape release builds for a serious peformance improvement-->
<haxedef name="NAPE_RELEASE_BUILD" unless="debug" />
<!--------------------------------CUSTOM---------------------------------------->
<!--Place custom nodes like icons here (higher priority to override the HaxeFlixel icon)-->
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment