我正在使用CreateJS将图形(形状)和位图添加到我的舞台上,并将其添加到我的HTML5画布中。在将大小为20px的圆形图形在屏幕上移动一段时间后,会出现严重的延迟问题。
我按照这篇文章来确定性能问题:http://blog.toggl.com/2013/05/6-performance-tips-for-html-canvas-and-createjs/ 因此,我尝试进行缓存... 现在当我按键时,圆圈不会移动。我是否缓存不正确?
我按照这篇文章来确定性能问题:http://blog.toggl.com/2013/05/6-performance-tips-for-html-canvas-and-createjs/ 因此,我尝试进行缓存... 现在当我按键时,圆圈不会移动。我是否缓存不正确?
world = new createjs.Container();
segment = new createjs.Shape();
segment.graphics.beginFill("red").drawCircle(0, 0, 20);
segment.x = 100;
segment.y = 100;
segment2 = new createjs.Shape();
segment2.graphics.beginFill("black").drawCircle(0, 0, 20);
segment2.x = 150;
segment2.y = 150;
ContainerOfPeople = new createjs.Container();
ContainerOfPeople.addChild(segment, segment2);
world.addChild(ContainerOfPeople); //add container of people to world container (which will contain all objects in a container)
world.cache(0, 0, 1000, 1000); //cache all objects within world container
stage.addChild(world);
编辑:
如果我在创建地图后不缓存瓦片,我可以看到它们渲染到画布上:
function createWorld() {
background = new createjs.Container();
for (var y = 0; y < mapWidth; y++) {
for (var x = 0; x < mapHeight; x++) {
var tile = new createjs.Bitmap('images/tile.png');
tile.x = x * 28;
tile.y = y * 30;
background.addChild(tile);
}
}
//background.cache(0, 0, mapWidth, mapHeight);
stage.addChild(background);
}
如果我缓存了瓷砖子元素的背景容器,它将不会被渲染。
function createWorld() {
background = new createjs.Container();
for (var y = 0; y < mapWidth; y++) {
for (var x = 0; x < mapHeight; x++) {
var tile = new createjs.Bitmap('images/tile.png');
tile.x = x * 28;
tile.y = y * 30;
background.addChild(tile);
}
}
background.cache(0, 0, mapWidth, mapHeight);
stage.addChild(background);
}
Why?