我正在使用createjs 0.8.0并且在获取位图大小时遇到问题。 它总是返回0
这是我的片段:
var imgVisa = new createjs.Bitmap("assets/images/Visa_logo.png");
console.log("imgVisa x : " + imgVisa.image.width);
var imgVisaX = initialXpos;
var imgVisaY = canvas.height - 300;
它将具有 imgVisa.image.width = 0 。
如果我正在使用:
imgSplash.Bitmap.width
它会抛出我的错误: Uncaught TypeError:无法读取属性' width'未定义的
任何人都可以提供帮助吗?
答案 0 :(得分:3)
您应该首先尝试预加载图像:
var img = new Image()
img.onload = function() {
// gets called when the img is loaded
};
img.src = 'img.png';
请记住,加载图像时会调用onload函数,因此它是异步的。
答案 1 :(得分:1)
您可以使用Bitmap.getBounds()。width