Objects falling into the screen

Hi 

  I have looked about on how to do this but firstly I think this might not be easy to explain and this maybe why I have could not be using the “right” terminology for this.

  Does Corona have a way of having objects fall “into” the screen so that the object would look a normal size as it enters the screen but as it falls into the screen it becomes smaller as it is further away.

  I hope this makes sense in what I am asking and I cannot think of a way of explaining it any better. Sorry if this has been asked before , I do try and avoid duplicate questions but I could not think of a way of wording this better when I was searching for it

http://timcs.co.uk/uploads/forums/direction_of_fall.png

Thanks

TimCS

Hello, I think i got what you want.

I just put it together in like a min or two.

Heres the code … Just put it into a main.lua and its will work…

local box = {} local bCounter = 1 local timerOne function zoomOut() transition.to( box[bCounter], { time = 1000, x = box[bCounter].x + 50, xScale = 0, yScale = 0, alpha = 0, onComplete = removeBox }) end function removeBox(event) local removeHi = event.target display.remove(removeHi) end local function spawnBoxes() local xSpawn = math.random(display.contentWidth \* 0.13, display.contentWidth \* 0.87 ) local ySpawn = math.random(display.contentHeight \* 0.17, display.contentHeight \* 1.01) box[bCounter] = display.newRect( xSpawn, ySpawn, 20, 20 ) box[bCounter].value = bCounter zoomOut() bCounter = bCounter + 1 end timerOne = timer.performWithDelay( 800, spawnBoxes, -1 )

Good Luck!!

Hi yes I think you could do this try this code below that I made. Good Luck! Tyler Jacobson

©Tyler Jacobson 2015 local object= display.newRect( 0, 40, 150, 150) local function getsmaller(event) object.width = object.width-10 object.height = object.height-10 transition.to( object, { time=5000, x = 600,y = 40 } ) end timer.performWithDelay( 1000, getsmaller,-1 )

Thank you both for this , my image may have provide an example of what I was after but the dropping in effect may not go in at an angle like this it may actual actual look like it has fallen from outside of the screen like dropping something onto the screen and it falling into the screen directly. I will look at both of your examples and see what I can do

Thank you both again for this . I am determined to make a game and have always wanted to do just that. I am coming up with basic ideas but then having that battle of trying to then actually put them into practice when writing a game. I think Corona has been one of the better game engine platforms that I have come across (although I have not tried them all especially those that cost a lot :slight_smile: ) so I really want this to gaming engine to work for me

TimCS

Maybe this is more to your liking:

local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, width = 10, height = 10, transition = easing.outBounce })

Thanks for your code hasty, nice effect as well, when the object drops using this effect is there a way to set it towards another object ? so would using the x , y setting within the transition.to function be used to do this as I cannot seem to get it to fall onto the other object which is larger instead it goes off to one corner.

Thanks

TimCS 

Are you doing something like this:

local circ = display.newCircle( display.contentCenterX, display.contentCenterY + 100, 20 ) local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, x = circ.x, y = circ.y, width = 10, height = 10, transition = easing.outBounce })

If you are setting the x and y destination in the transition to another object like this, it should end up in the centre of that object.

Hi hasty that is exactly what I am doing but the box heads towards the top corner of the “circle” however I am setting the “circle” (which is really an image BTW) but I know now what I am doing wrong on my image in order to make it appear in the center of the screen, I am setting the X and Y anchors = 0 so I guess this is what the box is going towards the anchor positions ? 

If I take the anchor positions away the box goes to the center of the image but the image is then offset to the center 

Thanks

TimCS

Hello again! I see this topic is going pretty far so i thought i’d throw in something cool i put together!!

Try it out!

local circle = {} local aCounter = 1 local timerOne local circleMiddle = display.newCircle( display.contentCenterX, display.contentCenterY, 20 ) circleMiddle.alpha = 0.2 function zoomOut() circleTransOne = transition.to( circle[aCounter], { time = 1000, x = circleMiddle.x, y= circleMiddle.y, xScale = 0.001, yScale = 0.001, alpha = 0, onComplete = removeCircle }) end function removeCircle(event) local removeOne = event.target display.remove(removeOne) end local function spawnCirlces() local xSpawn = math.random(display.contentWidth \* 0, display.contentWidth \* 1 ) local ySpawn = math.random(display.contentHeight \* 0, display.contentHeight \* 1) circle[aCounter] = display.newCircle( xSpawn, ySpawn, 2 ) circle[aCounter].value = aCounter zoomOut() aCounter = aCounter + 1 end timerOne = timer.performWithDelay( 10, spawnCirlces, -1 )

Good Luck and Thanks!

EDIT - Fixed a small bug, should be perfect now!

Yes, the box will go towards the anchor points. To have it go to the centre, you just have to account for the difference.

local circ = display.newCircle( display.contentCenterX, display.contentCenterY, 50 ) circ.anchorX = 0, 0 circ.anchorY = 0, 0 local boxShadow = display.newRect( circ.x, circ.y, 150, 150 ) boxShadow:setFillColor(0, 0, 0, 0.5) local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, x = circ.x + circ.width\*0.5, y = circ.y + circ.height\*0.5, width = 10, height = 10, transition = easing.outBounce }) transition.to(boxShadow, {time = 2400, width = 10, height = 10, transition = easing.outBounce})

