在 createjs 中,我尝试向舞台添加元素,但仅在由函数调用时才添加。
如果我将此代码添加到 onload init() 函数中,则代码将起作用:
function init()
{
background = new createjs.Shape();
background.graphics.beginLinearGradientFill(["blue", "darkgreen"], [0, 1], 0, 0, 100, 100).drawRect(0, 0, 70, 70);
background.x = 0;
background.y = 0;
stage.addChild(background);
}
但是如果我添加它就像
function init()
{
loadScreen();
}
function loadScreen()
{
background = new createjs.Shape();
background.graphics.beginLinearGradientFill(["blue", "darkgreen"], [0, 1], 0, 0, 100, 100).drawRect(0, 0, 70, 70);
background.x = 0;
background.y = 0;
stage.addChild(background);
}
我可能只是在做一些愚蠢的事情,任何提示表示赞赏。
谢谢
最佳答案
去掉loadScreen()函数定义后的分号(;)
function init()
{
loadScreen();
}
function loadScreen()
{
background = new createjs.Shape();
background.graphics.beginLinearGradientFill(["blue", "darkgreen"], [0, 1], 0, 0, 100, 100).drawRect(0, 0, 70, 70);
background.x = 0;
background.y = 0;
stage.addChild(background);
}
关于javascript - 创建JS函数添加到舞台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926874/