Families / Create specific object type

0 favourites
  • 6 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hey guys,

    So I have this project on a chess board, Queens, Knights, Pawns etc.

    I created an event sheet that creates some queens dynamically, based on some global parameters (how many queens to create, where to place them etc).

    I created another event sheet that creates some pawns dynamically, based on global parameters, with IDENTICAL code, except for the object name, where I replaced Queen with Pawn.

    And so on for knight, bishop etc. All these Queen, Pawn, Knight etc belong to the ChessPieceFamily family.

    I thought it would be nice to use this Families feature instead of copy/pasting code around (and forgetting to modify in all places).

    I would like to have just ONE event sheet, which creates some ChessPieceFamily dynamically (using System->Create object), and based on some global variable I would tell it what exactly to create (pawn, queen etc).

    Is this possible? I.e. filtering just one of all the object types in a family when using System->Create Object on a family?

    Thanks a lot!

    Geo.

    PS: looking forward to family instance variables and family accessing object instance variables too <img src="smileys/smiley1.gif" border="0" align="middle" />

  • As a possibility, you can at the top of the event sheet, do a specific object spawn with a bunch of branching if statements for which object you want to spawn. After that, you can use events which act on the Family, however, as mentioned in the r75 event log, families do not support added behaviors, and instance variables.

    To get around this, you could have a single object called ChessPiece and have different animations each of which corresponds to a different piece, queen, king, rook, knight, bishop, and pawn. Then you can just set the appropriate animation, and use event conditions which compare against a pieces current animation.

  • Just use one sprite with all the different piece graphics in different animation frame. So when you want to create a specific piece, you create this sprite and you set the proper animation frame.

    Then you can differenciate each piece by its animation frame and apply custom rules on them (how they move, how they attack, promotion, etc.)

    Note that this way when you promote a pawn you really just change it's look.

    Also don't forget to set the animation speed to 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great, thanks guys, this approach seems to be working. It would have been nice to have kind of a Family Factory, but I guess this workaround will do just fine for now.

    I ran into another issue with event sheets, but that's a different topic...

    Thanks again!

  • If you pass a family to 'create object', it'll pick a random object type to create. Instead just create the actual object type you want to create! You can then pick it in the family by its UID.

  • Thanks Ashley. I was trying to write "generic" code, e.g. have an event sheet that creates a "family", and depending on where I include this event sheet (i.e. depending on some global variable I set previously), the CreateObject would choose a particular object type from the family. I mean, I was trying to avoid passing the actual object type (and have a lot of "if"s in the object sheet which does the creation).

    The approach/workaround suggested by cacotigon and Yann actually works. Plus, I found out today about the function plugin which greatly simplifies my work. Sure, it would be nice if I could somehow tell the CreateObject, when passing the Family, what object type I want (by passing some index, or some string perhaps, or by passing some ad-hoc "tag" that would be set on the object type when it gets added to the family). But for now I can live without <img src="smileys/smiley1.gif" border="0" align="middle" />

    Thanks.

    Geo

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