Hello,
just wanted to know if anyone has a hack to control width of sprite (or similar element). First I encountered the problem, where I needed to set bigger width, than it's actually is, and it was easy, I used 1px wide transparent Shape element (I call spacer) to position in the bottom right corner, to make is as wide as I needed.
Problem is that now I need to make it smaller than it's actually is. Here's the scenario. I have elements at random positions from -1000 to 1000 px on x and y axis, tweening to their destination position. So as you've guessed the container of all these elements can be up to 2000 px wide (withal the width varies).
So if I want to for example center my container on the screen (and target elements there), problem is that through out the tweening, width changes and in the end container is not centered.
Position of container needs to be set before tweening.
And as it is a component I'm creating for general use (like button class), I would like to try make it without any restrictions of when and how to set position etc.
Right now my only option is to check absolute maximal boundary and use spacer element to make sure center of my container does not move, meaning it's right in the middle of the container all the time. But that seems like an ugly solution for now. As width of this container would be returned as large value. Which is bad for generic component. Maybe someone has better idea?
TLDR; Do you know a way to set width of sprite, although other elements (children of sprite) go beyond that width
Comments
So here goes my monologue again. It does not matter how wide or tall your Sprite is, because you don't see it anyway, but what matters it the value you return.
So if you want to make your element 200 px wide, simply override getWidth function to return 200px. Doh.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
local s1 = Sprite.new()
s1.getWidth = function() return 100 end
local s2 = Sprite.new()
s2:addChild(s1)
p(s1:getWidth()) -- 100
p(s2:getWidth()) -- 0
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!