Evening, all! I do believe this is my first forum post. Been at C2 for a little while now, and I've been able to accomplish a lot. That said, I'm bringing up a suggestion that I've seen visited a few time in the past (for instance,
--Pardon the lack of a link, still new in the forums so the rep is low).
I'd like to have the ability to dynamically create an object, such as a sprite (though I bet other items such as arrays would benefit from this as well) by checking a variable as opposed to clicking to select it each time. It would serve many purposes that aren't possible without the functionality.
For example: let's imagine a game like Castlevania, SotN. Items may be equipped in either right or left hand, and activated by that button. There are many, many items, and each one holds a fair amount of animation --especially if (unlike SotN swords) you plan to have the equipped item always visible, even when not in use. This means additional animations for walking, jumping, crouching, etc.
The most prescribed method is creating a single sprite object, and creating many animation cycles/frames. This has a number of drawbacks. For one (and this may only apply games containing many items with high res sprites) it goes against best practices as I've come to understand them from a lot of time in tuts. Large spritesheets can cause the loading bar at launch to hang for a bit, then suddenly jump. Occasionally, this can cause a player to think their game has locked up before it's loaded. It may seem Trivial, but it has been suggested that while using spritesheets to cover multiple objects is helpful, it can be overdone.
Secondly, it can quickly become difficult to organize and keep track of player equipment, and lacks automation. Instead of storing your object variables neatly inside their instances, you will need to create separate arrays. Now, while I do love arrays, I think many people will agree that after a certain size they can be difficult to keep track of without separate references outside of the program, like a list or spreadsheet to track object IDs (unless you're good at remembering that "Epic Chicken Slicer Sword of Justice" has an object ID of 73.
Then there's the fact that the sprite can quickly become cluttered with animations. You're loading all of them each time, despite not needing most of them, and tracking them is even more difficult.
Heaven forbid you accidentally apply an image point change to all animations while tired. That can lead to a lot of repair work if not caught immediately.
Consider this:
On equipping an object, a variable is set. We'll say it's the right hand, and call our variable EquipRightHand. Perhaps it's global, or perhaps it's a player instance variable. Let's say you equipped a rapier. The method of equipping isn't important in this example. The result is: set EquipRightHand:EquippedObject. Variable becomes EquipRightHand:WeaponRapier
Now, with one action in the same event, we create new object: Sprite.EquipRightHand at the player's position.
Additionally, if the animation names and origin points of the objects are set to match the player's, you could set every weapon/item sprite to mimic the player's position, animation and frame in one event and have every other object line up from that point on. If the player's animation frame is PlayerWalk02, the Rapier (also at PlayerWalk02) will line up perfectly on top of the player. Change the EquipRightHand variable to Scimitar, and your work is already done, provided the Scimitar's animation names and image points line up. Imagine the amount of animation you would need in one sprite if you did this via frames, and the amount of array reference you could avoid otherwise.
The only other way to avoid a single, very large sprite sheet, as I understand, is to create many, many different events for each object, resulting in a lot of code. (IE: If WeaponEquip:"WeaponRapier", then DoSomeAction. If WeaponEquip:"WeaponScimitar", then DoSomeAction.) For this example, I'm not taking into account plugins, which are useful, but may depreciate as C2 evolves. Also, I love to see how much functionality I can squeeze out of anything in vanilla flavor.
I realize this has been brought up and dismissed before, but I feel the usefulness of this proposed function is there. I use strings all over the place for dynamic coding, and this is one place I am sorely missing that functionality.
One thing I've learned over the years, whether it's code, music, Photoshop, etc. is that everyone has a different method to get from A to B, and there's always something you can learn from someone else. I'd love to see how others accomplish what I'm talking about in a way we maybe haven't considered.
I hope I haven't lost you with the long post!
Thoughts?