Pin one sprite to another of the same type

0 favourites
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hi, an answer to this question might solve a few problems for me.

    How do I Pin one sprite to another of the same type at runtime? (via the Pin command).

    As far as I've been able to tell you can't reference two different sprites of the same type at the same time, so my_sprite(1) can't be pinned to my_sprite(2). I also don't think you can hold types other than Boolean, Number or String in a local/global variable, so that approach wouldn't work.

    Any confirmation/clarification about this would be much appreciated!

  • Add Pin behavior to my_sprite(1), go to Events sheet and set action for my_sprite(1) "pin to object" and select my_sprite(2).

    <img src="http://dl.dropbox.com/u/50581036/27.11.png" border="0" />

  • Hi JohnJ, thanks for taking the time to reply but I think your example illustrates linking a sprite of one type to a sprite of a different type. What I am talking about would be like trying to pin one instance of Sprite2 (a ghost) to another instance of Sprite2 (another ghost).

  • i tried it and i think you right, i doesnt work, i think the behavior doesn't take the picked objects into account for this to work behavior should be modified

  • jumprock, ok, I see now. And for what you pin one Sprite2 to another Sprite2? Any control or change params will be work for both... Make different types?

    Or you can create an example, share it and tell which result do you want.

  • Hi JohnJ, In this situation finding a workaround isn't really the focus, it's just serving to highlight the fact that references to two or more different instances of a single type can never exist in the same event action at the same time (and hence they can never have direct access to each other).

    Pinning was just an example (one that I currently am dealing with) of functionality that can't be used because of this.

  • Not possible? (referencing two instances of the same type in the one action)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If there are two Sprite instances their values can be accessed with Sprite(n).

    Ex.

    Text: Set Text to Sprite(0).X + Sprite(1).X

    In the case of your question, it will be simple to do when families are implemented, but at this point you'll have to resort to events instead of using the pin behavior as a workaround.

  • Hi R0J0hound, I'm not sure that would work.

    Just say your sprite type was called Cat, as I understand it you could pick a first instance by it's index (though probably seleting by UID is going to be more use) but once you picked a second instance the reference to Cat in your actions section would be to the last selected instance.

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

    Cat(2).my_instance_variable = Cat(1).my_instance_variable.

    Instead all you can do is:

    Cat.my_instance_variable = Cat.my_instance_variable

    where Cat refers to the last referenced instance. As far as I can tell actions only allow you to reference a single, currently selected instance of any particular type at a time.

    Not sure if I have a correct understanding or maybe didn't comprehend exactly what you were saying, but to me it seems impossible without a middle man event/action to store values in a proxy variable. And the native Pin functionality seems impossible to implement at all between two instances of the same type.

    Will be interested to see families... can you explain the concept at all?

  • o you could never have an action that said something like:

    Cat(2).my_instance_variable = Cat(1).my_instance_variable.

    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

  • 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.)

  • 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?

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

    <img src="https://dl.dropbox.com/u/81458667/code.JPG" border="0" />

    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.

  • is that posible to make object pins to one object's position and second object's angle at the same time ?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)