Hello everyone,
I have fixed DisplayingABitmap with eventlistener of stage’s resize
Before old code:
package;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.Sprite;
import openfl.Assets;
class Main extends Sprite {
public function new () {
super ();
var bitmap = new Bitmap (Assets.getBitmapData (“assets/openfl.png”));
addChild (bitmap);bitmap.x = (stage.stageWidth - bitmap.width) / 2; bitmap.y = (stage.stageHeight - bitmap.height) / 2;
}
}
After:
package;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.Sprite;
import openfl.display.StageAlign;
import openfl.display.StageScaleMode;
import openfl.Assets;
import openfl.Lib;
import openfl.events.Event;
class Main extends Sprite {
/**
- Fix: Add variable of bitmap
*/
private var bitmap:Bitmap;public function new () {
super (); /** * Fix: Add propreties of stage */ Lib.current.stage.align = StageAlign.TOP_LEFT; Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE; Lib.current.stage.frameRate = 60; bitmap = new Bitmap (Assets.getBitmapData ("assets/openfl.png")); addChild (bitmap); /** * Added: Add listener for resizing of stage */ Lib.current.stage.addEventListener(Event.RESIZE, onResize); onResize(null);
}
/**
- Add new function by stage eventlistener with resize.
/
private function onResize(evt:Event = null):Void
{
/*
- Move: old code will stay and move to function of listener with stage’s resize
*/
bitmap.x = (stage.stageWidth - bitmap.width) / 2;
bitmap.y = (stage.stageHeight - bitmap.height) / 2;
}
}
/**
- Improved by Jens Eckervogt ( aka SourceSkyBoxer )
- Added propreties of stage
- Moved old code to function of listener with stage’s resize
- Added new listener with stage’s eventlistener
- Bonus explanation:
Improvement with stage's resize
- Thanks for suggestions!
*/
If you want release my improved DisplayingABitmap into openfl samples
"openfl-samples" means messed up and has issues and bugs
"openfl-samples-fixed" means clean up and fresh codes without errors, issues, failures or critics!
Would you like we add new openfl-samples-fixed for openfl because it is very important to check for beginners - I don’t want beginners are mad and sensitive. That is why we want make clean library for openfl, lime and NME too because NME still is in the development! From nmehost.com.
You know box2D is buggy - I find Nape very better than boxs2D
I want we develop nme + openfl + lime.
PS: I found web.archivie.org - wow restored website of nme.io tutorials and community I have readden yesterday…
Thanks!