怎么用easeljs添加事件,改变颜色

Gannys 2017-06-12 05:51:38
用createjs在页面上画了很多circle,然后设置了一个mouseover事件,只要鼠标移动到某一个圆上,那这个圆就变成一个长方形。但是我每次指着一个圆,总是另一个圆变成了长方形,

function initCircles() {
circles = [];
for(var i=0; i<100; i++) {
var circle = new createjs.Shape();
var r = 7;
var x = window.innerWidth*Math.random();
var y = window.innerHeight*Math.random();
var color = colors[Math.floor(i%colors.length)];
var alpha = 0.2 + Math.random()*0.5;
circle.overcolor="red";
circle.alpha = alpha;
circle.radius = r;
circle.graphics.beginFill(color).drawCircle(0, 0, r);
circle.x = x;
circle.y = y;
circle.index = i;
circles.push(circle);
circle.movement = 'float';

circle.addEventListener("mouseover", function(event) {
circles[circle.index].graphics.clear().beginFill("#BD07D5").drawRect(0,0,50,60).endFill();
stage.update(event);
});

circle.addEventListener("mouseout", function(event) {
circles[circle.index].graphics.clear().beginFill("#BD07D5").drawCircle(0,0,r).endFill();
stage.update(event);
});
stage.addChild(circle);
}
}
...全文
281 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gannys 2017-06-12
  • 打赏
  • 举报
回复
就是这个图的样子
Gannys 2017-06-12
  • 打赏
  • 举报
回复

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