设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3086|回复: 11
打印 上一主题 下一主题

[有事请教] 如何判断旋转了的Sprite被点击

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
1
发表于 2018-4-15 13:20:49 | 显示全部楼层

Sprite.prototype.worldToLocalXY  = function ( x,y,sprite) {
    var node = sprite || this;  
    return node.worldTransform.applyInverse({x:x,y:y},{visible:node.worldVisible});
};



/**
* 是触摸自己
* @param {number} x x坐标
* @param {number} y y坐标
* @param {boolean} type 是否不检查位图(true 为不检查 )
* @param {bolean}c 是否检查子图(true 为 检查 )
*
*
*/
Sprite.prototype.isTouchThis = function (x, y, type, c) {
    if (this.visible) {
        var loc = this.worldToLocalXY(x,y)
        var x = loc.x
        var y = loc.y
        var v = loc.visible
      
        if(v){
            if (c) {
                for (var i = 0; i < this.children.length; i++) {
                    var s = this.children[i]
                    if (s && s.isTouchThis && s.isTouchThis(x, y, type,c)) {
                        return true
                    }
                }
            }

            if (this.isTouchIn && this.isTouchIn(x, y, type)) {
                return true
            }
        }
    }
    return false
}



/**是在之中
* @param {boolean} type 不检查图片
*
*/
Sprite.prototype.isTouchIn = function (x, y, type) {
    if (this.anchor) {
        var x = x + this.anchor.x * this.width
        var y = y + this.anchor.y * this.height
    }
    if (this.isTouchInFrame(x, y, type)) {
        return type || this.isTouchInBitamp(x, y)
    } else {
        return false
    }
}


/**是在区域中 */
Sprite.prototype.isTouchInFrame = function (x, y, type) {
    return x >= 0 && y >= 0 && x < this.width && y < this.height;
};


/**是在位图上不透明点 */
Sprite.prototype.isTouchInBitamp = function (x, y) {
    if (this._realFrame) {
        var x = x + this._realFrame.x
        var y = y + this._realFrame.y
    }
    if (this.bitmap && this.bitmap.getAlphaPixel(x, y)) {
        return true
    }
    return false
}

点评

哎……这个..解决不了旋转以后的问题啊  发表于 2018-4-15 16:53
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-22 18:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表