EaselJS改变颜色onMouseOver [英] EaselJS Change Color onMouseOver

查看:316
本文介绍了EaselJS改变颜色onMouseOver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在HTML canvas元素中实施所有鼠标和向量相关信息后切换到EaselJS。



我已经习惯了EaselJS,它真的很整洁。我特别喜欢容器和它们如何简单地绘制嵌入的形状。但是,我无法弄清楚您是如何实施 shape 的颜色更改的, a>在鼠标上。



我应该从容器中删除形状,并使用新颜色创建一个新的形状?

干杯



编辑:这里是我使用的向量的一个例子绘制我的圆

  var circle = new Shape(); 
circle.graphics.beginStroke(rgba(255,0,0,0.75))
.setStrokeStyle(lw)
.drawCircle(w / 2,h / 2,r)
.endStroke()
.beginFill(rgba(255,255,0,0.5))
.drawCircle(w / 2,h / 2,r-lw / 2)
.endFill();
circle.shadow = new Shadow(rgba(0,0,0,0.5),10,-10,10)

有一个简单的方法来传递一个新的颜色beginFill?我可以使用变量吗? circle.graphics ... 只执行一次,或每次调用 stage.update()

解决方案

您要将Shape.graphics.beginFill更改为鼠标悬停时不同的颜色。



以下是示例(警告:斜线代码!)


I switched over to EaselJS after having muleheadedly implemented all mouse and vector related information in the HTML canvas element.

I have gotten used to EaselJS and it is really neat. I especially like the containers and how simple they make drawing embedded shapes. However, I can't figure out how you, for example, implement a color change of a shape on a mouse over. Anything as simple as a rectangle changing color from red to green.

Am I supposed to remove the shape from its container and create a new shape with the new color?

To complicate matters, if one shape partially occludes another, lets say a square inside a circle, then onMouseOver will not register for the circle when over the square. Is there any way around this.

Cheers

EDIT: here is an example of the vector I use to draw my circle

    var circle=new Shape();
    circle.graphics.beginStroke("rgba(255,0,0,0.75)")
            .setStrokeStyle(lw)
            .drawCircle(w/2,h/2,r)
            .endStroke()
            .beginFill("rgba(255,255,0,0.5)")
            .drawCircle(w/2,h/2,r-lw/2)
            .endFill();
    circle.shadow=new Shadow("rgba(0,0,0,0.5)",10,-10,10)

Is there an easy way to pass a new color to beginFill? Can I use variable there? Does the circle.graphics... get executed only once, or every time there is a call to stage.update()?

解决方案

You want to change the Shape.graphics.beginFill to a different color on the mouseover.

Here's an example (warning: sloppy code!)

这篇关于EaselJS改变颜色onMouseOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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