How do I Rotate sprite, then set new bounding box?

0 favourites
  • 12 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • I'm making a level editor and I want to be able to rotate a sprite, and resize it at runtime, but after I rotate it, I want it's height/width to be based on it's new angle. kinda resetting it's bounding box, like you would in photoshop or something.

    so, for example, if i rotate it 90 degrees, essentially it's width becomes it's height (this example wouldn't be hard, but I want it to work for any angle).

    Does that make sense?

    I've been at this for a while, and I can't find anything in the forums.. Is there a plug-in or something that does this?

    Any help would be much appreciated!

  • I'm not completely sure what you are after, but this example might be of help:

  • but after I rotate it, I want it's height/width to be based on it's new angle.

    I'm probably misinterpreting this, but the bounding box automatically resizes based on rotation.. I've just had the reverse of your problem, where I want a visual 'selection' box that doesn't change size as the sprite is rotated, so I can't use the technique used by LittleStain.

  • codah

    couldn't that just be done, using a seperate selection sprite?

  • codah

    couldn't that just be done, using a seperate selection sprite?

    Yep Sorry for the confusion.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • LittleStain Thank you! I think this is what I'm after. Simple enough.. I think I had pretty much figured it out except I had it backwards.. (3 days straight of coding/sleeping/coding.., sooner or later something gets backwards)

    but I'm not positive, I might be trying to do what codah said.. Either way, I think I've got what I need now to figure it out.

    I'll check it out here in a bit and if I can't figure it out I'm holding you both responsible.

    Thanks guys!

  • If you run your game in debug, click on the sprite in the object tree on the left, you will see the bounding box rotating and changing shape in real time, just like what LittleStain did by creating a sprite to the bbox dimensions. I thought you would've done that before

  • I did not explain myself well at all.. but I found what I needed..

    I was basically doing a way too hard version of r0j0's second capx on this post:

    Think I'll just go ahead and do it that way, heh..

  • spacedoubt

    You can do what you described like this,at least for the first part that is.

    https://dl.dropboxusercontent.com/u/542 ... w_rot.capx

    The bounding box of a rotated triangle can be found by adding an image point at each corner of the triangle and then finding the min and max horizontally and vertically.

    And like you said you can make the bounding box only update after rotation. The only tricky part was positioning the bounding box while rotating, but there's a useful formula for that here:

    https://www.siggraph.org/education/mate ... 2drota.htm

    And while I was at it I added the ability to rotate around any point for little extra effort,

    The only aspect of that can't be done is resizing in relation to the screen, as that would introduce skewing, which C2 can't do. So you'd be limited to only resizing relative to the object.

    Edit:

    Here it is working with multiple objects. Shirt click to toggle selection.

    https://dl.dropboxusercontent.com/u/542 ... multi.capx

  • R0J0hound You're not fooling anyone. We all know you're some sort of space alien.

    Thanks so much! I appreciate that. You have no idea how much I've learned from you.

    The only aspect of that can't be done is resizing in relation to the screen, as that would introduce skewing, which C2 can't do. So you'd be limited to only resizing relative to the object.

    Would you mind elaborating on this just a bit? Once I've rotated it, can I scale the bbox and have the sprite scale with it, or is that what you're saying it can't do?

  • Well, take for instance a box rotated 45 degrees. Then if you stretched it vertically relative to the screen you would get an elongated diamond. There isn't a way in C2 to stretch the box like that. Other than that the math is not bad.

  • That makes sense.

    I ended up with something I like. It's kinda some weird mixture of everything.. but it works, and I understand it, heh..

    Thanks again!

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