hi. i’m trying to do a function to scale an object to the left in a defined area.
i use the formula: -area*.5+object.contentWidth*.5 to reposition my object to the left.
the problem is when i move my object and i change the scale same time, this formula don’t work 100% sometimes he moves a pixel to the worng position. i think is a problem is that scale in not integer and pixels are integers. maybe internal they are doing the wrong position. i tried math.round, ceil, floor. even i made a round function to let only 2 decimals, still with no luck.
heres a sample code that i made to prove my point:
local width=130 local height=300 local toque=display.newRect(0,0,width,height) toque.alpha=0.3 toque.isVisible=true -- this box is to be hidden in the future toque.isHitTestable=true local object=display.newRect(0,0,width,20) local grupo=display.newGroup() grupo:insert(toque) grupo:insert(object) grupo.x=centerX grupo.y=centerY local function touch(self, event) if event.phase == "began" then display.getCurrentStage():setFocus( self ) self.isFocus = true y = (event.y - event.yStart) elseif self.isFocus then if event.phase == "moved" then y = (event.y - event.yStart) diferenca=y-posAntigo object.y=object.y+diferenca object.xScale=object.xScale+diferenca\*0.01 object.yScale=object.yScale+diferenca\*0.01 object.x=-width\*.5+object.contentWidth\*.5 -- this formula should be correct? elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus(nil ) self.isFocus = false end end posAntigo=y return true end toque.touch = touch toque:addEventListener( "touch", toque )
you can try this code and you will understand what i’m talking about.
if i use transitions this problem with scale dont show up.
i don’t know if its a bug of xScale and yScale or i’m doing anything wrong.
any help is appreciated.
best regards,
Carlos.