view.entity-module.SpriteBasedEntity.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of module-entities Show documentation
Show all versions of module-entities Show documentation
Entity Manager module for the CodinGame engine toolkit. Simplify the management of shapes and drawings.
import { TextureBasedEntity } from './TextureBasedEntity.js'
import { ErrorLog } from '../core/ErrorLog.js'
import { MissingImageError } from './errors/MissingImageError.js'
/* global PIXI */
export class SpriteBasedEntity extends TextureBasedEntity {
constructor () {
super()
Object.assign(this.defaultState, {
image: null,
baseWidth: null,
baseHeight: null,
scaleMode: 'LINEAR'
})
this.missingTextures = {}
}
updateDisplay (state, changed, globalData) {
super.updateDisplay(state, changed, globalData)
if (changed.image) {
try {
if (state.image !== null) {
this.graphics.texture = PIXI.Texture.from(state.image)
} else {
this.graphics.texture = PIXI.Texture.EMPTY
}
this.graphics.texture.baseTexture.scaleMode = PIXI.SCALE_MODES[state.scaleMode]
} catch (error) {
if (!this.missingTextures[state.image]) {
this.missingTextures[state.image] = true
ErrorLog.push(new MissingImageError(state.image, error))
}
}
}
if (changed.baseWidth) {
this.graphics.width = state.baseWidth
}
if (changed.baseHeight) {
this.graphics.height = state.baseHeight
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy