PlayState.hx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package;
  2. import flixel.FlxG;
  3. import flixel.FlxSprite;
  4. import flixel.FlxState;
  5. import flixel.util.FlxColor;
  6. import flixel.tweens.FlxTween;
  7. import flixel.tweens.FlxEase;
  8. import flixel.system.FlxAssets;
  9. import flixel.system.FlxSound;
  10. import textbox.Textbox;
  11. import textbox.Settings;
  12. class PlayState extends FlxState
  13. {
  14. var tbox:Textbox;
  15. var tbox2:Textbox;
  16. var cursor:FlxSprite;
  17. var cursorTween:FlxTween;
  18. var beep1:FlxSound;
  19. var beep2:FlxSound;
  20. override public function create():Void
  21. {
  22. cursor = new FlxSprite(0, 0);
  23. cursor.makeGraphic(8, 4);
  24. beep1 = new FlxSound();
  25. beep1.loadEmbedded(AssetPaths.beep1__ogg);
  26. beep2 = new FlxSound();
  27. beep2.loadEmbedded(AssetPaths.beep2__ogg);
  28. var settingsTbox:Settings =
  29. {
  30. font: FlxAssets.FONT_DEFAULT,
  31. fontSize: 16,
  32. textFieldWidth: 320,
  33. color: FlxColor.WHITE
  34. };
  35. tbox = new Textbox(200,30, settingsTbox);
  36. tbox.setText("Hello World!@011001500 How goes? @010@001FF0000Color test!@000 This is a good old textbox test.");
  37. tbox.characterDisplayCallback = function(t:textbox.Text):Void
  38. {
  39. cursor.x = t.x + t.width + 2;
  40. cursor.y = t.y + t.height - 4;
  41. cursor.color = t.color;
  42. beep1.play(true);
  43. };
  44. tbox.bring();
  45. var settingsTbox2:Settings =
  46. {
  47. font: FlxAssets.FONT_DEFAULT,
  48. fontSize: 10,
  49. textFieldWidth: 400,
  50. charactersPerSecond: 30,
  51. color: FlxColor.YELLOW
  52. };
  53. tbox2 = new Textbox(30,150, settingsTbox2);
  54. tbox2.setText("This is another textbox, to show how the settings variables can change the result. Speed, size or color and more with the effects! Note that there is a fully working text wrap! :D");
  55. tbox2.characterDisplayCallback = function(t:textbox.Text):Void
  56. {
  57. cursor.x = t.x + t.width + 2;
  58. cursor.y = t.y + t.height - 4;
  59. cursor.color = t.color;
  60. beep2.play(true);
  61. };
  62. tbox2.statusChangeCallback = function(s:textbox.Status):Void
  63. {
  64. if (s == textbox.Status.DONE)
  65. {
  66. cursorTween = FlxTween.color(cursor, 0.5, cursor.color, FlxColor.TRANSPARENT, {
  67. type: FlxTween.PINGPONG,
  68. ease: FlxEase.cubeInOut
  69. });
  70. }
  71. };
  72. add(cursor);
  73. tbox.statusChangeCallback = function (newStatus:textbox.Status):Void
  74. {
  75. if (newStatus == textbox.Status.FULL)
  76. {
  77. tbox.continueWriting();
  78. }
  79. else if(newStatus == textbox.Status.DONE)
  80. {
  81. add(tbox2);
  82. tbox2.bring();
  83. }
  84. };
  85. add(tbox);
  86. super.create();
  87. }
  88. override public function update(elapsed:Float):Void
  89. {
  90. super.update(elapsed);
  91. }
  92. }