How to rotate object to different angles easily??

0 favourites
  • 4 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hi C2 users:

    Another question from a nub. Is there a way to easily rotate an object? That is,

    1. user touches object. (this is for the iPad so I need to use touch and also mouse for testing--I've read that tutorial on how to use both so can probably figure that out)

    2 object rotates 45 degrees.

    3. Repeat rotation. (I want this to be an endless loop, but want the user to be able to control the rotation based on the touch)

    I have used another similar program where this is fairly simple. I'm just not finding an easy way to do this in C2.

    Since I'm new to C2, I'm looking for something that I'd be able to understand without a lot of background in the software.

    TIA <img src="smileys/smiley1.gif" border="0" align="middle" />

    • On Object1 touched
    • > Set Sprite.angle to Sprite.Angle+45
    • On Object2 touched
    • > Set Sprite.angle to Sprite.Angle-45
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can test whether a finger touches on an object using the Touch -> On Touched Object event. Select the object you want to rotate, and in the events you add the Rotate clockwise (or counter-clockwise) action for the object.

    If you want to test for the mouse however you should add the Mouse button is down condition, right click it and select add another condition. This time choose Cursor is over object. Then you can add the events to rotate the object.

    Note; You can't simply use the 'mouse on object clicked' event because this way you'd have to click it multiple times to rotate it (and not instead holding the mouse button down).

    If you want to allow the object to be only rotated to 45, 90, 135, 180, etc, you should be a little more specific. Do you want to make the object rotate immidiately 45 degrees after a second passes (and not smooth)? Or do you want it to rotate a little (eg 5 degrees) as long as the object is touched? In the last case, should it rotate to the nearest interval(-thing? 45 or 90 or 135 or etc)? Or should it always rotate upwards (so if the angle is say 60 and the object isn't touched anymore it automaticly rotates futher to 90).

  • Thank you. I will try to test these solutions out and get back with any further questions. I appreciate the help.

    OK. Just tested this. EncryptedCow's solution works, but doesn't loop and uses two sprites. Maybe i'm missing something, but I would like to use one sprite and rotate it to angles whenever the user touches the object. For now, I think using the mouse is the best option. I can try out the touch later.

    Jasper's solution is a little confusing for me.

    I get this piece:

    • Mouse Left Button is Down

    -Mouse Cursor is Over Sprite

    But don't understand "Then you can add the events to rotate the object." I add events and not actions?

    I would like the object to freely rotate to any angle that the user wishes. Not sure how to set that up either. If that would be to hard for a nub to understand, maybe a rotation to by 45 degrees on each click or touch would work.

    "If you want to allow the object to be only rotated to 45, 90, 135, 180, etc, you should be a little more specific. Do you want to make the object rotate immidiately 45 degrees after a second passes (and not smooth)? Or do you want it to rotate a little (eg 5 degrees) as long as the object is touched? In the last case, should it rotate to the nearest interval(-thing? 45 or 90 or 135 or etc)? Or should it always rotate upwards (so if the angle is say 60 and the object isn't touched anymore it automaticly rotates futher to 90)"

    Thanks again for your help.

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