Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ;
- import ncw.Bitmap;
- import ncw.Lib;
- import ncw.Screen;
- class Main {
- var scr:Screen;
- var img0:Bitmap;
- var img1:Bitmap;
- var pos:Float = 0;
- var spd:Float = 3;
- function onFrame() {
- // bouncing motion:
- pos += spd;
- if (pos > 200) { pos = 200; spd *= -1; }
- if (pos < -100) { pos = -100; spd *= -1; }
- // drawing:
- scr.bitmap.clear();
- // drawTo(image, x, y, rectX, rectY, rectWidth, rectHeight)
- scr.bitmap.drawTo(img0, 0 - pos, 0, 0, 0, 100, 480);
- scr.bitmap.drawTo(img1, 0 - pos, 0, 100, 0, 100, 480);
- scr.bitmap.drawTo(img0, 0 - pos, 0, 200, 0, 100, 480);
- scr.bitmap.drawTo(img1, 0 - pos, 0, 300, 0, 100, 480);
- // next frame:
- Lib.setTimeout(onFrame, 30);
- }
- function new() {
- scr = new Screen(new Bitmap(500, 438));
- scr.enable();
- var left = 2, onLoad = function(_) {
- if (--left == 0) onFrame();
- };
- img0 = Bitmap.load("img/0.png", onLoad);
- img1 = Bitmap.load("img/1.png", onLoad);
- }
- // entry point
- public static function main() { new Main(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement