我使用CreateJS将图形(形状)和位图添加到舞台上,并将其添加到我的HTML5画布。CreateJS缓存对象 - 对象现在不在舞台上动画
在屏幕上移动圆形图形(20px大小)后,稍微有一段时间后出现严重滞后。
我跟着这篇文章,以找出性能问题: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);
}
为什么?
我不认为你的问题来自这个简单的圈子。我们需要更多的代码来帮助你。 –