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

Get help using Construct 2

Post » Mon Sep 29, 2014 2:18 am

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!
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Mon Sep 29, 2014 8:59 am

I'm not completely sure what you are after, but this example might be of help:
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Sep 29, 2014 10:15 am

spacedoubt wrote: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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Sep 29, 2014 10:43 am

@codah

couldn't that just be done, using a seperate selection sprite?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Sep 29, 2014 10:46 am

LittleStain wrote:@codah

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


Yep :) didn't say I hadn't done it, just that I couldn't use the bounding box size :) Sorry for the confusion.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Sep 29, 2014 11:49 pm

@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. :twisted:

Thanks guys!
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Tue Sep 30, 2014 12:21 am

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 :D
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Sep 30, 2014 1:02 am

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:
viewtopic.php?t=71352&start=0

Think I'll just go ahead and do it that way, heh..
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Post » Tue Sep 30, 2014 1:56 am

@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
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Tue Sep 30, 2014 4:31 am

@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.

R0J0hound wrote: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?
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 45 guests