- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 CreateJS 将图形(形状)和位图添加到我的舞台,并将其添加到我的 HTML5 Canvas 。
在屏幕上移动圆圈图形(大小为 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);
编辑:
如果我在创建 map 后不缓存这些图 block ,我可以看到它们呈现在 Canvas 上:
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);
}
如果我确实缓存了 tile children 的背景容器,它不会呈现
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);
}
为什么?
最佳答案
如果您正在为它的子对象设置动画/移动它,您不会想要缓存整个世界。将缓存视为拍摄 DisplayObject 及其所有子项的快照。缓存项目时,您不会看到对子项所做的任何更改,直到您按照 EaselJS 文档中的说明再次更新缓存:
http://www.createjs.com/Docs/EaselJS/classes/DisplayObject.html#method_cache
cache ( x y width height [scale=1] )
Defined in cache:735
Draws the display object into a new canvas, which is then used for subsequent draws. For complex content that does not change frequently (ex. a Container with many children that do not move, or a complex vector Shape), this can provide for much faster rendering because the content does not need to be re-rendered each tick. The cached display object can be moved, rotated, faded, etc freely, however if its content changes, you must manually update the cache by calling updateCache() or cache() again. You must specify the cache area via the x, y, w, and h parameters. This defines the rectangle that will be rendered and cached using this display object's coordinates.
为了进一步说明,假设您有一个游戏 Angular 色 Container
由 6 个 child 形状、2 条 ARM 、2 条腿、一个 body 和一个头组成。在游戏过程中, Angular 色的 ARM 和腿会四处摆动。在这种情况下,您不想缓存 Angular 色,因为每次移动 ARM 和腿时都将被迫更新缓存,从而消除了缓存带来的任何性能提升。
但是,假设一旦 Angular 色死亡,他就会卡住在一个死的位置,并且 alpha 会从屏幕上消失。在这种情况下,您将缓存该字符。这是因为 alpha 动画变得越来越 CPU 密集,它必须考虑更多的形状。通过缓存 Angular 色,您实际上是在告诉 CPU 只补间一个形状而不是 6 个。然后您可以 uncache
一旦您的 alpha tween 完成并且您想要返回第 2 轮的播放器。
更新
easeljs首次引用时异步加载图像。因为您没有预加载图像,所以在缓存背景时图像数据还没有加载到内存中。
这是一个 fiddle ,其中图像作为 base64 编码字符串嵌入,因此可立即缓存以证明缓存按预期工作。我的建议是使用 preloadjs库在将图像添加到舞台之前先加载图像。
关于javascript - CreateJS 缓存对象 - 对象现在不会在舞台上设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21732795/
如何在 createjs 中显示自定义光标?我在 Canvas 上渲染了多个图像/位图。我希望每当我单击特定位图时光标更改为特定图像。也就是说,单击图片 1 时,光标将变为画笔图像,单击图片 2 时,
我在 CreateJS/TweenJS 中有多个 Tweens: createjs.Tween.get(elem1).to({..}); createjs.Tween.get(elem2).to({.
我在 creatJS 方面遇到问题,希望您能提供帮助。 var stage = new createjs.Stage(canvas); 我收到此错误: angular.js:13642 Refere
我的项目是从服务器加载的。我使用 preloadjs 加载图像,然后使用它创建位图。加载图像后,可以使用以下命令创建位图新的createjs.Bitmap(路径);如果使用 firfox,但在使用 C
我正在制作一个射击游戏,其中我需要通过将子弹绑定(bind)到“tick”事件来更新子弹的状态,但是当调用删除方法将它们从“tick”事件中删除时,它不会将其删除。创建新实例后,它会不断更新,而不是绑
我试图将这个 h1 插入到 canvas 中。但它没有显示。无论如何,将 w3school html 集成到 Canvas 中,而无需使用 easeljs 程序创建文本。我将其添加到 Canvas 内
如何在createjs中仅在对象的右侧和底部绘制阴影。物体上或顶部和左侧没有阴影。 阴影仅包含 4 个参数 1.阴影的颜色 2. x 3. 年 4.模糊效果 但它没有说明 4 个不同的方面。 var
在 CreateJs 中,Firefox 呈现的文本对象的顶部位置与其他浏览器略有不同,而形状对象没有显示这种差异。 例如, this.text = new cjs.Text("Click to St
希望有人能帮忙。 我在 CreateJS 中有一个游戏工作正常,添加了暂停按钮的功能,也工作正常,除了暂停按钮不可见,但我的所有其他对象都是:(如果我单击我知道暂停按钮所在的位置该功能有效,但我只是看
我正在尝试使用 createjs 版本 8 中的新继承模型。我想让 Tile 继承自 createjs.Shape这是最基本的代码。 //This is the Tile constructor fu
这个问题已经有答案了: easeljs not showing bitmap (1 个回答) 已关闭 6 年前。 我怀疑答案就在 PreloadJs 中但是,我已经在我的 code 中删除了对它的修改
我正在使用这个 fiddle 中的代码: https://codepen.io/rauluranga/pen/KwoBdE 我想使用此代码使我的oes.container 中的每个对象都具有随机移动。
我正在开发一个 createjs 游戏,其中图像保存在容器内。我想将图像补间到屏幕上的某个位置并将图像切换到另一个图像。几秒钟后,我想从 Canvas /屏幕中删除新图像。 目前,我正在将 (evt)
我尝试将自己的方法添加到 Tween 类中以暂停/恢复所有补间。这就是我所拥有的: createjs.Tween.pauseAllTweens = function() { for ( var
这是图形: http://snag.gy/aVFGA.jpg 大矩形是 Canvas 元素,小矩形是 Canvas 中的图像对象。我想找到离左边的实际距离是多少。 值是我在控制台中看到的值: regX
我不知道我的代码有什么问题。我对 javascript 很陌生。有时 createjs 会工作,有时则不会。这没有意义,因为我正在从其他人的教程中复制精确的代码。
所以, 我刚开始学习 CreateJS,我遇到了我的第一个问题:我无法让补间工作(我希望它应该工作)。 示例如下:http://www.hakoniemi.net/labs/createjs-test
我想更改父容器内 2 个子容器的坐标。最初,我循环遍历父容器的子容器并单独更改它们的 x,y...但随后更改父容器的 x,y 更有意义>... 问题是...我需要获取每个子项的单独更改坐标...但是更
我尝试通过 SoundJS 声音注册加载声音,并收到以下错误: createjs.js:15 Uncaught Error: Type not recognized. 我认为 soundjs 库在定位
所以我尝试使用 Createjs 对矩形大小进行动画处理。我发现有两种方法可以创建矩形。要么: var rectangle = new createjs.Rectangle(0,0,100,100);
我是一名优秀的程序员,十分优秀!