How do I spawn a particular Family member

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • So I want to do something simple with Families, but don't seem to understand how. Lets say I have a Sprite family called Fruit_Family, and it's full of sprites like Apple, Banana, Orange, etc. So I write an event similar as follows:

    On Click of Fruit_Family: Spawn Fruit_Family at point X,Y

    Now, what I intend is for the specific fruit being clicked to be what's spawned at the given point. However, Spawning from a family seems to just spawn a random member of that family instead. Is there any way to write this event so it will spawn another of the particular family member I've clicked?

  • you could use: on click on sprite"Apple": spawn sprite "Apple" at point x,y (and the same for the other member)

    or

    add instance text variable to your "Fruit_Family" (eg "type") and set the instance var "type"= "Apple" for apple sprite, "type" ="Orange" for orange sprite etc

    on click on Fruit_Family

    ---Fruit_Family.type="Apple": spawn sprite apple at point x,y

    ---Fruit_Family.type="Orange": spawn sprite Orange at point x,y

    --- etc

    or you can play with the rex nickname plugin

  • The first two solutions seem to be functionally identical, in as much as I'd end up having to hard-code a different event/sub-event for each different fruit to spawn. Since I don't necessarily know how many different fruit I'll end up with, though, I was hoping for a cleaner solution, like making it all into one big event that covers any possible types. The Identifying variable seems like it'd be a step in the right direction, if I could spawn a specific object based on that variable, without having to create a separate conditional for each object.

  • If you want an individual object to spawn, then just spawn that object, not the family.

    If you need to compare Apple, don't compare the fruit family, compare the apple.

    At some point you are going to have to determine what you picked. At that point you are going to have to Compare a variable, or the actual object. There is no way that I know of to return the object that was clicked without a bunch of If than statements.

    MadSpy has the solutions for you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not solved at all. The proposition seems to suit any needs.

    Do you find any solution yet Rex ?

  • Not solved at all. The proposition seems to suit any needs.

    Do you find any solution yet Rex ?

    Doesn't seem possible in the way I described within Construct 2, unfortunately. Families don't seem to allow for it. The complicated workaround I ended up with was to have one Universal_Prop_Object that serves as all the various things fruits, and changes properties relative to a spreadsheet based on an Item_Name variable assigned at spawn. More complicated than I was hoping, but easily extensible for various item/fruit types, which was the main thing I was looking for.

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