Difference between revisions of "Sprite:hitTestPoint"
From GiderosMobile
Line 13: | Line 13: | ||
'''y''': (number) the y coordinate to test<br/> | '''y''': (number) the y coordinate to test<br/> | ||
'''visible''': (bool) test for hidden sprite (clipping/masking) '''optional, default = false'''<br/> | '''visible''': (bool) test for hidden sprite (clipping/masking) '''optional, default = false'''<br/> | ||
− | '''ref''': (Sprite) specifies which sprite is the reference of x,y coordinates | + | '''ref''': (Sprite) specifies which sprite is the reference of x,y coordinates. If nil global coordinates are assumed '''optional, default = nil''', '''new Gideros 2023.2'''<br/> |
=== Return values === | === Return values === |
Revision as of 11:17, 21 February 2023
Available since: Gideros 2011.6
Class: Sprite
Description
Checks whether the given coordinates (in global coordinate system) is in bounds of the sprite.
(bool) = Sprite:hitTestPoint(x,y,visible,ref)
Parameters
x: (number) the x coordinate to test
y: (number) the y coordinate to test
visible: (bool) test for hidden sprite (clipping/masking) optional, default = false
ref: (Sprite) specifies which sprite is the reference of x,y coordinates. If nil global coordinates are assumed optional, default = nil, new Gideros 2023.2
Return values
Returns (bool) true if the given global coordinates are in bounds of the sprite, false otherwise
Example
Moves a pixel with the mouse
local pixel = Pixel.new(0xff0000, 1, 32, 32)
local x0, y0, focus
pixel:addEventListener(Event.MOUSE_DOWN, function(e)
if pixel:hitTestPoint(e.x, e.y) then
focus = true
x0, y0 = e.x, e.y
e:stopPropagation()
end
end)
pixel:addEventListener(Event.MOUSE_MOVE, function(e)
if focus then
local dx = e.x - x0
local dy = e.y - y0
pixel:setX(self.camera:getX() + dx)
pixel:setY(self.camera:getY() + dy)
x0 = e.x
y0 = e.y
e:stopPropagation()
end
end)
pixel:addEventListener(Event.MOUSE_UP, function(e)
if focus then
focus = false
e:stopPropagation()
end
end)
- Sprite:addChild
- Sprite:addChildAt
- Sprite:clearBlendMode
- Sprite:clone
- Sprite:contains
- Sprite:get
- Sprite:getAlpha
- Sprite:getAnchorPoint
- Sprite:getAnchorPosition
- Sprite:getBounds
- Sprite:getChildAt
- Sprite:getChildIndex
- Sprite:getChildrenAtPoint
- Sprite:getClip
- Sprite:getColorTransform
- Sprite:getDrawCount
- Sprite:getHeight
- Sprite:getLayoutConstraints
- Sprite:getLayoutInfo
- Sprite:getLayoutParameters
- Sprite:getMatrix
- Sprite:getNumChildren
- Sprite:getParent
- Sprite:getPosition
- Sprite:getRotation
- Sprite:getRotationX
- Sprite:getRotationY
- Sprite:getScale
- Sprite:getScaleX
- Sprite:getScaleY
- Sprite:getScaleZ
- Sprite:getSize
- Sprite:getSkew
- Sprite:getSkewX
- Sprite:getSkewY
- Sprite:getWidth
- Sprite:getX
- Sprite:getY
- Sprite:getZ
- Sprite:globalToLocal
- Sprite:hitTestPoint
- Sprite:isVisible
- Sprite:localToGlobal
- Sprite:redrawEffects
- Sprite:removeChild
- Sprite:removeChildAt
- Sprite:removeFromParent
- Sprite:set
- Sprite:setAlpha
- Sprite:setAnchorPoint
- Sprite:setAnchorPosition
- Sprite:setBlendMode
- Sprite:setClip
- Sprite:setColorTransform
- Sprite:setEffectConstant
- Sprite:setEffectStack
- Sprite:setGhosts
- Sprite:setLayoutConstraints
- Sprite:setLayoutParameters
- Sprite:setMatrix
- Sprite:setPosition
- Sprite:setRotation
- Sprite:setRotationX
- Sprite:setRotationY
- Sprite:setScale
- Sprite:setScaleX
- Sprite:setScaleY
- Sprite:setScaleZ
- Sprite:setShader
- Sprite:setShaderConstant
- Sprite:setSkew
- Sprite:setSkewX
- Sprite:setSkewY
- Sprite:setStencilOperation
- Sprite:setStopEventPropagation
- Sprite:setVisible
- Sprite:setX
- Sprite:setY
- Sprite:setZ
- Sprite:spriteToLocal
- Sprite:swapChildren
- Sprite:swapChildrenAt
- Sprite.ADD
- Sprite.ALPHA
- Sprite.EFFECT MODE AUTOMATIC
- Sprite.EFFECT MODE CONTINUOUS
- Sprite.EFFECT MODE TRIGGERED
- Sprite.LAYOUT ANCHOR CENTER
- Sprite.LAYOUT ANCHOR EAST
- Sprite.LAYOUT ANCHOR NORTH
- Sprite.LAYOUT ANCHOR NORTHEAST
- Sprite.LAYOUT ANCHOR NORTHWEST
- Sprite.LAYOUT ANCHOR SOUTH
- Sprite.LAYOUT ANCHOR SOUTHEAST
- Sprite.LAYOUT ANCHOR SOUTHWEST
- Sprite.LAYOUT ANCHOR WEST
- Sprite.LAYOUT FILL BOTH
- Sprite.LAYOUT FILL HORIZONTAL
- Sprite.LAYOUT FILL NONE
- Sprite.LAYOUT FILL VERTICAL
- Sprite.MULTIPLY
- Sprite.NO ALPHA
- Sprite.SCREEN
- Sprite.new
- Event.ADDED_TO_STAGE
- Event.ENTER_FRAME
- Event.KEY_CHAR
- Event.KEY_DOWN
- Event.KEY_UP
- Event.LAYOUT_RESIZED
- Event.MOUSE_DOWN
- Event.MOUSE_ENTER
- Event.MOUSE_HOVER
- Event.MOUSE_LEAVE
- Event.MOUSE_MOVE
- Event.MOUSE_UP
- Event.MOUSE_WHEEL
- Event.REMOVED_FROM_STAGE
- Event.TOUCHES_BEGIN
- Event.TOUCHES_CANCEL
- Event.TOUCHES_END
- Event.TOUCHES_MOVE