Sprite:setAnchorPoint

From GiderosMobile
Revision as of 10:43, 22 August 2024 by MoKaLux (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)