Please do a favor!

Hello everyone ! I recently played impossible rush which is maked by 15 YEAR old boy which is on the top charts of the apple a few time ago…so while playing his game one thing confused me that “How to make thing rotate with touch” means as soon as  i touched the screen it rotates to the right…wow thats amazing i mean i can not understand whether that object is static or dynamic ??..and i just know that it must contain some thing like :-

local function onTouch (event) if (event.phase == "began" ) then 

only i know this please complete the function or edit it and if can please help me to understand …please…do this favor.

WAITING FOR REPLY… :slight_smile:

You can get the source code for that here I believe: http://ragdogstudios.com/shop/impossible-rush-source-code/

Sorry i can not buy…but then also if you know than please right the code and even if i buy the code then also i do not have anyone here to help me understand it!

I can tell you that the colored block could be set up in several ways:

  1. No physics at all. It is possible to calculated the collision/intersection of the dot with the block without physics.  Then rotation would be done via a transition.to() call.

  2. Physics with a dynamic body.  The body would then have the gravityScale set to 0 and the dot would use gravity to fall.  In this case you could still use transition.to() to rotate, manually code via an enterFrame listener, … 

  3. Physics body with a kinematic body.  This would be best.  It would ignore forces (like gravity) but you could still manipulate the object and it’s respective bodies.

The real question is, how does he detect color collisions.  i.e. How does he know if he is colliding with the red, green, yellow or blue side?

This would actual be done by tracking the current rotation of the block and then using that knowledge to determine, “rotation == 0, collide with red side; … collision == 270 collided with green side”

Please be aware, there is no ONE way to achieve all of these interactions and actions.  You could code this in about a dozen ways.

I’ve not played the game. Rotation is really easy,  but the effects for rotation ramp things up a bit.

If you just want to change the rotation, then if your object is called “box”:

box.rotation = 90

That will rotate to a specific angle… If you want to rotate it left or right by X number of degrees:

box.rotation = box.rotation - 90 -- rotate counter clockwise 90 degrees box.rotation = box.rotation + 90 -- rotate clockwise 90 degrees

Both of these will be instance with no animation. To animate it for a fixed rotation you would use transition.to:

transition.to( box, { time = 500, rotation = -90, delta = true })

This animates the rotation 90 degrees counter clockwise over 1/2 second (500 milliseconds). If you want to touch and hold and have it rotate while it’s being held down, that’s starting to ramp up the complexity.

Rob

ok i understand upper section but what you said about “how does he detect color collisions.  i.e. How does he know if he is colliding with the red, green, yellow or blue side?” i do not understand …(sorry :frowning: ) but please touch your topic deeply.

THANKS BRO…your code works and is fantastic …with all of you i have learned soooo much in 4 days and my complete code for thus command is 

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation - 90 box.rotation = box.rotation + 90 transition.to(box , {time = 500 , rotation = -90 , delta = true}) end end Runtime:addEventListener("touch" ,rotateBox)

Thank you very much…but a question arises to me that "Why we have written

box.rotation = box.rotation - 90 box.rotation = box.rotation + 90)  

i mean it doesn’t make any sense (but it work)…we rotate the box firstly in -90 and then in +90 which result to be zero…seriously…and also “Why we only wrote -90 in transition.to command”??

transition.to(box , {time = 500 , rotation = -90 , delta = true})

Don’t irritate…Think that i am your lil brother so please tell me !! please please please

Rob says that you can either rotate it anti-clockwise by using - 90 and clockwise by using + 90, not to write the both code at the same time

You can write anything in transition.to command . like + 90 or + 100 or + 140… It depends on you !! 

This should be your code

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation - 90 -- to rotate it anti clockwise without any transition end end Runtime:addEventListener("touch" ,rotateBox)

Or

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation + 90 -- to rotate it clockwise end end Runtime:addEventListener("touch" ,rotateBox)

Or 

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then transition.to(box , {time = 500 , rotation = -90 , delta = true}) -- to rotate it anticlockwise with a transition end end Runtime:addEventListener("touch" ,rotateBox)

