Sprite:spriteToLocalMatrix

From GiderosMobile

Available since: Gideros 2023.2
Class: Sprite

Description

Converts from one Sprite local matrix space to another. Returns a Matrix that transforms a coordinate in other Sprite space into a coordinate in current Sprite space.

Sprite:spriteToLocalMatrix(spr)

Parameters

spr: (Sprite) target sprite local matrix space

Example

local sprite = Sprite.new()
local pix = Pixel.new(0xff0000, 1, 32, 32)
pix2 = pix:clone()
pix3 = pix:clone()
pix2:setColor(0x00ff00)
pix3:setColor(0x0000ff)
-- rotation
pix:setRotation(45)
-- position
pix:setPosition(1*32, 1*32)
pix2:setPosition(1.5*32, 1.5*32)
pix3:setPosition(2*32, 2*32)
-- order
sprite:addChildrenAt ( { pix, pix2, pix3 } )
stage:addChild(sprite)

local matrix = pix2:spriteToLocalMatrix(pix)
pix2:setMatrix(matrix)