我可以画框,但我不能删除它! (帆布) [英] I am able to draw the box but I am not able to remove it! (Canvas)

查看:146
本文介绍了我可以画框,但我不能删除它! (帆布)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前问过这个问题,似乎我使用的代码很混乱。所以这是一个虚拟转储版本的相同的代码。
我使用add函数在画布上绘制一个正方形。像明智的,我应该能够使用remove函数从画布中删除项目!

I have asked this question before and it seemed that the code I was using was pretty confusing. So this is a virtually dumed down version of the same code. I draw a square on the canvas using the add function. Like wise I should be able to remove the item from the canvas using the remove function! Alas it doesn't seem to happen so.

以下是代码

$(window).addEvent('load',function(){


CANVAS.init({ canvasElement : 'canvas' });
CANVAS.layers.add( new Layer({
    id : 'myLayer'
}));

var colors = [
    'rgba(255,0,0,1)',
    ];

var pos = [
    { x: 150, y : 100 },
]

       var foo = new CanvasItem({
        id : 'item',
        x : pos[0].x,
        y : pos[0].y,
        fillStyle : colors[0],
        events : {
            onDraw : function(ctx)
            {
                ctx.fillStyle = this.fillStyle;
                ctx.fillRect(this.x,this.y,200,200);
            }
        }
    });

CANVAS.layers.get('myLayer').add(foo);
CANVAS.draw();
CANVAS.layers.get('myLayer').remove(foo);
CANVAS.draw();
    });

也可以看到 jsfiddle

我使用的库是通过mootools canvas库实现的。 这是功能的链接。

The library I am using to implement this is via mootools canvas library. Here is the link of the functions.

希望这将帮助人们得到我的查询。如果你仍在思考我的问题究竟是什么,随时问问题!感谢

Hopefully this will help people get my query. Feel free to ask questions if you are still pondering about what exactly is my problem! Thanks

编辑:库中有一个错误。请在答案的意见中找到下面纠正的代码的链接。感谢。

EDIT : There is a bug in the library. Please find the link to the corrected code below in the comments of the answer. Thanks.

推荐答案

库中的错误是在remove函数中。我有以下脚本,删除该错误。希望它帮助人。 :)

the error in the library was in the remove function. I have the following script which removes the bug. Hope it helps people. :)

http://gist.github.com/ 589185

这篇关于我可以画框,但我不能删除它! (帆布)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