Set center point runtime

Discussion and feedback on Construct 2

Post » Sun Jun 23, 2013 3:23 pm

Hi all,

I want to know if somebody has a trick or a way to set the center point (0) on runtime?

Because I want to "pin" some runtime created sprites and in some of than the middle is not the point I want!

Thanks
B
108
S
11
G
8
Posts: 180
Reputation: 8,728

Post » Sun Jun 23, 2013 4:04 pm

You can't change the origin at runtime, but why not use multiple image points, and just pin to them as needed?
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Sun Jun 23, 2013 4:48 pm

I'm not sure I understand what you mean by runtime created sprites. If you want to pin object A, to object B, your are going to pin the origin of A to maintain relation to object B, so A does not stick to the origin of B, it just keeps it's relative position to B consistent to where it was before pinning.

If you move A 20 px to the left of B and then pin, A will be kept at 20 px left of B (well, rotation is also taken care of in a smart way).

Here's an example of attaching A to B, when you don't care about what origin B has: http://dl.dropbox.com/u/10338488/pin_to_not_center.capx

I hope this solves your pinning problem, as I don't see how changing the origin of A could have any affect. Say you have a sword, and you want to hold the sword by the handle (so you put the origin in the handle when you have it attached to a character). If you want to stab the enemy and have the sword stay in the enemy, if you position the sword such that the tip is in the enemy, and then pin it, it would still work perfectly. Rotation and all taken into account.
B
10
S
5
G
3
Posts: 4
Reputation: 1,664

Post » Mon Jun 24, 2013 12:49 pm

@GeometriX and @laserbeam

Sorry the long time to comment, but just after I do the post, I had a fever in all day long! Now I am better so let me explain again.

The trouble I have is because when I "LoadURL" an "sprite", it come with the origin at the center. If the "sprite" is a arm, when I "pinned" it to the torso it rotates at the center, instead of in the shoulder.
B
108
S
11
G
8
Posts: 180
Reputation: 8,728

Post » Mon Jun 24, 2013 1:10 pm

Ah, you should've said that these are loaded sprites.

In that case, you can't do anything with the sprite itself, but you could create an invisible dummy object that's pinned to the loaded sprite's origin, and set up with its own image points that can be pinned to.
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Mon Jun 24, 2013 4:07 pm

@GeometriX

Yes I already think in this way, but is complicated for many objects.

Thanks anyway
B
108
S
11
G
8
Posts: 180
Reputation: 8,728

Post » Mon Jun 24, 2013 5:13 pm

Another option would be to create your own pinning system using events. You'd have to use a bit of trig, but it should give you the flexibility you need to position objects based on a loaded objects center origin.

Having said that, I think GeometriX's suggestion of using an invisible object would work just as well, and be much simpler to implement.
B
62
S
19
G
8
Posts: 341
Reputation: 12,075


Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot], zenox98 and 6 guests