One Object Type to rule them all... or not?

0 favourites
  • 13 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Sorry for the title but i had to do it..

    By now most of you surely had to choose how to create many different enemies, characters, items, etc.

    As i saw so far there's two main ways of doing it, take enemies as instance:

    First Way: You create an individual "Object Type" (sprite) for each enemy. Then you play with instances of these many object types.

    Second Way: You create only one general/abstract "enemy" object type and then you individualize each enemy as different animations or animation frames of this general object type.

    For example, you create an Object Type "EasyEnemies". Then from animation frame 0 to 6 you add all animations of enemy "spider". From frame 7 to 10 you add all animations for enemy "skeleton" and so for.

    Then you spawn instances of this single object type at the frame that reference the enemy you want to spawn.

    This second way is widely used in many tutorials and examples in C2.

    For certain objects/sprites, like statics scenery, looks like a good way to go. Frame 0 is a rock, frame 1 is a tree, and it's easy to reference and spawn each sprite/object like this.

    But what about complex objects/sprites, like enemies, or say, 7 player's characters?

    If i add all enemies sprites in a single object type i would get a very "heavy" object loaded into memory, increasing loading time and, most likely, i could just want 6 of 20 enemies encapsulated in this single object type or "animation frame"method.

    For all those 20 enemies as a single object type there's also each individual animation. And fear arise...

    It terrifies me to go this second way for complex objects/sprites if i have to load and keep into memory so many sprites that i could or could not need in a certain moment or level. However i keep seeing people using this method for everything, from rocks and trees to all enemies and player's characters. So i'm starting to think that i'm missing something or i'm misunderstanding something.

    Sorry for the wall of text but this is a major grey area that i never solved and never get enough info to feel safe using it freely.

    Tell me your story, it will help me a lot! One Object type for many "enemies" or better keep'em separated each in it own object type and start developing the damn game?

    Thanks dudes (and dudas).

  • for enemies i would recommend useing a family and make all enemie style a own sprite.

    You can than make every option to the family and it will change for all enemies, you can set the strenght of an enemy just in it instances variables.

    adding a animation with different images just makes sense in my opinon if you have for an example the same rock with different colors from purple to yellow or something.

    Its very easy to work with but makes your sprite senseless big if you use 1 sprite for everything and will slow your game down.

    I used this methode in a game where something just change its skin if the player gets leveled up, so i packed every skin in 1 sprite and made "set frame to level", its very lazy and makes my code smaller. But i know that it wound effect a lot in my game that i am makeing right now because it has no moveing elements and will hopefully dont make any lags.

  • Thanks EyeForcz - So it's not that crazy to keep using a 1:1 enemy:object type at least for enemies and complex multi-animation heavy sprites. I'm ok using one object type for all, lets say, 1 frame static colliders. Each frame being a different object (tree, rock, pillar, etc).

    And for more complex objects i keep them each in it's own object type, maybe using the frame technique for evolved forms of the same sprite, like weak spider (green), strong spider (red). Being from frame 0 to 10 reserved to the green weak spider and from 11 to 21 reseved to the red spider (evolution through instance variables/array).

    Someone else found that using a single big object type (sprite) worth all possible dangers against using individual object types per sprite? I'm spinning in my axis for more stories!!

    Wicked combinations of families, arrays, containers, whatever are welcome.

  • Bumping for more opinions...

    One big "Sprite" Object Type as container of many enemies/characters (with its own animations for each) accessed each by animation frames references or keep'em each in it own Object Type and don't call for unnecesary problems?

    I see this one object type for all method, for example, in Kyatric's "myMiniRpg" capx example and many other popular examples and tutorials. If they choose that method, maybe there's a reason why... or maybe was chosen because those examples were just quick examples without enough enemy types/animations... I don't know..

    Please, if you evere used a big single Sprite Object Type containing all or many enemy types (spiders, skeletons, werewolves, etc) and found it worth it agains using a single object for each enemy please tell your experience. (Enemies just as an example).

    Thanks!

  • I'm kind of dying here...

    Question:

    There's a clean way to manage an array without using the "animation frame" or "animation state" method as a reference to the array index?

    I'm struggling because that method doesn't scale well when there's many, say, monsters stored in the array, each with it's own set of animations.

    It force me to keep a single big "object type" as a container of all monsters with all their animations in memory. I use them all or not (monsters is just an example of something stored in the array).

    I'm trying to use arrays in conjunction with a Family (monsters) or with individual object types per monster so to keep memory low and to keep animation states cleaner for each monster.

    Question again:

    Someone ever used another method than the commonly used "animation frame = array index"? Or ever used it with a big array of objects with many animations (for instance, 200 monsters with 4 animations states each)?

    It blows my mind trying to scale Construct 2 to handle many enemies stored in an array while keeping them in their own object type.

    Please help and thanks in advance!

  • Are you finding problems using the object-type-per-enemy method? Coupled with good use of Families I think it is easier to think about. Maybe share what you have done, at least in concept.

  • Could you explain why you want all your enemies grouped into the same object type? That sounds like it'd be a nightmare to code... It's much less complicated to just use multiple object types and put them all into a family.

  • Hello to all.

    If you look around the many tutorials and capx examples about arrays you most likely saw a method were a single sprite object loads all monsters types sprites (just an example) and use their animation frames to reference each monster that should take data from the array.

    I want to avoid that method, at least, for complex objects like enemies. But all examples use this animation frame method and i get stuck eventually.

    There's a popular array example made by Kyatric explaining arrays and how to loop through it (it's called MyMiniRPG.capx) and use the animation frame method.

    I want to convert that example to use individual object types per monster grouped in a family (families could be avoided for now if you want) but i can't grasp the right method.

    Let's say we have a 2d array of 50 monsters, X reference the index of each monster and Y reference each attribute of each monster.

    Now we create each monster as a separate object type with instance variables to load and save data taken from the array (Or use a "Monsters" family instance variables).

    Now imagine some kind of spawner object in the level spawning random monsters using the array data to "fill" each monster instance variables giving each one their particular attributes.

    How should i proceed without looping the array using animation frames as reference? I don't supposed to know the exact x (index) position of a particular monster in the array so i have to relay on loopindex somehow.

    Did you ever used arrays to load data to an object type looping the indexes without relying in the animation frame method?

    I can't give a .capx file because there's nothing until you take data from the array. But below i leave Kyatric's example, if you can do the same he did but using individual object types per monster and a different looping method i will be saved. Or point me some directions and i will follow from there.

    Link to Kyatric's array example:

    http://www.scirra.com/forum/forum_posts.asp?TID=48528&PID=305024&title=rpg-problem#305024

    Thanks folks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just have an ID value for each monster type. This can be your index into an array. edit: the problem is with spawning. I guess you could 'cheat' and use the 'nickname' plugin to spawn based on monster name from the array.

    edit2: try this. Without nickname plugin. Uses a Family and separate objects, with the same array and other code structure.

  • Oh man, I've never seen that nickname plugin before. rexrainbow you're a goddam rock star

  • Amazing codah ! Exactly what i was looking for! You used Families and individual Object Types! I now have both methods at my disposal! I'm breaking my exclamation key!

    I believe this deserve an entire tutorial on arrays just to add this method to the more popular "single object type / animation frame" method. Once I understand how SOL choose each monster in the family i will try to create a tutorial around your example.

    Thanks you very much again Codah, you solved a big issue i had from the beginning of time and by itslef this example is a powefull template of a complete RPG / Any Game cycle.

    Of course thanks to you Kyatric for creating the original example wich, beyond my bitching, actually shows the best way to go for non heavily animated objects, like inventory items, shops, level editors, etc. (I'm on your "How to Code Monster Loot Drops" this days).

    Thanks you very very much to both of you!

  • Amazing codah ! Exactly what i was looking for! You used Families and individual Object Types! I now have both methods at my disposal! I'm breaking my exclamation key!

    I believe this deserve an entire tutorial on arrays just to add this method to the more popular "single object type / animation frame" method. Once I understand how SOL choose each monster in the family i will try to create a tutorial around your example.

    Thanks you very much again Codah, you solved a big issue i had from the beginning of time and by itslef this example is a powefull template of a complete RPG / Any Game cycle.

    Of course thanks to you Kyatric for creating the original example wich, beyond my bitching, actually shows the best way to go for non heavily animated objects, like inventory items, shops, level editors, etc. (I'm on your "How to Code Monster Loot Drops" this days).

    Thanks you very very much to both of you!

    No worries. I guess you've seen the tiny 'gotcha' (not really, just some boilerplate stuff) hidden away in the Group, and that you're ok with it. i.e. an On Create for each monster type... It's not that bad and once done, it's set and forget.

  • Your "gotcha" solution is a trade off that i don't see as a bad thing. Trying to figure out how to solve my problem i get back to Game Maker (and a little of Unity) to see how those engines use arrays in similar cases. It's impressive how easy is to get into a mess of code and, worst, how easy is to fall into logic bugs that are so much difficult to see in the mess of code. Going back to Construct 2 is like a shower after a fall into a mud hole.

    Going from code to C2 kind of visual programming lift many barriers but also makes a little confusing some aspect of game programming where there's too much of "real programming" involved (like arrays). Usualy you can look into other's code but since C2 is unique you can get stuck for longer trying to "translate" a complex process from coding to visual representations of events.

    Again your solution on the "On Create" group is pretty much needed. I don't see a better way so far.

    Time to roll this array this thing into my prototype and see how it goes.

    See you Codah! Thanks for your help.

    But, there's a trade off and, to me, unless i get seriusly stuck like in this case, it's far wort it. C2 eventually is capable of doing anything code can do. I guess that, with arrays solved, there's no more barriers to overcome.

    I really want to make your example more visible to everyone so i hopefully will be able to make a tutorial out of it. As long as Kyatric let me use his example as the template.

    Thanks again Codah.

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