Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var map = new Tileset("tileset.png");
- function Tileset(url) {
- this.image = new Image();
- this.image.referenceDuTileset = this;
- this.image.onload = function() {
- this.referenceDuTileset.largeur = this.width / 32;
- }
- this.image.src = url;
- Tileset.prototype.dessinerTile = function(numero, context, xDestination, yDestination) {
- var xSourceEnTiles = numero % this.largeur;
- if (xSourceEnTiles == 0) {
- xSourceEnTiles = this.largeur;
- }
- var ySourceEnTiles = Math.ceil(numero / this.largeur);
- var xSource = (xSourceEnTiles - 1) * 32;
- var ySource = (ySourceEnTiles - 1) * 32;
- context.drawImage(this.image, xSource, ySource, 32, 32, xDestination, yDestination, 32, 32);
- }
- }
- window.onload = function() {
- var canvas = document.getElementById('canvas');
- var ctx = canvas.getContext('2d');
- map.dessinerTile(2, ctx, 32 * c + 160 * ml, 32 * l + 128 * mc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement