Pin one sprite to another of the same type

Get help using Construct 2

Post » Mon Nov 28, 2011 12:02 am

[quote]So you could never have an action that said something like:

Cat(2).my_instance_variable = Cat(1).my_instance_variable.[/quote]

Well, yes you can, what I typed was quite literal, "Sprite(1).X" is an allowed expression:
http://dl.dropbox.com/u/5426011/examples%208/inst_ex.capx
A bit more info:
Sprite(1).X
will always give the X position of the second instance of sprite, (not the second picked).

When families get implimented it would look like this:
Make object "Sprite" part of a family called say "Blue".
Then with events Blue is just another selection of Sprite, so you can pick two separate instances of Sprite.

+ Start of Layout:
+ Sprite: Pick Instance with UID: 22
+ Blue: Pick Instance with UID: 34
---> Sprite: Pin Pin to Blue

B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Nov 28, 2011 12:22 am

Thanks for your exampleR0J0hound, I see what you mean.

I'm guessing it's not possible to select directly by UID with this method without using a loop firstly to map instance indexes to their UIDs and then using local variables to store the relevant indexes of the instances you are insterested in.


Look forward to families, or a way to store types other than Number, Boolean and Text in a local variable (if we could store an object/sprite instance in a variable this would be very powerful and cut down on a lot of event/action/loop work arounds.)jumprock2011-11-28 02:20:43
B
16
S
5
G
1
Posts: 43
Reputation: 1,595

Post » Fri Dec 16, 2011 7:36 pm

Hi Jumprock,

You might be thinking about this from the wrong direction. You probably already know this, but I'll say it anyways: When you select objects with a condition, all the objects with that condition are returned. Therefore, if you have an object called Ball, operations on "Ball" select all of them, but operations which select the specific UID only select the one with that UID... But this also works with instance variables.

If you have two objects that you want to be related in this way, set an instance variable in both to the same (unique in your game) value. (You could do this at the time they are created, perhaps) For example, if you created three sprites and set an instance variable called "attr" to "5" in two of them, but not in the third. When you go to select instances via "Compare Instance Values" and you sellect for attr=5, you will get two instances of the object with the value set, but not the third.

Does that make sense?

B
17
S
3
G
6
Posts: 14
Reputation: 3,850

Post » Tue Jun 26, 2012 6:20 pm

I'm trying to recreate a snake-like effect with each minion collected adding to the end of the chain, but I'm having trouble with this, as the only way I've been able to do it so far is by pining all the sprites to the player, and they bunch up on top of each other. Setting them to solid causes all sorts of problems trying to move the player, so that's no help.
Ideally I would like to pin each sprite(n) instance to sprite(n-1) using a for each loop with the boolean variable collected set to true, but I'm a bit lost, so any help would be appreciated.

BTW sorry to hijack this thread but the original question doesn't seem to have an answer and I dind't want to duplicate.
Storm.storm2012-06-26 18:25:09
B
4
Posts: 1
Reputation: 352

Post » Mon Jul 08, 2013 1:32 pm

is that posible to make object pins to one object's position and second object's angle at the same time ?
B
22
S
3
G
2
Posts: 30
Reputation: 3,688

Post » Wed Aug 21, 2013 7:10 pm

Sorry to dredge this up again, but i'm facing a similar issue and no answer is yet to be found.

I did come up with a rather convoluted workaround that involves spawning invisible anchors to pin to so you are pinning to a different sprite type, but if there is a more elegant way to do this I would love to hear!

http://storage.wertle.com/construct2/SnakeTrailExample.capx
B
9
S
2
Posts: 87
Reputation: 1,051

Post » Sat Jun 14, 2014 5:44 pm

Only way I know how to do this is to have an intermediate object.
That would be the tail in this simple example:
Tail -> Pin to Cat
Cat -> Pin to Tail
B
8
S
1
Posts: 5
Reputation: 437

Post » Wed Aug 06, 2014 2:25 pm

You're absolutely right, this thing has hindered me from efficiently designing a button that builds a bridge when activated, the bridge is made out of smaller blocks. I can't spawn multiple instances of the same object, (I was planning to use "set visible" on the bridge(n).. But it's impossible to reference an object by its index, I think)
B
4
S
1
Posts: 1
Reputation: 250

Post » Sun Oct 18, 2015 1:50 am

How do I pin a object to a cloned object? Meaning using the UID number of the cloned object?
B
14
S
5
G
2
Posts: 164
Reputation: 2,926

Post » Wed Nov 11, 2015 12:19 am

Hi, I have the same trouble. Maybe someone can help or give us a tip.

I have an enemy with Sprite-Head / Sprite-Body / Sprite-ArmLeft / Sprite-ArmRight so if I pin them together everything is fine.
But when I want to clone the enemy (with all his sprites) the pin object pins to the wrong enemy.
Pick by UID is an option, I know. But my enemies will be spawning every X secund(s). So i don't know which UID they'll have (or maybe I do?)

I also tried "pick sprite by overlapping object":

Sprite-Head overlapping Sprite Body
-> Sprite-Head pin to Sprite Body
Sprite-Arm overlapping Sprite Body
-> Sprite-Arm pin to Sprite Body

I know it's a very messy way. And I also tried the same methode with the condition pick by nearest....
But both results are not working properly. Maybe "pick sprite on collusion" works better, but still, it's not a nice way to make it work.

Hopefully somebody can help us here. Thanks!
B
14
S
7
G
5
Posts: 31
Reputation: 3,976

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest