Set Pivot Point of a sprite

For questions about using Classic.

Post » Mon May 02, 2011 12:31 pm

Hello everyone,

Is it possible to set the pivot point (or hot spot) of a sprite to a certain value?

I'd like to have multiple objects rotate around the same axis.

Thanks in advance,
Maarten
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 02, 2011 5:30 pm

I think this is possible, have you tried "Set current frame pivot point" under "Animation" actions for the sprites? If you don't need this to work at runtime, clicking the red target in the image editor will let you place one as well. Hopefully these work with co-ordinates outside of the object itself.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon May 02, 2011 6:05 pm

Thank you for your reply! It worked, but not as I expected it to work. What I'm trying to do is this:

I have 3 sprites and want to rotate them in a way that their relative position and angle towards each other stays the same. Something like this:



Is it possible to create some kind of parent to do this?
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 02, 2011 6:24 pm

Ahh, that takes some math, no problem though since I had to do something like that before :)

Here is how to have them always stay at the same point relative to a base object.

X position of point/object to attach to base:
[code:2i1cs2vl]Mech.X - distance(WeaponSlot.Value('XOffset'),WeaponSlot.Value('YOffset'), 0, 0) * cos(Mech.Angle + angle(WeaponSlot.Value('XOffset'),WeaponSlot.Value('YOffset'), 0, 0))[/code:2i1cs2vl]

Y position of point/object to attach to base:
[code:2i1cs2vl]Mech.Y - distance(WeaponSlot.Value('XOffset'),WeaponSlot.Value('YOffset'), 0, 0) * sin(Mech.Angle + angle(WeaponSlot.Value('XOffset'),WeaponSlot.Value('YOffset'), 0, 0))[/code:2i1cs2vl]

Where XOffset is the constant X offset from the base at the normal angle,YOffset is the constant Y offset from the base at normal angle and Mech is the base object.

Then you just change the angle of the blue bars to the angle of the base! :D
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon May 02, 2011 6:34 pm

Wow thanks, that looks a bit too complicated for me to come up with at the moment. I'm having a bit of a hard time to understand it.

Am I right that the WeaponSlot is the base object and the Mech is the object that you want to rotate with the WeaponSlot? And did your create a variable with the XOffset and the YOffset of the WeaponSlot?
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 02, 2011 6:54 pm

[quote="Muurtegel":fm05llss]Wow thanks, that looks a bit too complicated for me to come up with at the moment. I'm having a bit of a hard time to understand it.

Am I right that the WeaponSlot is the base object and the Mech is the object that you want to rotate with the WeaponSlot? And did your create a variable with the XOffset and the YOffset of the WeaponSlot?[/quote:fm05llss]

Heh, almost (WeaponSlot is the object that rotates around Mech) and yup, XOffset and YOffset belong to WeaponSlot.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Mon May 02, 2011 7:11 pm

Sorry for taking so long to get this straight, I'm still doing this wrong.

Maybe you can help me by taking a look at the .cap: https://rapidshare.com/files/460290723/rotating.cap

Thanks a lot for the help so far!
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 02, 2011 7:19 pm

You could always use image points.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon May 02, 2011 7:24 pm

Well I currently have no idea what I'm doing (I'm just doing what JayJay suggests and haven't figured out how it works yet). So if you have a better suggestion, please do tell me.
B
2
S
2
G
1
Posts: 109
Reputation: 1,068

Post » Mon May 02, 2011 7:27 pm

Ah, that's saved in a newer version of Construct. I'll make a cap of my own to show you (I don't want to update until I have time to make sure my game project will work the same in the newest version). Hopefully I'll have it ready in the next half hour.

Edit: Here is the example of my method, I'll try it using image points as I think that should work too and upload that here in a bit.

[url:2ev1bgms]http://dl.dropbox.com/u/4714446/Rotate.cap[/url:2ev1bgms]

Edit 2: Alright, that was much quicker to make :lol: Although this method has some disadvantages (you can't reposition the arms at runtime, or load custom offsets from files, etc). Still, this one should be much easier to implement if you want the arm rotation to be hard coded.

[url:2ev1bgms]http://dl.dropbox.com/u/4714446/Rotate%20Method%202.cap[/url:2ev1bgms]
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests