Displaying a bitmap fixed + nme library still is alive but nme is not died

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!

Download file

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!

1 Like

Wow, blast from the past :slight_smile:

I don’t know if “DisplayingABitmap” should have resize code, although it makes the sample nicer, I believe that it makes it look more complicated to get started. The real goal is to provide cut-and-paste code for adding bitmap images to projects :wink:

I should go through and turn our samples into quick tutorials

I vote no. DisplayingABitmap should be as simple as possible.

Maybe handling resize events could be a separate sample.

@player_03, why do you not vote that? So sad if beginners don’t know if they are new to resizing of stage’s event.

Example:
How does bitmap stay center if you resize window?
Answer they need to get tutorial.

I agree with @singmajesty because he’s right and it is simple tutorial for beginners.

@player_03:
Please do not hide tutorials and explanations for newbies / beginners!
I want show for newbies and beginners.

PS: Sorry I argue with @player_03 because he should vote “yes” because it is simple to explain for newbies and beginners

Thanks!

But as I said, the tutorial doesn’t have to be DisplayingABitmap. It could be a new sample.

1 Like