Sprite:setAnchorPoint: Difference between revisions

From GiderosMobile
Created page with "__NOTOC__ '''Available since:''' Gideros 2016.10<br/> '''Class:''' Sprite<br/> === Description === Sets x, y, z anchor position of '''Sprite''' in its relative coordinate..."
 
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
=== Description ===
=== Description ===
Sets x, y, z anchor position of '''Sprite''' in its relative coordinates.
Sets x, y, z anchor position of '''Sprite''' in its relative coordinates.
<source lang="lua">
<syntaxhighlight lang="lua">
Sprite:setAnchorPoint(anchorX,anchorY,anchorZ)
Sprite:setAnchorPoint(anchorX,anchorY,anchorZ)
</source>
</syntaxhighlight>


=== Parameters ===
=== Parameters ===
Line 13: Line 13:
'''anchorY''': (number) anchor position in Sprite internal coordinates<br/>
'''anchorY''': (number) anchor position in Sprite internal coordinates<br/>
'''anchorZ''': (number) anchor position in Sprite internal coordinates '''optional'''<br/>
'''anchorZ''': (number) anchor position in Sprite internal coordinates '''optional'''<br/>
=== Example ===
<syntaxhighlight lang="lua">
application:setBackgroundColor(0xaa5500)
-- the visuals
local trash = Bitmap.new(Texture.new("gfx/Trash_can_0006.png"))
local bus_stop_signal = Bitmap.new(Texture.new("gfx/bus_stop_signal_0007.png"))
local pub = Bitmap.new(Texture.new("gfx/pub_0008.png"))
-- anchors
trash:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
bus_stop_signal:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
pub:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
-- position
local posy = 270
trash:setPosition(40, posy)
bus_stop_signal:setPosition(60, posy)
pub:setPosition(200, posy)
-- order
stage:addChild(trash)
stage:addChild(bus_stop_signal)
stage:addChild(pub)
</syntaxhighlight>
=== Note ===
'''setAnchorPoint''' is also available in the Bitmap class: [[Bitmap:setAnchorPoint]]


{{Sprite}}
{{Sprite}}

Latest revision as of 15:20, 11 May 2025

Available since: Gideros 2016.10
Class: Sprite

Description

Sets x, y, z anchor position of Sprite in its relative coordinates.

Sprite:setAnchorPoint(anchorX,anchorY,anchorZ)

Parameters

anchorX: (number) anchor position in Sprite internal coordinates
anchorY: (number) anchor position in Sprite internal coordinates
anchorZ: (number) anchor position in Sprite internal coordinates optional

Example

application:setBackgroundColor(0xaa5500)
-- the visuals
local trash = Bitmap.new(Texture.new("gfx/Trash_can_0006.png"))
local bus_stop_signal = Bitmap.new(Texture.new("gfx/bus_stop_signal_0007.png"))
local pub = Bitmap.new(Texture.new("gfx/pub_0008.png"))
-- anchors
trash:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
bus_stop_signal:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
pub:setAnchorPoint(0.5, 1) -- anchor middle & bottom of sprite
-- position
local posy = 270
trash:setPosition(40, posy)
bus_stop_signal:setPosition(60, posy)
pub:setPosition(200, posy)
-- order
stage:addChild(trash)
stage:addChild(bus_stop_signal)
stage:addChild(pub)

Note

setAnchorPoint is also available in the Bitmap class: Bitmap:setAnchorPoint