Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | tileset |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
31a1d7564ec65419fd62b1e515f9f613 |
User & Date: | athaudia 2017-07-25 02:36:56.523 |
Context
2017-07-25
| ||
16:34 | automatic scaling check-in: b9f5dfb290 user: athaudia tags: trunk | |
02:36 | tileset check-in: 31a1d7564e user: athaudia tags: trunk | |
01:52 | context and loader and timing check-in: edca182ac3 user: athaudia tags: trunk | |
Changes
Changes to lib/src/context.dart.
1 2 3 4 5 6 7 8 9 10 11 12 13 | import 'dart:html'; class Context { CanvasRenderingContext2D _ctx; Context(this._ctx); void draw(ImageElement img, int x, int y) { _ctx.drawImage(img, x, y); } void rect(int x, int y, int w, int h) { _ctx.fillRect(x, y, w, h); } } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import 'dart:html'; class Tileset { ImageElement _img; int _tileW, _tileH, _spacing; Tileset(this._img, this._tileW, this._tileH, this._spacing); int tileCountX() { return ((_img.width+_spacing) / (_tileW+_spacing)).floor(); } } class Context { CanvasRenderingContext2D _ctx; Context(this._ctx); void draw(ImageElement img, int x, int y) { _ctx.drawImage(img, x, y); } void rect(int x, int y, int w, int h) { _ctx.fillRect(x, y, w, h); } void drawTile(Tileset tileset, int tile, int x, int y) { int tcx = tileset.tileCountX(); int tx = tile & tcx; int ty = (tile / tcx).floor(); int posx = tx*(tileset._tileW+tileset._spacing); int posy = ty*(tileset._tileH+tileset._spacing); Rectangle src = new Rectangle(posx, posy, tileset._tileW, tileset._tileH); Rectangle dst = new Rectangle(x, y, tileset._tileW, tileset._tileH); _ctx.drawImageToRect(tileset._img, dst, sourceRect: src); } } class Loader { int loaded = 0; ImageElement image(String url) { var img = new ImageElement(src: url); loaded -= 1; img.onLoad.listen((e) => loaded += 1); return img; } Tileset tileset(String url, int tileWidth, int tileHeight, {int spacing = 0}) { return new Tileset(image(url), tileWidth, tileHeight, spacing); } } |
Changes to lib/src/loader.dart.
1 2 | import 'dart:html'; | < < < < < < < < < | 1 2 | import 'dart:html'; |
Changes to web/index.html.
1 2 3 4 | <!DOCTYPE html> <html> <head> </head> | | | 1 2 3 4 5 6 7 8 | <!DOCTYPE html> <html> <head> </head> <body style="margin:0"> <script type="text/javascript" src="main.dart.js"></script> </body> </html> |
Changes to web/main.dart.
1 2 3 4 5 6 | import 'dart:html'; import 'package:playtypus/playtypus.dart'; class MyGame extends Game { ImageElement img; int tick = 0; | > | > | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import 'dart:html'; import 'package:playtypus/playtypus.dart'; class MyGame extends Game { ImageElement img; Tileset tileset; int tick = 0; MyGame() : super(1920, 1080) {} void onPreload(Loader load) { img = load.image("tileset.png"); tileset = load.tileset("tileset.png", 16, 16, spacing: 1); } void onLoad() {} void onRender(Context ctx) { ctx.rect(0,0,tick,600); //ctx.draw(img, 0, 0); int tile = (tick / 1).floor(); for(int x = 0; x < 1920/16; ++x) for(int y = 0; y < 1080/16; ++y) ctx.drawTile(tileset, tile+x+y, x*16, y*16); } void onTick() { tick += 1; } } |
︙ | ︙ |