Pin one sprite to another of the same type

Get help using Construct 2

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

Post » Wed Nov 11, 2015 6:01 am

Mario I don't know how you could solve this, but bear in mind that multiple pinned objects might start lagging. Especially it they are pinned in a [Parent<--Child<--Child of child] fashion. It seems to me that manual positioning is always faster and I'd like to hear the more advanced users' opinions about this.
B
12
S
4
G
1
Posts: 116
Reputation: 1,680

Post » Wed Nov 11, 2015 11:38 am

@immortalx thank you for your advise, you are right. As I said, it's a very nasty way of "coding" and in the end it's not solving the problem.

I guess, I have to read more about IID, UID and Functions.
B
14
S
7
G
5
Posts: 31
Reputation: 3,976

Post » Wed Nov 11, 2015 12:04 pm

Hey Mario4President, :)

If each enemy is made up of a set of unique object types, then you might be able to use the "Containers" feature of Construct 2, to associate all the objects of an enemy.

This will work as long as an enemy only needs one of each object type.
For instance, if an enemy has a body and two arms, all as separate objects, then you'd need the arms to each be unique objects (e.g. leftArmObj, rightArmObj), as you can't put the same object (e.g. armObj) in a Container twice. At least not to my knowledge.

Containers page of Scirra's C2 Manual
B
21
S
13
G
8
Posts: 306
Reputation: 5,458

Post » Thu Nov 12, 2015 11:23 am

@fisholith

Hey, I was playing around with Containers too. It'll work.....but not for me, because I need the sprites to be independent. So if you hit the Sprite_Arm, only the Sprite_Arm will be destroyed. Not the whole Enemy. Containers are fine, but not in this case.

Anyways, I found a very good tutorial written by TELLES0808. It helped me a lot, I played around a bit and I think I found a workaround for my problem.
In case somebody is interessted in, I'll try to post it here. Right now I'm overworked but hopefully I'll find some time in the evening.

I would like to post the link to the tutorial but I'm not allowed to, since I have not enough rep-points for posting urls but the tutorial is called "Understanding UID, IID, Health, Cards and Rocket smoke trail."
B
14
S
7
G
5
Posts: 31
Reputation: 3,976

Post » Fri Nov 20, 2015 2:08 pm

Ah, yeah, containers will take everything down with them if they get destroyed.
Below are a few possible alternatives that might work in place of containers.
Also, I posted the link to the tutorial you mentioned at the very end. :)


UIDs & Private Variables
As an alternative to containers, you can store the UID of the ArmObj in a private variable of the ArmDetectorObj.
Then if ArmDetectorObj collides with lava, you can,
Pick ArmObj by UID, (using the UID you stored earlier), and Destroy just the ArmObj.
To make sure the UID gets stored correctly, you can Have the ArmObj's "On created" event be responsible for creating the ArmDetectorObj, and saving the ArmObj's UID into a private variable of ArmDetectorObj.

Thus, whenever you create an ArmObj, it will automatically instantly create and link its very own unique ArmDetectorObj .


Pin Behavior & "PinnedUID" Expression
In some cases, if you are already using the Pin Behavior, you can use it's built in PinnedUID expression to get the UID of the pinned object, though this is more of a special case.
Manual page: Pin Behavior


Store Reference Behavior
Another option that might be worth looking into is the third-party "Store Reference" behavior.
It can be added to objects to make linking them in events simpler and easier to read.
Forum page & Download: Store Reference Behavior


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Here's the link to the tutorial you mentioned :)
Understanding UID, IID, Health, Cards and Rocket smoke trail.
B
21
S
13
G
8
Posts: 306
Reputation: 5,458

Post » Tue Dec 15, 2015 3:46 pm

@fisholith
Ah, yeah Version 1 "UID & Privat Variable" is a nice solution too. In fakt, it's even better, because the Programm-Code will be much smaller and clearer than the way I did it.

and thanks a lot for posting the third-party Behavior. It's great! It will help me with much more than only in this matter!
B
14
S
7
G
5
Posts: 31
Reputation: 3,976

Post » Fri Jan 08, 2016 2:54 am

is there someone here can help me with my custom analog control for my character?
B
3
Posts: 1
Reputation: 177

Previous

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 31 guests