Advertisement
YellowAfterlife

NCW Test

Oct 25th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.01 KB | None | 0 0
  1. package ;
  2. import ncw.Bitmap;
  3. import ncw.Lib;
  4. import ncw.Screen;
  5.  
  6. class Main {
  7.     var scr:Screen;
  8.     var img0:Bitmap;
  9.     var img1:Bitmap;
  10.     var pos:Float = 0;
  11.     var spd:Float = 3;
  12.     function onFrame() {
  13.         // bouncing motion:
  14.         pos += spd;
  15.         if (pos > 200) { pos = 200; spd *= -1; }
  16.         if (pos < -100) { pos = -100; spd *= -1; }
  17.         // drawing:
  18.         scr.bitmap.clear();
  19.         // drawTo(image, x, y, rectX, rectY, rectWidth, rectHeight)
  20.         scr.bitmap.drawTo(img0, 0 - pos, 0, 0, 0, 100, 480);
  21.         scr.bitmap.drawTo(img1, 0 - pos, 0, 100, 0, 100, 480);
  22.         scr.bitmap.drawTo(img0, 0 - pos, 0, 200, 0, 100, 480);
  23.         scr.bitmap.drawTo(img1, 0 - pos, 0, 300, 0, 100, 480);
  24.         // next frame:
  25.         Lib.setTimeout(onFrame, 30);
  26.     }
  27.     function new() {
  28.         scr = new Screen(new Bitmap(500, 438));
  29.         scr.enable();
  30.         var left = 2, onLoad = function(_) {
  31.             if (--left == 0) onFrame();
  32.         };
  33.         img0 = Bitmap.load("img/0.png", onLoad);
  34.         img1 = Bitmap.load("img/1.png", onLoad);
  35.     }
  36.     // entry point
  37.     public static function main() { new Main(); }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement