Difference between revisions of "Sprite:hitTestPoint"
From GiderosMobile
m |
|||
(15 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
+ | '''Class:''' [[Sprite]]<br/> | ||
+ | |||
=== Description === | === Description === | ||
− | + | Checks whether the given coordinates (in global coordinate system) is in bounds of the sprite. | |
− | Checks whether the given coordinates (in global coordinate system) is in bounds of the sprite. | + | <syntaxhighlight lang="lua"> |
− | + | (bool) = Sprite:hitTestPoint(x,y,onlyvisible,ref) | |
− | < | + | </syntaxhighlight> |
− | + | ||
− | (bool) = Sprite:hitTestPoint(x,y, | ||
− | </ | ||
=== Parameters === | === Parameters === | ||
− | '''x''': (number) | + | '''x''': (number) the x coordinate to test<br/> |
− | '''y''': (number) | + | '''y''': (number) the y coordinate to test<br/> |
− | ''' | + | '''onlyvisible''': (bool) hit test only for visible sprite (clipping/masking) '''optional, default = false'''<br/> |
+ | '''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 === | ||
− | '''Returns''' (bool) | + | '''Returns''' (bool) ''true'' if the given global coordinates are in bounds of the sprite, ''false'' otherwise<br/> |
+ | |||
+ | === Example === | ||
+ | '''Moves a pixel with the mouse''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | 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) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | {{Sprite}} |
Latest revision as of 05:28, 23 April 2024
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,onlyvisible,ref)
Parameters
x: (number) the x coordinate to test
y: (number) the y coordinate to test
onlyvisible: (bool) hit test only for visible 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