0 Favourites

[SOLVED] Pick spawned sprite

This forum is currently in read-only mode.
  • hello people, i'm new here :D i'm experimenting with this great tool, but i'm stuck :( my problem is pretty basic, but i can't find the solution, even after reading some tutorials (although they were for Construct 2). I don't know how to pick a sprite I just created. I read that in Construct 2, spawned sprites can be used in any sub-event or events in the same level, but in Construct Classic I don't know how it works :s I did this:

    For each Player:

          Player 'SpriteID' equal to 0: Player - Spawn Object Sprite5

                                        Player - Set 'SpriteID' to Sprite5.UID

          

          Sprite5 Unique ID is

          Player.Value('SpriteID'):      Sprite5 - Set XY to player.XY

    it spawns one Sprite5 for every Player in layout, but one of them keeps spawning Sprite5's every tick. Also, Sprite5's spawned through the editor dissapear, so i guess that it's affecting every Sprite5, not only the spawned ones

    What i want to do is to spawn one Sprite5 for every Player, then set Player.SpriteID = Sprite5.UID, and move all the Sprite5 to the corresponding Player in every tick.

    i'm probably doing everything wrong :P can you help me?

    sorry for my bad english

  • when objects are in a container they don't need to be spawned, just spawning the 1 object that the other is linked too will create the seconded object.

    further more, since the objects are in a container, construct already assumes you want that object whenever the first object is in the event.

    so to fix:

    you only need 1 event,

    #3: always set sprite 5 x.y. to player x.y.

    that's it...

    delete the rest. (except 1 & 2 )

    and don't worry about creating a sprite 5 for each player in the editor, it automatically dose that for you.

  • I just noticed that both sprites were already in a container, that's why it wasn't working XD that method with containers works well in this case, but is not very practical when you have 2 or more sprites to spawn. Anyway, if I don't put them in a container, it correctly picks the last spawned sprite. In fact, the container was the problem. Thank you for the help :D

    also, I uploaded the wrong cap file D:

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • "I uploaded the wrong cap file D:"

    ha nice :)

    -----------------------------------------------------------------------

    if your going the rout of manual picking, the key is for each loops,if you hit a road block,just keep playing around with those.

    and when your trying to find a object with the uid as a value, make sure you use:

    ( the object with the value of the UID)= picker

    ( the object that the UID belongs to)= object

    for each picker:

          -object UID = picker value ,UID'

    if you do it the other way:

    For each object

         -picker value 'UID' = object UID

    It won't work unless you also For each the pickers

    and that's 2X as slow to process.

    ---------------------------------------------------------------------

    Some other methods that are useful. In particular for picking the same kind of object as the one doing the picking:

    _______________

    Using functions:

    add the .x and .y of an object as a parameter

    call a function forgetting objects

    on function:

    set other objects value 'target x' and 'target y' to parameter .x and .y

    ______________

    Using arrays:

    set each object value 'AX' and 'AY' to a unique position in an array.

    and do all your comparisons based of the array positions, not the objects themselves.

    ---------------------------------------------------------------------       

    like i said, these are only really necessary for picking the same object. i know that's not what your doing right now, but it think everybody at some point gets headaches over this problem.

  • This is what i did:

    <img src="http://www.freeimagehosting.net/newuploads/ztlua.jpg" border="0" />

    Not the most efficient way, but it works :P I have a bit of experience in other game making programs, like GM, but seems that construct does a lot of work for you, and sometimes simple things become confusing. But I like that I can make basic games really fast, so I'll keep experimenting :B

    The arrays method seems a bit more complicated, because I have to keep track of the array positions. I'll take a look later...

    Thank you again Bartosh :)

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