Thanks SonicX278 and hasty for your efforts here - I am going to look at both of these and then work on what I need to do , the object that is “static” where the other lands/falls onto, will eventually be one of many of the same probably in a row going across the screen (probably near the bottom of the screen) and then random objects (mainly an array of images) will fall towards these. So I guess I will need a table to hold the falling objects and a table to hold the “static” objects and then work on some kinda of loop that randomly drops the objects randomly towards those “static” objects and would “stick” to them , then more objects that fall could also land on these as well.

Thanks again

TimCS

Hello, I think i got what you want.

I just put it together in like a min or two.

Heres the code … Just put it into a main.lua and its will work…

local box = {} local bCounter = 1 local timerOne function zoomOut() transition.to( box[bCounter], { time = 1000, x = box[bCounter].x + 50, xScale = 0, yScale = 0, alpha = 0, onComplete = removeBox }) end function removeBox(event) local removeHi = event.target display.remove(removeHi) end local function spawnBoxes() local xSpawn = math.random(display.contentWidth \* 0.13, display.contentWidth \* 0.87 ) local ySpawn = math.random(display.contentHeight \* 0.17, display.contentHeight \* 1.01) box[bCounter] = display.newRect( xSpawn, ySpawn, 20, 20 ) box[bCounter].value = bCounter zoomOut() bCounter = bCounter + 1 end timerOne = timer.performWithDelay( 800, spawnBoxes, -1 )

Good Luck!!

Hi yes I think you could do this try this code below that I made. Good Luck! Tyler Jacobson

©Tyler Jacobson 2015 local object= display.newRect( 0, 40, 150, 150) local function getsmaller(event) object.width = object.width-10 object.height = object.height-10 transition.to( object, { time=5000, x = 600,y = 40 } ) end timer.performWithDelay( 1000, getsmaller,-1 )

Thank you both for this , my image may have provide an example of what I was after but the dropping in effect may not go in at an angle like this it may actual actual look like it has fallen from outside of the screen like dropping something onto the screen and it falling into the screen directly. I will look at both of your examples and see what I can do

Thank you both again for this . I am determined to make a game and have always wanted to do just that. I am coming up with basic ideas but then having that battle of trying to then actually put them into practice when writing a game. I think Corona has been one of the better game engine platforms that I have come across (although I have not tried them all especially those that cost a lot :slight_smile: ) so I really want this to gaming engine to work for me

TimCS

Maybe this is more to your liking:

local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, width = 10, height = 10, transition = easing.outBounce })

Thanks for your code hasty, nice effect as well, when the object drops using this effect is there a way to set it towards another object ? so would using the x , y setting within the transition.to function be used to do this as I cannot seem to get it to fall onto the other object which is larger instead it goes off to one corner.

Thanks

TimCS 

Are you doing something like this:

local circ = display.newCircle( display.contentCenterX, display.contentCenterY + 100, 20 ) local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, x = circ.x, y = circ.y, width = 10, height = 10, transition = easing.outBounce })

If you are setting the x and y destination in the transition to another object like this, it should end up in the centre of that object.

Hi hasty that is exactly what I am doing but the box heads towards the top corner of the “circle” however I am setting the “circle” (which is really an image BTW) but I know now what I am doing wrong on my image in order to make it appear in the center of the screen, I am setting the X and Y anchors = 0 so I guess this is what the box is going towards the anchor positions ? 

If I take the anchor positions away the box goes to the center of the image but the image is then offset to the center 

Thanks

TimCS

Hello again! I see this topic is going pretty far so i thought i’d throw in something cool i put together!!

Try it out!

local circle = {} local aCounter = 1 local timerOne local circleMiddle = display.newCircle( display.contentCenterX, display.contentCenterY, 20 ) circleMiddle.alpha = 0.2 function zoomOut() circleTransOne = transition.to( circle[aCounter], { time = 1000, x = circleMiddle.x, y= circleMiddle.y, xScale = 0.001, yScale = 0.001, alpha = 0, onComplete = removeCircle }) end function removeCircle(event) local removeOne = event.target display.remove(removeOne) end local function spawnCirlces() local xSpawn = math.random(display.contentWidth \* 0, display.contentWidth \* 1 ) local ySpawn = math.random(display.contentHeight \* 0, display.contentHeight \* 1) circle[aCounter] = display.newCircle( xSpawn, ySpawn, 2 ) circle[aCounter].value = aCounter zoomOut() aCounter = aCounter + 1 end timerOne = timer.performWithDelay( 10, spawnCirlces, -1 )

Good Luck and Thanks!

EDIT - Fixed a small bug, should be perfect now!

Yes, the box will go towards the anchor points. To have it go to the centre, you just have to account for the difference.

local circ = display.newCircle( display.contentCenterX, display.contentCenterY, 50 ) circ.anchorX = 0, 0 circ.anchorY = 0, 0 local boxShadow = display.newRect( circ.x, circ.y, 150, 150 ) boxShadow:setFillColor(0, 0, 0, 0.5) local box = display.newRect(display.contentCenterX, display.contentCenterY, 150, 150) box:setFillColor(1, 0, 0) transition.to(box, {time = 2400, x = circ.x + circ.width\*0.5, y = circ.y + circ.height\*0.5, width = 10, height = 10, transition = easing.outBounce }) transition.to(boxShadow, {time = 2400, width = 10, height = 10, transition = easing.outBounce})