yetneverdone wrote: ↑Thu Nov 17, 2022 2:46 pm
Can the x and y be optional when creating the sprite? Perhaps default it to 0 if nil is passed
Yes, but it leads to bugs in my experience.
If you want to make the position optional you can modify the "node.lua" file:
Code: Select all
function node.new(x, y, mt)
x, y = x or 0, y or 0
local t = { x = x, y = y, r = 0, sx = 1, sy = 1 }
yetneverdone wrote: ↑Thu Nov 17, 2022 2:46 pm
What's the difference between transforming the nodes vs using the rest of the parameters in :setGraphic (rotation, scale, offset, shear)?
setGraphic offsets the graphic relative to the position of the sprite.
This allows you to rotate your image around its center, rather than the top-left corner.
yetneverdone wrote: ↑Thu Nov 17, 2022 2:46 pm
Whats the recommend way of lets say drawing a scaled and rotated sprite to the center of the screen/view?
Sprites located at 0, 0 will be in the center of the screen/view.
Here is how to offset your image to the center of the sprite:
Code: Select all
local iw, ih = img:getDimensions()
local sprite = view:newSprite(0, 0)
sprite:setGraphic(img, -iw/2, -ih/2)
sprite:setRotation(math.pi/2)
I admit, this is not very elegant and similar scene graph libraries have better ways to center your graphic.
I considered adding something like sprite:setGraphic(drawable, "center") but some drawable objects like meshes do not have predefined dimensions.
Thank you for the questions!