Reposition object to a stored object's UID

0 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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:

    Hope this helps,

    -- cacotigon

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

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