SetReferencePoit Bug

Hi

This is a real show stopper for me. Consider the following… I have to Rects, same size, same position on the screen. Now, what I want to simulate is that one of the rects is a bucket and the other rect is water inside the bucket. Moving the “bucket” to the left side (in the onTouch event) causes the bucket to tip over and the water-rect should reduce in “height”. To achieve this, I have set the SetReferencePoint to BottomLeft, so when the bucket tips over, the rect sits on the bottom left side (tipping to the left). No problems so far… But, when the height of the other rect (the water) is reduced, it seems like the height is calculated from the center of the rect (assuming it its reference point is Center?). So the “water” rect moves gradually to the center when the height is reduced (1px every frame)

I have now idea how to get around this. I have tried with transitions and so on but no luck

Sample code

-- Simulate bucket  
bucket = display.newRect(screenWidth \*0.5, 700, 100, 100)  
bucket:setReferencePoint(display.BottomLeftReferencePoint)  
bucket.x = screenWidth \*0.5  
bucket.y = 700  
bucket:setFillColor(0, 255, 0, 100)  
bucket:addEventListener( "touch", onTouch )  
  
--Simualate water  
water = display.newRect(screenWidth \*0.5, 700, 100, 100)  
water:setReferencePoint(display.BottomLeftReferencePoint)  
water:setFillColor(0, 0, 255)  
water.x = screenWidth \*0.5  
water.y = 700  

local function main( event ) if(math.abs(bucket.rotation) == 45) then if(water.height \> 2) then local newHeight = water.height-1 water.height = newHeight --NOT CALCULATED FROM REFERENCE POINT ?? end end end Runtime:addEventListener( "enterFrame", main ) [import]uid: 36300 topic_id: 7132 reply_id: 307132[/import]

Hmm, the only way i can think to do it is reduce the water by 2 at a time and add 1 to its .y. This will reduce 1 pix from the top and one from the bottom, but then u move one pix down so it appears both pixs came from the top.
local newHeight = water.height-2
water.height = newHeight
water.y = water.y + 1 [import]uid: 8872 topic_id: 7132 reply_id: 25128[/import]

Thanks for the reply kam187.

I have tried this. But consider a rotation of -45 degrees (bucket tips over 45 degrees to the left). The two rects aligns correctly when both have the same height. But when reducing the water, the water gradually moves out of the bucket rect since the origin of the rotation is wrongly calculated from the center. So when the water rect is for example half the height of the bucket rect the water rect is outside the bucket rect, which of course is the case since the rotation of the water rect is now further down comparing to the bucket rect.

The only way to make this work is by my thought if both rects has a reference point of bottom left.

  • Magnus [import]uid: 36300 topic_id: 7132 reply_id: 25178[/import]

hmm since any change to attributes is instant you can rotate back, reindex x/y from the bucket coordinates, then rotate again? I know its still a corona bug but it might get your app releasable for now?

with some experimentation u could calculates it mathematically to optimise the physical movements.

I’ve had to do the same thing with many other things in corona for android especially.

[import]uid: 8872 topic_id: 7132 reply_id: 25231[/import]