Trouble With Classes
Hello! I'm currently working on a 2D Platform game, but I'm having some trouble with classes.
The main character in the game I'm making has 4 classes- one for the up sprite, down sprite, left sprite, and right sprite. I'm using keyboard functions to make my character move, but I'm running into some trouble.
For example, let's say I'm in the CharacterRight class. I also have a function in this class for if the keyboard.LEFT function, so that when the character goes left the sprites switch and it's not just the character's right sprite walking backwards.
The problem is that I'm trying to remove the child of CharacterRight while adding CharacterLeft, but I can't because the file gives me an error when I try and give the variations instance names. I'm assuming that you can't give instance names to symbols within their own class, but I'm still lost.
How can I make it so my character switches sprites if I can't remove/add children this way?
A lot of things here. First you can't instantiate a class in that same class constructor because you are entering in an eternal loop.
Second, it's not a good idea to add/remove stage objects from a class except the main game glass. You should add instances of all your movements in the main class for that purpose.
Third, I would suggest you to have all the character's moves in the same movieclip and then gotoAndPlay the right portion of the animation according the keyboard press. It's much more efficient that way reducing the load of adding/removing display objects on each move and let the garbage collector stay in peace for a while :)
Thanks for the suggestion and the help, that should be a much better way to work it.
|All times are GMT +1. The time now is 03:37 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.