If you want to use overlaying sprites, which technique makes more sense..

0 favourites
  • 10 posts
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • If you want to have two sprites of same size and shape over each other (to create certain visual effects by manipulating their effects individually for example) does it make more sense to use two different objects or try to use two instances of the same object and control them individually by manipulating their instance variables individually.

    Using two objects is much easier since you can just pin one to the other, but using two instances of the same object would save memory usage if you are using large sprites and you would be using the same sprite for both objects anyway.

    I tried using two instance of the same object but could not get it to work really well. How would you code an object so it always has two instances on top of each other and you can control the variables of those two overlapping instances individually?

  • The most common way to address two instances separately is to use a family. Add this sprite to a family, move all instance variables to the family level. If you have many instances, you can add another variable ParentUID. And then you will be able to pick the "parent" sprite instance, its "child" family instance, and refer to them both in the same event.

    On clicked Sprite
    SpriteFamily compare variable ParentUID=Sprite.UID
    	Sprite set opacity to 100
    	SpriteFamily set opacity to 50
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi DOP!

    I Know I should Use families. There is on complicating factor though. I would like the instances to be on separate layers for effect purposes. However, I'm also sorting the z-order of the instanced by using the "sort z-order" action which seems to move all the instances of the same object to the same layer.

    So I'm not sure if what I'm trying to do is really possible, unless you can use the "sort z-order" action selectively, so instances of the same object get sorted right on different layers. Alternative methods of sorting z-order are probably more resource demanding than just using two objects.

  • You can pick only instances on a selected layer, and move them to top/bottom of the layer depending on the value in the instance variable. If you don't have too many objects and not doing it too often, I think it should be ok performance wise..

  • In this case I have about 120 objects that are constantly moving, so their Z-level needs to be updated quite frequently. I suppose that can start to get demanding.

  • This is how i tried to pin the "parent" and "child" instance together:

    Upon creation two instances are given the same Family.UID variable value. The other instance is also set Child Boolean True.

    Object.FamilyUID = Family.FamilyUID

    Obect = Child Boolean True

    => Pin Object to Family.

    Doesn't seem to work.

  • No, this is not right. There is no such thing as "family UID". All instances are in the family, and each instance has different own UID.

    You can assign the same unique identifier to both instances, which you will need to generate and make sure it's unique.

    But I think the easier solution is to declare one instance "parent" and another "child" and link the child to the parent using ParentUID.

    If ParentUID=0, then this is a parent instance. If ParentUID>0, this is a child instance and you can easily find its parent.

  • Yes, I see how that should work. However, I think I'm setting up the code incorrectly since I don't seem to be able to pin the child object to the parent object. How would set up the event to pin each child to their parent object after creation.

  • It depends on how you create these instances. Do you place them on the layout in pairs in the editor? Or do you create them in runtime?

    EDIT: here is a demo:

    dropbox.com/s/pigyy4g5kgb67kq/PairInstances.capx

  • Thanks!

    I think I got to work the way I want now.

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