Spawned Copies of Sprites

0 favourites
  • 13 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • Hi all

    New to Construct (and game authoring) but have gone through the faq, manual and forum looking for an answer to this.

    I have a sprite "Carn" to which I assign values to variables during runtime, not in the layout. Once this instance has enough health & energy I spawn a new instance of Carn.

    At present, the new instance selects the default variable values from the layout. I would like it to inherit its parent's values.

    Secondly, after the spawn action in the same event, if I select Carn.UID it gives me the UID of the parent, not the child.

    This picture might make it a bit clearer:

    <img src="http://www.superelastic.net/construct2/CarnSpawn.png" border="0" />

    Any help would be much appreciated.

    Thanks

  • Save the parent UID in a local variable before spawning the new object, this way you can refer to it with 'pick UID with variable_here' condition. Depending on how many variables we are talking about it might be simpler to save the variables themselves into local variables before spawning the object and then assign them from the local variables :)

  • Thanks for the reply, vee. For inheritence, I could individually assign each variable to the child object (although there are 30+variables) but seems a reasonable solution. However, I still need to identify the child UID. I thought this would be populated by NewUID=Carn.UID but that picks up the parent.

  • This could work: save parents uid into variable of the child (var_parent). Now you can do cool stuff like pick every child of certain carn with event like this :

    carn.var_parent = parentcarnUID

    .. Set variables to same as parent

    After you create new,object in construct it is picked automatically. If You created it from same object id guess they would both be picked. You Can browse them using iid(number of selected instance after name)

    carn(0).uid = parent uid

    carn(1).uid = child uid

  • Cheers! Will definitely use the first bit for inheritance.

    The second bit returns some odd results for me - I think I need to look at how I'm spawning.

    The actual parent and child UIDs are 73 and 280, however I get the following:

    carn(0).uid = 5 (shrug)

    carn(1).uid = 73 (parent ID)

    carn(2).uid = 279 (child ID minus 1)

    Would UIDs typically be incremental (1,2,3,4...)?

  • Uids would be Id assigned at creation, its number assigned to every object at creation. Yes, incremental like you said, bit if you create object_rock and it gets uid 13, if next object created is object_tree it would get uid 14. So uids are not object specific but shared between. All objects.

    iids on other hand are ways to browse list of selected objects. If you have picked 5 tree objects you could refer each one with rock(0), rock(1) etc.

    In your case it seems that there are more than two objects selected. Try what this returns: carn(pickedcount-1).uid I imagine that might be the uid of the last selected object which should be the one created. :-)

  • Thanks once more. Definitely getting somewhere (and learning plenty). One remaining oddness I have is that carn.pickedcount = 1 for all instances, even though I have multiple instances in action. Occassionally I see it rise to 2 then immediately drop back to 1.

  • Object.Pickedcount gives you the amount of instances of the referenced object that are currently picked, meaning, how many instances of object your actions affect. With object.pickedcount 2, you currently have 2 objects picked and so doing 'object.variable = 1' would set that variable to 1 for both of those objects.

    If you are seeing pickedcount = 1, then you only have single instance of the object picked. Picking is the thing I had hardest time grasping with C2, it is really powerful tool when you learn to use it properly! :)

    Hope this helps, it's hard to say where the problem exactly is in your case without seeing the .capx of your project :)

  • You've been a great help!

    The spawn is created in a For Each loop so I guess it makes sense that pickedcount shows as 1. Where it spawns that must increase it to 2 until it passes through the loop and reverts to 1.

  • Just one other thing, is there a way to identify the total number of instances spawned for an object. If I can get the total number of IIDs, I can select the last one as the child and the penultimate one as the parent.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • instance.count seems the way to go.

  • Every object has object.count function which returns number of specific object instances in the game. So carn.count returns total number of carn instances in the game.

    You can use 'pick all' in system menu to pick every single instance of the object, then you could use 'pick nth' instance in system menu to pick object.count-1 to pick last (latest) instance of the object. Or which ever instance you desire.

    Hope this answers your question :)

  • Yes indeed!

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