在Cocos2d-X3.2(Lua)中,如何检测点是否位于矩形中?
这里是事件句柄函数,在Cocos2d-X3.2(Lua)中,如何检测点是否位于矩形中?,lua,cocos2d-x,Lua,Cocos2d X,这里是事件句柄函数,self是一个cc.Node,self.bg是一个cc.Sprite local function onTouchEnded(touch, event) local location = touch:getLocation() local size = self.bg:getContentSize() local rect = cc.rect(self:getPositionX(),self:getPositionY(),si
self
是一个cc.Node
,self.bg
是一个cc.Sprite
local function onTouchEnded(touch, event)
local location = touch:getLocation()
local size = self.bg:getContentSize()
local rect = cc.rect(self:getPositionX(),self:getPositionY(),size.width,size.height)
end
如何比较location
和rect
以检查此精灵是否已单击,我已阅读此文档,
似乎cc.rect
没有containsPoint
功能,是否有其他方法处理此问题?如果location.x>rect.x和location.xif location.x > rect.x and location.x < rect.x + rect.width and
location.y > rect.y and location.y < rect.y + rect.height then
-- location is in rect, do your stuff
end
location.y>rect.y和location.y