Base2D.hx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. class Base2D extends hxd.App {
  2. var obj : h2d.Object;
  3. var tf : h2d.Text;
  4. override function init() {
  5. // creates a new object and put it at the center of the sceen
  6. obj = new h2d.Object(s2d);
  7. obj.x = Std.int(s2d.width / 2);
  8. obj.y = Std.int(s2d.height / 2);
  9. // load the haxe logo png into a tile
  10. var tile = hxd.Res.hxlogo.toTile();
  11. // change its pivot so it is centered
  12. tile = tile.center();
  13. for( i in 0...15 ) {
  14. // creates a bitmap into the object
  15. var bmp = new h2d.Bitmap(tile, obj);
  16. // move its position
  17. bmp.x = Math.cos(i * Math.PI / 8) * 100;
  18. bmp.y = Math.sin(i * Math.PI / 8) * 100;
  19. // makes it transparent by 10%
  20. bmp.alpha = 0.1;
  21. // makes the colors adds to the background
  22. bmp.blendMode = Add;
  23. }
  24. // load a bitmap font Resource
  25. var font = hxd.Res.customFont.toFont();
  26. // creates another text field with this font
  27. var tf = new h2d.Text(font, s2d);
  28. tf.textColor = 0xFFFFFF;
  29. tf.dropShadow = { dx : 0.5, dy : 0.5, color : 0xFF0000, alpha : 0.8 };
  30. tf.text = "Héllò h2d !";
  31. tf.y = 20;
  32. tf.x = 20;
  33. tf.scale(7);
  34. }
  35. // if we the window has been resized
  36. override function onResize() {
  37. if( obj == null ) return;
  38. // center our object
  39. obj.x = Std.int(s2d.width / 2);
  40. obj.y = Std.int(s2d.height / 2);
  41. // move our text up/down accordingly
  42. if( tf != null ) tf.y = s2d.height - 80;
  43. }
  44. override function update(dt:Float) {
  45. // rotate our object every frame
  46. if( obj != null ) obj.rotation += 0.6 * dt;
  47. }
  48. static function main() {
  49. hxd.Res.initEmbed();
  50. new Base2D();
  51. }
  52. }