Oh my Gosh you are awesome bro…i have no words as you are just awesome…omg…really understood and you are genious :)…you telled me the easiest way…Thanku

You can get the source code for that here I believe: http://ragdogstudios.com/shop/impossible-rush-source-code/

Sorry i can not buy…but then also if you know than please right the code and even if i buy the code then also i do not have anyone here to help me understand it!

I can tell you that the colored block could be set up in several ways:

  1. No physics at all. It is possible to calculated the collision/intersection of the dot with the block without physics.  Then rotation would be done via a transition.to() call.

  2. Physics with a dynamic body.  The body would then have the gravityScale set to 0 and the dot would use gravity to fall.  In this case you could still use transition.to() to rotate, manually code via an enterFrame listener, … 

  3. Physics body with a kinematic body.  This would be best.  It would ignore forces (like gravity) but you could still manipulate the object and it’s respective bodies.

The real question is, how does he detect color collisions.  i.e. How does he know if he is colliding with the red, green, yellow or blue side?

This would actual be done by tracking the current rotation of the block and then using that knowledge to determine, “rotation == 0, collide with red side; … collision == 270 collided with green side”

Please be aware, there is no ONE way to achieve all of these interactions and actions.  You could code this in about a dozen ways.

I’ve not played the game. Rotation is really easy,  but the effects for rotation ramp things up a bit.

If you just want to change the rotation, then if your object is called “box”:

box.rotation = 90

That will rotate to a specific angle… If you want to rotate it left or right by X number of degrees:

box.rotation = box.rotation - 90 -- rotate counter clockwise 90 degrees box.rotation = box.rotation + 90 -- rotate clockwise 90 degrees

Both of these will be instance with no animation. To animate it for a fixed rotation you would use transition.to:

transition.to( box, { time = 500, rotation = -90, delta = true })

This animates the rotation 90 degrees counter clockwise over 1/2 second (500 milliseconds). If you want to touch and hold and have it rotate while it’s being held down, that’s starting to ramp up the complexity.

Rob

ok i understand upper section but what you said about “how does he detect color collisions.  i.e. How does he know if he is colliding with the red, green, yellow or blue side?” i do not understand …(sorry :frowning: ) but please touch your topic deeply.

THANKS BRO…your code works and is fantastic …with all of you i have learned soooo much in 4 days and my complete code for thus command is 

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation - 90 box.rotation = box.rotation + 90 transition.to(box , {time = 500 , rotation = -90 , delta = true}) end end Runtime:addEventListener("touch" ,rotateBox)

Thank you very much…but a question arises to me that "Why we have written

box.rotation = box.rotation - 90 box.rotation = box.rotation + 90)  

i mean it doesn’t make any sense (but it work)…we rotate the box firstly in -90 and then in +90 which result to be zero…seriously…and also “Why we only wrote -90 in transition.to command”??

transition.to(box , {time = 500 , rotation = -90 , delta = true})

Don’t irritate…Think that i am your lil brother so please tell me !! please please please

Rob says that you can either rotate it anti-clockwise by using - 90 and clockwise by using + 90, not to write the both code at the same time

You can write anything in transition.to command . like + 90 or + 100 or + 140… It depends on you !! 

This should be your code

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation - 90 -- to rotate it anti clockwise without any transition end end Runtime:addEventListener("touch" ,rotateBox)

Or

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then box.rotation = box.rotation + 90 -- to rotate it clockwise end end Runtime:addEventListener("touch" ,rotateBox)

Or 

display.setStatusBar (display.HiddenStatusBar) centerX = display.contentCenterX centerY = display.contentCenterY local box = display.newImageRect("crate.png" , 160 , 160) box.x=centerX box.y=320 box.rotation=90 local function rotateBox (event) if (event.phase=="began") then transition.to(box , {time = 500 , rotation = -90 , delta = true}) -- to rotate it anticlockwise with a transition end end Runtime:addEventListener("touch" ,rotateBox)

Oh my Gosh you are awesome bro…i have no words as you are just awesome…omg…really understood and you are genious :)…you telled me the easiest way…Thanku