cacotigon's Recent Forum Activity

  • You can scratch 1 and 4, I went ahead and added them to the default Sprite plugin javascript so that I could make use of them in my projects. <img src="smileys/smiley4.gif" border="0" align="middle" />

    I guess Clone would be the singular most important feature out of these that I'd like to see in Construct. There's just not a clean way to implement something like this in Construct 2 through events, since we can't create/spawn by "string name".

  • I'm sure most of these are already in the "what I presume to be massive" suggestion box, but I thought I'd throw them out anyway:

    1. Family.ObjectName( Event/Expression) - Get the project-defined name of an object within a picked family list. If current Family SOL list is greater than one, it does the standard Construct 2 behavior which just returns the ObjectName of the first one in the currently picked Family set.

    2. Clone object (Action) - Copies all instance variables, position, etc. The only things that would be new would be UID and IID values.

    3. IsBehaviorActive (Event/Expression) - We can already disable/enable behaviors through events, it would be nice to also have a Platform.IsBehaviorEnabled/Bullet.IsBehaviorEnabled/etc (it would help save having to declare an instance variable)

    4. Sprite.HasAnimation(string animName) - Expression/Action - returns true/false as to whether an animation of some name exists for a given sprite. This would be an incredibly useful since I am frequently adding sprites with specific sets of animation names and have generic code to handle switching between them.

    And lastly I wish to impart my sincere appreciation for the work and care that has gone into Construct 2 in the first place!

    Thanks,

    -- Cacotigon

  • DevRaccoon:

    Prox is correct, your function signature parameter expects a *single UID* as its Param(0). When you use the obj_creature Is Active, you filter your SOL list to just that set of creatures, however, when referring to expressions such as obj_creature.X or obj_creature.UID, internally Construct has no idea which element in that array you're referring to, so it just picks the first obj_creature in the filtered picked list for that property. It doesn't pass that group of UIDs as a collection, it passes a single one to the Function, so you have to call the Function() *once* for each creature.

    That being said, in general, you want to do as much filtering as possible before the for-each call to optimize performance. Instead of iterating across the entire list of obj_creature and doing the "Active comparison" each time, it's better to pick/filter first, then use for-each:

    <img src="https://dl.dropboxusercontent.com/u/12667027/Construct%202/FunctionForEach.png" border="0" />

  • ChrisAlgoo

    You're very welcome. I also added a new section to the bottom of the tutorial where I discuss the performance aspects and advantages of Family to Family collision detection.

  • Animmaniac

    As I understand it, the way the engine is setup it can't really do a single nested loop for all collisions internally, because the user can setup all kinds of different collision detection wherever they want (even between events/actions that could change the positions of objects) in their event sheets.

    EDIT: Ignore this next paragraph, I'm clearly tired as this would very much *not* address the order problem that I just described, aka events which change positions of objects.

    (In order to do something like that, it would have to "read-ahead" for all possible collision checking events, aggregate them, filter for the distinct checks and remove duplicates, run the collision detection against this unique set, and finally store this in some kind of temporary Game Loop Cycle CollisionMap which any Collision events would just internally map against.) -- Bla bla bla

    EDIT: Resume reading here. :)

    Out of curiosity, I just did a profiling test of the two approaches:

    Object to Family

    Family to Family

    Family to Family is about ~1.5-2x times more performant.

    Benchmarking Capx

  • Animmaniac

    I'm sorry but it would increase the number of unnecessary checks, let's break it down item by item. Maybe if collision checks between objects were cached, but as Ashley has confirmed in a previous thread of mine, they are not.

    Let's say you have a family with three objects X, Y and Z, and one of each object in your layout.

    Using your system of checking object to family collision, you would have three events:

    X On Collision with Family: This would internally run two separate collision checks: X-Y and X-Z

    Y On Collision with Family: This would internally run two separate collision checks: Y-X and Y-Z

    Z On Collision with Family: This would internally run two separate collision checks: Z-X and Z-Y

    Making for a total of 6 collisions

    Not let's see what would happen if we used Family to Family collision:

    Family On Collision with Family:

    Checks X-Y, X-Z, Y-Z

    X-Y is the same as Y-X

    X-Z is the same as Z-X

    Y-Z is the same as X-Y

    So in your example, you perform 2x the number of collision checks. You can imagine that for 100s of objects in a game, this just wouldn't scale well.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Animmaniac

    Couple things.

    1. An overlap combined with trigger once is basically the same thing as an On collision.

    2. You would have to duplicate that collision event for every monster type in MonsterFamily if you wanted something similar to happen for each one. Granted, you can simplify the action component through a common function but still.

    3. To further elaborate on 2, ideally you want to consolidate collision checking into as few check events as possible to avoid unnecessary duplicate collision checking and keep things as performant as possible. Doing a Family check against Family allows us to reduce collision checking to a single event.

  • Hey guys,

    I've decided that this question is fairly important and hits a lot important concepts that are crucial to understanding how Construct 2 works, so I've written a tutorial to help explain:

    Understanding Picking with Respect to Families

    The tutorial not only covers how to distinguish between identical objects within single events, but why it's important from a modular design standpoint.

    Ashley, I'd love to get your feedback about it, particularly if I've made any mistakes in my explanations. <img src="smileys/smiley36.gif" border="0" align="middle">

    I hope this helps everybody.

  • ChrisAlgoo, I've noticed that this type of question seems to come up every once in a while on the forums, so I've written a tutorial to hopefully clarify the confusion.

    Understanding Picking with Respect to Families

    The tutorial not only covers how to distinguish between identical objects within single events, but why it's important from a modular design standpoint.

  • jayderyu

    That won't work. As Ashley has stated in the past, Indexing by IID is not limited to the SOL (list of selected objects).

    See my earlier response to this thread for workarounds.

  • TELLES0808

    I think that's a bit of a harsh assessment for GM.

    A lot of people who use GM "know how to code" as you've stated, but GM gives you a foundational framework so that you can focus on the unique aspects of coding your game. Frameworks like GM/Unity make it so we don't have to re-invent the wheel. We don't have to develop our own physics engine / scene graph / asset management system / map editor / etc.

    In the end, both are great tools, the choice of which one to use boils down to a couple factors for most people:

    1. What kind of coding environment are you more comfortable with

    (Scripting vs GUI Event system)

    2. What's your budget

    -- Construct 2 - $120.00

    -- Game Maker - If you want to develop for android/ios/ubuntu/windows 8/pc/etc for Game Maker, the Master Collection is what you want and costs $500. That being said, you can do a lot with the $50 dollar one as well.

    3. What kind of platforms do you want to develop for

    Great games can be made on both engines. For an interesting read on Game Maker (among other engines including Unity), see this:

    PC Gamer Indies Guide to Game Making

    Spelunky is a text-book example of an amazing game that was made using Game Maker. I used Game Maker extensively before migrating to Construct and can say that for the majority of users (especially the Construct 2 demograph), it has a much steeper learning curve. There's a lot less built-in behaviors/plugins and you have to do more actual "coding".

  • Ashley,

    EDIT: I just re-read your post in which you kind of address this potential solution. :p Sounds like as you've said, it might actually hurt performance.

    Thanks for your reply.

    What if you invalidated all cached Collision results for a given entity after any command which results in a change of position/angle/scale using some kind of HasChanged boolean?

    So maybe you have a central collision Cache which is an internal dictionary, it is only added to when two elements collide. The key represents the unique instance of the object, and the value is a enumerable list of elements that it has collided with on this loop cycle.

    CollisionMap[Obj1] = { Obj2 }; // set of objects Obj1 has collided with

    CollisionMap[Obj2] = { Obj1 }; // set of objects Obj2 has collided with

    So in the game loop:

    <font size="2">

    <font face="Verdana, Arial, Helvetica, sans-serif">

    Clear Collision Dictionary at beginning

    Set all objects HasChanged = false

    On Obj1 Collision Obj2 routine: (doesn't actually do any bound checking yet)

    Foreach(Obj1 in Layout)

    -- Foreach(Obj2 in Layout)

    -- -- If Obj1.HasModified = false && CollisionMap[Obj1].Value.Contains(Obj2) { TriggerCollision(); }

    -- -- Else { Run Normal collision bounding checks -- save results into CollisionMap }

    </font>

    </font>

    Would this help to optimize collision performance at all?

cacotigon's avatar

cacotigon

Member since 10 Mar, 2009

None one is following cacotigon yet!

Connect with cacotigon

Trophy Case

  • 15-Year Club
  • x2
    Coach One of your tutorials has over 1,000 readers
  • RTFM Read the fabulous manual
  • Email Verified

Progress

18/44
How to earn trophies