lufy's legend

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 7608|回复: 5

缩放后,事件位置不对

[复制链接]

9

主题

0

好友

117

积分

士兵

Rank: 1

发表于 2017-2-15 14:51:34 |显示全部楼层
大神我有个背景,
背景里面嵌套了一个按钮,
绑定了一个单击事件

如果我缩放这个背景, 这个按钮点击位置就不对,请问有什么好的办法吗

回复

使用道具 举报

37

主题

8

好友

9305

积分

诸侯王

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

发表于 2017-2-15 14:57:57 |显示全部楼层
不会吧,代码发一下我看看
不回答与技术和引擎不相关的问题
回复

使用道具 举报

9

主题

0

好友

117

积分

士兵

Rank: 1

发表于 2017-2-15 15:52:07 |显示全部楼层
new InteractivePNG()
如果这个按钮是new InteractivePNG()创建的才会,如果是new LSprite()就不会
回复

使用道具 举报

9

主题

0

好友

117

积分

士兵

Rank: 1

发表于 2017-2-15 15:56:21 |显示全部楼层
这个按钮是不规则的,我不想通过缝隙点到背景,应该还是用new InteractivePNG(),但又不想缩放后,事件位置错位
我需要怎么处理,请教大神
回复

使用道具 举报

37

主题

8

好友

9305

积分

诸侯王

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

发表于 2017-2-15 21:50:59 |显示全部楼层
donnier 发表于 2017-2-15 15:56
这个按钮是不规则的,我不想通过缝隙点到背景,应该还是用new InteractivePNG(),但又不想缩放后,事件位置 ...

这个没办法,InteractivePNG所使用的方法目前不支持缩放
如果不是动态变化的对象的话,你可以先把图形缩放后draw到一个LBitmapData对象上,然后再放到InteractivePNG中
不回答与技术和引擎不相关的问题
回复

使用道具 举报

4

主题

0

好友

52

积分

士兵

Rank: 1

发表于 2018-8-20 14:03:07 |显示全部楼层
            InteractivePNG.prototype.hitTestPoint = function (x, y) {
                var self = this;
                var point = self.getRootCoordinate();
                point.x = x - point.x;
                point.y = y - point.y;
                for (var i = 0, l = self.childList.length; i < l; i++) {
                    var child = self.childList[0];
                    if (!child.bitmapData._locked) {
                        child.bitmapData.lock();
                    }
                    var cx = point.x - child.x;
                    var cy = point.y - child.y;
                    if (cx < 0 || cx > child.bitmapData.width * child.scaleX || cy < 0 || cy > child.bitmapData.height * child.scaleY) {
                        continue;
                    }
                    var pixel = child.bitmapData.getPixel(Math.round(cx / child.scaleX), Math.round(cy / child.scaleY));
                    if (pixel && pixel[3] > 0) {
                        return true;
                    }
                }
                return false;
            };

我也发现这个问题,自己改了一下这里,初步是可以用的了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

防止垃圾广告,请填写任意字符

Archiver|lufy's legend

GMT+8, 2024-3-29 17:58 , Processed in 0.051677 second(s), 25 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部