mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Tilorswift json loader implemented.
This commit is contained in:
33
tilorswift/js/Field.js
Normal file
33
tilorswift/js/Field.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export default class Field
|
||||
{
|
||||
className = 'field';
|
||||
|
||||
constructor(tileset, index = 0)
|
||||
{
|
||||
this.tileset = tileset;
|
||||
this.index = index;
|
||||
this.htmlElement = document.createElement('td');
|
||||
this.init();
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
this.htmlElement.classList.add(this.className);
|
||||
this.htmlElement.style.width = String(this.tileset.getTileWidth()) + 'px';
|
||||
this.htmlElement.style.height = String(this.tileset.getTileHeight()) + 'px';
|
||||
this.htmlElement.style.backgroundSize = 'auto ' + this.tileset.getTileHeight() + 'px';
|
||||
this.htmlElement.style.backgroundImage = 'url("' + this.tileset.image.src + '")';
|
||||
this.htmlElement.style.backgroundPositionX = -this.index * this.tileset.getTileWidth() + 'px';
|
||||
}
|
||||
|
||||
setIndex(index)
|
||||
{
|
||||
this.index = index;
|
||||
this.htmlElement.style.backgroundPositionX = -this.index * this.tileset.getTileWidth() + 'px';
|
||||
}
|
||||
|
||||
getElement()
|
||||
{
|
||||
return this.htmlElement;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user