[SOLVED]Spawn instances of spr from same spr

Get help using Construct 2

Post » Mon Feb 04, 2013 11:16 pm

@Alcemon - i think i get it now, you want a sprite to "clone" itself and be the one spawning the other sprites instead of a system event?

the difference i'm seeing here is, correct me if i misunderstood is, the system - create object > correctly picks and sets the instance variable
whereas - sprite - spawn another object - sets the instance variable to 0?

it also seems to multiply the pieces variable - which is really odd - making the spawn loop function incorrectly.

i have made a new example on how to fix this, add an "on created" condition and move the set spriteID action to this condition, seems to work correctly.
updated instance chain (r117)
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Tue Feb 05, 2013 3:52 pm

@wretchedshark, thanks again for the reply. We are getting close to the issue :)

Now, try to make each sprite to spawn exactly to the right of the previous sprite (spawning in the predefined image point 2).

To top everything make sure to alternate the use of the animation "clone" in such way that:
-the first spawned is using the Default animation
-the second spawned is using the clone animation
-the third spawned is again using the Default animation, and so on

This should not be possible without setting up information of the sprites immediately after the spawn (which is apparently not possible in Construct2 if the spawning sprite is the same as the sprite being spawned).
B
19
S
4
G
4
Posts: 70
Reputation: 3,896

Post » Tue Feb 05, 2013 4:45 pm

[QUOTE=Alcemon]
This should not be possible without setting up information of the sprites immediately after the spawn (which is apparently not possible in Construct2 if the spawning sprite is the same as the sprite being spawned).[/QUOTE]

It is possible, you could do it by varying this example a little bit:

Snake demo

Most of the example is not by me, only the few fixes. Check the final events for spawning and setting the sprite positions in events above. The point here is: divide your problem to few small, simple functions. :)

Solving your problem here could be done by applying approach taken there.vee412013-02-05 16:47:08
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Tue Feb 05, 2013 6:20 pm

@vee41 Thanks for the tip. Basically this is using a global variables; (loopIndex and LastBodyUID) to help up picking and putting information into each of the instances.

This also could work as an even better work-around to the one I linked but the truth is that it is still not possible to pick the created sprite when the spawning/creating command is done from another instance of the same sprite.

Hmm...maybe both instances are picked (creator and created) and it's necessary to use 'Pick nth instance' before using it. I will try that right now and report the results.

**UPDATE** Sorry, no luck, pick nth instance doesn't seem to help in this case.Alcemon2013-02-05 18:35:21
B
19
S
4
G
4
Posts: 70
Reputation: 3,896

Post » Tue Feb 05, 2013 7:28 pm

When an object is created it becomes the only instance of that type that is picked. Once it is no longer picked it cannot be picked until the next top level event.

Some more info:
http://www.scirra.com/forum/picking-problem_topic41776_post257714.html#257714
http://www.scirra.com/forum/r102-breaking-change-questions_topic56576_post352637.html#352637

The way I'd do it is create the 5 sprites in one event then position them in the next.
http://dl.dropbox.com/u/5426011/examples16/create5.capx
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Feb 05, 2013 7:57 pm

@Alcemon - i am curious as to why is it important to spawn them FROM the "default" sprite. why not just spawn them using the system event and then position them according to where the default sprite is spawned?

it seems a lot less finicky using "system - create object" rather than "sprite - spawn another object", is there a particular reason you want the sprite to spawn the clones?wretchedshark2013-02-05 19:57:25
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Tue Feb 05, 2013 9:57 pm

@R0J0hound thanks for your answer. I initially thought it answered everything but I did find an inconsistency that I wanted to address.

Please look at the following snippet(sorry, I could not direct embed from a google drive image)
https://docs.google.com/file/d/0B20uobjbjbtgS2tjX25TTTZPOG8/view

The scoping rules that you mention in your two links are not breached. And yet it does not work as it should, as running that code would spawn infinite instances of Sprite1 as opposed to only 2.

@wretchedshark currently the thread is not so much about "getting something done in any way" (which in hindsight, WOULD be the objective of the "how do I do..." subforum). Many of the proposed solutions in the thread already answer the original question.

It is more about finding an explanation for a C2 behavior I did not not anticipate or understand (as maybe it is known limitation, bug?).
B
19
S
4
G
4
Posts: 70
Reputation: 3,896

Post » Tue Feb 05, 2013 10:13 pm

Now I see the problem, it's a bug, spawn doesn't pick the new object.

The workaround would be to use the System->Create action instead of Sprite->Spawn. For the position use Sprite.ImagePointX(2) and Sprite.ImagePointY(2).
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Feb 05, 2013 10:14 pm

@Alcemon - ah i see, then i think it is simply a case of how the function in the program handle things

system - create - each sprite can be set and individual instance variable while the spawning is happening

sprite - spawn object - setting variables while spawning keeps the original sprites values (in my experience)

you can do a workaround to get the desired behaviour (using system) or you can use a workaround inside of using sprite - spawn another object.

this seems handy in that say you have an enemy you could have it spawn direct clones (using sprite spawn another object) or have it spawn weaker clones (using system and setting its health variable or defense etc).

i will have a look again later and look for more ways to accomplish what you are hoping to achieve within sprite spawning another object
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Tue Feb 05, 2013 11:41 pm

'System: Create Sprite' picks the newly created Sprite.

'Sprite: Spawn Sprite' doesn't pick the new Sprite - the original one remains picked.ramones2013-02-05 23:41:26
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, abdalghani, Ethan, Marxally, Naightwolf and 27 guests