Reposition object to a stored object's UID

Get help using Construct 2

Post » Fri Feb 10, 2012 12:30 am

The way i did it in game maker was to spawn the object, while storing its id. Example "mycap = instance_create(x, y, obj_cap);" then i just told the spawner object to reposition the cap to its x, y, using the mycap reference. "mycap.x = spawner.x; mycap.y = spawner.y;"
This process was strait forward for me.

In C2, i tried this by putting a variable in the spawner object, then did this condition "if spawner.myobj == 0 > spawn cap object > store spawner UID in cap object's variable > set spawner.myobj to 1" so it only triggers once.

then in every tick, i tried to set the caps position to the stored id like so "set position to self.storedid, self.storeid"

Didn't seem to work. What is one way to achieve this? Thanks for the help.

Also, there is no real in depth tutorials on varies uses of UID/IID in the manual or tutorial section, so i just been trying to guess it with no luck.
B
50
S
11
G
7
Posts: 274
Reputation: 8,146

Post » Fri Feb 10, 2012 6:33 am

I think you might be overcomplicating things, this is much simpler:
(Spawner.myobj == 0)
     Spawner.myobj = 1
     Spawner.Spawn Object (child_obj)
     child_obj set position to Spawner.X Spawner.Y

That will do it immediately, however, Sprite.Spawn method can create an object located at an image point or origin, so it should already be "on top" of the Spawner so to speak.

Secondly, why would you need "on tick"? Unless the spawner is moving around, it's going to repeatedly set the child_obj's position to the same coordinates.

Let's assume for a moment that the Spawner does move around, you could just pin the child object:
#1: Add Pin behavior to the child object and pin the child object to the Spawner right after the Spawner.Spawn child_obj call.


Here is how to use a stored UID's sprite's properties (you have to use Sprite.Pick call)
#2: If you want to set child_obj to obj_parent's coordinates, but you only have obj_parent's uid value, then you need to do this:

Pick(instance of obj_parent where UID = obj_parent)
     child_obj.Set position( obj_parent.X, obj_parent.Y )

See here for tutorials on picking:
http://www.scirra.com/forum/how-do-ifrequently-asked-questions_topic45416.html

Hope this helps,
-- cacotigon
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Fri Feb 10, 2012 1:55 pm

"cap = 0 > cap = 1 > spawn cap > pin to spawner" That seems to work great. I guess i didn't need to reposition it. Thanks for the help! 8)
B
50
S
11
G
7
Posts: 274
Reputation: 8,146


Return to How do I....?

Who is online

Users browsing this forum: MarkThomas and 0 guests