Merge pull request #40 from lctrt/feat/draw-callback

add callback to draw
This commit is contained in:
Лu Лinveгa 2019-07-14 15:36:15 +12:00 committed by GitHub
commit 595110f781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,13 +94,16 @@ function Surface (ronin) {
}
}
this.draw = function (path, rect = this.getFrame()) {
this.draw = function (path, rect = this.getFrame(), callback = () => {}) {
const img = new Image()
img.src = path
img.onload = () => {
const ratio = img.width / img.height
const scale = rect.w / img.width
this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * scale)
if (typeof callback === 'function') {
callback()
}
}
}