Newbie here, seeking for help - drag gesture

Hi guys,

Im a n00b and I need some help with an idea I have.

I have a circle on my screen and as I swipe the screen I want that circle to rotate…

Can anyone suggest how can I achieve this?

Thank you [import]uid: 8241 topic_id: 3096 reply_id: 303096[/import]

Hi Andrei,
logically, calculate the distance the touch has moved from the last polled position and then based on that distance, you can set the rotation of the object. So if the swipe from one end to the other end of the screen was 360 degrees and the screen is 320 (width) x 480 (height) then angle = (320/360) * pixels_moved

I hope you understand this and your question is resolved.

If you are after some code to do that, I need to look at the corona equivalents and write something up for you, I am new to Corona, but the concepts of creating games are fine.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3096 reply_id: 9127[/import]

Thank you very much for your reply.

As I’ve said I’m new to corona, so if you will be able to help me with an example of the code I will be very grateful.
If you want we can talk in more detail on my email address andrew[dot]buta at gmail [dot com].

Thank you very much,

Andrei [import]uid: 8241 topic_id: 3096 reply_id: 9165[/import]

Hi andreib,

try this code, I changed the rectangle to text, so that you can see the rotation better

--Rotate a rectangle based on sliding the finger on the screen  
  
--Variables used locally  
local rect  
local startX, startY  
local dX, dY  
  
local amountToRotate  
  
--Functions   
onTouch = function(event)  
 if event.phase=="began" then  
 startX = event.x  
 startY = event.y  
 elseif event.phase=="ended" then  
 --  
 elseif event.phase =="moved" then  
 dX = startX - event.x  
 dY = startY - event.y  
  
 rect.rotation = (dY \* amountToRotate)  
 end  
end  
  
amountToRotate = (360/display.contentHeight)  
--rect = display.newRect(display.contentWidth/2,display.contentHeight/2,100,100)  
--rect:setFillColor(255,0,0,200)  
  
rect = display.newText("Hello", display.contentWidth/2, display.contentHeight/2)  
rect:setTextColor(255,255,255)  
  
Runtime:addEventListener("touch", onTouch)  

This could be optimised for better handling, but to get an idea of what you want, I think this is a good start for you.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3096 reply_id: 9235[/import]

Wow,

This is exactly what I wanted to achieve.

Is it possible to give me your email address and talk in detail, I’m really thinking that we can cooperate somehow :wink:

Thank you [import]uid: 8241 topic_id: 3096 reply_id: 9270[/import]

Hi andreib,
I am not sure how we can collaborate, but I am all ears. You can get in touch with me on jayantatjcu (at) gmail (dot) com.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3096 reply_id: 9271[/import]