y positions changeing

Hi All,

I am very newbie on corona. (almost 2 hours :slight_smile:

I have a pipe and a ball.

I want when move my ball than my pipe’s height change but my pipe’s y positions doesnt chenge. But pipe growing to double way.

My Source is below. please help me.

local physics = require("physics") physics.start() display.setStatusBar( display.HiddenStatusBar ) local background = display.newImage( "jungle\_bkg.png" ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 background.width = display.contentWidth background.height = display.actualContentHeight local pipe pipe= display.newImage("board.png") pipe.x =display.contentWidth / 2 pipe.y =1 local ball ball = display.newImage( "coconut.png" ) ball.x =display.contentWidth / 2 ball.y =35 physics.addBody( ball,"static" , { density=0.6, friction=0.6, bounce=0.6, radius=19 } ) local MoveBaby = function( event ) ball.x=event.x ball.y=event.y pipe.height=ball.y pipe.y = 1 return true end ball:addEventListener( "touch", MoveBaby )

I think this is a reference-point issue.  The default is at the center of the image or object.  From what I can see (using newRect instead of the images), it looks like the “pipe” is moving only half the distance it needs to … because half of your increase in height is showing up at the top (off screen).

(alternately, in line 37, set “pipe.height = 2 * ball.y” and it seems to work for me)

If you change objects size or content then corona resets all reference points and even alter some positions sometimes. Example can be width, height or text content of text object. The best practice is to shift reference point and position object again after changing such properties.

jbp1 and piotrz55

thanks for replies. But my issues doesnt resolve  :frowning:

Pipe growing from center. I want pipe should grove from top reference point. How can i do?

Please explain me with code 

And it will be. You must take it as granted that objects grows from center if you change .width or .height. So as I mentioned, you change pipe size -> it grows from center -> you set new reference point -> you place pipe accordingly.

[lua]
local rect = display.newRect(0, 0, 50, 50)
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 200
rect.y = 200

rect.width = 100 --reference point reseted to center
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 200
rect.y = 200
[/lua]

Thank you piotr.

it has been solved.

Thank you very much again.

I think this is a reference-point issue.  The default is at the center of the image or object.  From what I can see (using newRect instead of the images), it looks like the “pipe” is moving only half the distance it needs to … because half of your increase in height is showing up at the top (off screen).

(alternately, in line 37, set “pipe.height = 2 * ball.y” and it seems to work for me)

If you change objects size or content then corona resets all reference points and even alter some positions sometimes. Example can be width, height or text content of text object. The best practice is to shift reference point and position object again after changing such properties.

jbp1 and piotrz55

thanks for replies. But my issues doesnt resolve  :frowning:

Pipe growing from center. I want pipe should grove from top reference point. How can i do?

Please explain me with code 

And it will be. You must take it as granted that objects grows from center if you change .width or .height. So as I mentioned, you change pipe size -> it grows from center -> you set new reference point -> you place pipe accordingly.

[lua]
local rect = display.newRect(0, 0, 50, 50)
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 200
rect.y = 200

rect.width = 100 --reference point reseted to center
rect:setReferencePoint(display.TopLeftReferencePoint)
rect.x = 200
rect.y = 200
[/lua]

Thank you piotr.

it has been solved.

Thank you very much again.