How do I create 360 rotation of object on touch (no slider use)?

0 favourites
  • 12 posts
From the Asset Store
JPEG format 364x HD backgrounds in 2688 x 1536 Resolution
  • Hi Friends,

    Need help in getting 360 rotation of an object done (already have different angles images) on touch swipe left and right. You might have seen the same in many sites where car or bike is rotated using mouse or touch. Please help me how to do that. Sharing capx of what I have done before and it not giving best results.

    Here is the file. bit.ly/2VFgCy1

    Regards,

    Jatin

    Tagged:

  • Wow, 37 events to rotate one sprite! :)

    You can remove the slider bar and do this with just one event:

    Mouse left button is down: Sprite set frame to ((mouse.X+180)%180)/5
    

    Also, set animation speed to 0 in the sprite editor.

  • Or maybe

  • Or maybe

    Hi thanks for the reply but I tried to add the touch and it is giving weird jerks while touching the sprite and everytime starts from same position on touch instead of starting from the position where last touch ended. can you help me out how to make it smooth?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Wow, 37 events to rotate one sprite! :)

    You can remove the slider bar and do this with just one event:

    > Mouse left button is down: Sprite set frame to ((mouse.X+180)%180)/5
    

    Also, set animation speed to 0 in the sprite editor.

    Hi DOP, thanks for reply but the solution you shared roated image once and then stopped. where as my requirement is smooth 360 rotation on touch. can you help me out in that.

  • Sorry, I don't understand. You can rotate the image left and right many times, not just once.

  • Sorry, I don't understand. You can rotate the image left and right many times, not just once.

    It rotates with jerk on touch start. oN each touch start it starts from same fixed point instead of from the point where user touches.

  • Ok, I fixed it, see this demo:

    dropbox.com/s/7rrjq240qvwsykq/slider-pulsar2.capx

  • Ok, I fixed it, see this demo:

    https://www.dropbox.com/s/7rrjq240qvwsykq/slider-pulsar2.capx?dl=0

    Great solution !

  • Ok, I fixed it, see this demo:

    https://www.dropbox.com/s/7rrjq240qvwsykq/slider-pulsar2.capx?dl=0

    Thanks a ton dop. it worked very nicely now. 100% working solution. But I have one question, what is the solution formula you applied for animation frame on touch/mouse. Bcz when I tried the same 360 rotation on object with 23 frames (instead of 35 of pulsar demo capx), it acted wierdly though rotated smoothely. On swiping towards right, bike was rotating towards left side and vice versa instead of goign into the same direct as of touch direction. I think the secret is behind the formula u applied, can you explain it a bit. That will be very helpful.

  • Are you talking about the last formula? It should work with any number of frames in the animation.

    .

    I am not very good at explaining..

    (((mouse.X-startX)/8)+(Sprite4.AnimationFrameCount*10)+startFrame)%Sprite4.AnimationFrameCount

    Here "8" means sensitivity - frame will change every 8 pixels.

    %Sprite4.AnimationFrameCount is the remainder after division. For example, 50%36 will give you frame number 14 in animation with 36 frames.

    (Sprite4.AnimationFrameCount*10) - this part of the formula is needed to prevent the value in brackets to go into negative numbers (when you swipe to the left). It basically just adds 360. For example:

    (10+360)%36=10

    (-10+360)%36=26

  • Are you talking about the last formula? It should work with any number of frames in the animation.

    .

    I am not very good at explaining..

    (((mouse.X-startX)/8)+(Sprite4.AnimationFrameCount*10)+startFrame)%Sprite4.AnimationFrameCount

    Here "8" means sensitivity - frame will change every 8 pixels.

    %Sprite4.AnimationFrameCount is the remainder after division. For example, 50%36 will give you frame number 14 in animation with 36 frames.

    (Sprite4.AnimationFrameCount*10) - this part of the formula is needed to prevent the value in brackets to go into negative numbers (when you swipe to the left). It basically just adds 360. For example:

    (10+360)%36=10

    (-10+360)%36=26

    Thanks dop for such nice explanation. It is really helpful but you r bad lier, u said you r not good explainer but I feel you are good in explaining the solution. God bless you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)