Hello, I have a working code with working sprites. But I'm trying to figure out how to make him stop moving when i don't hold down the key. Here is the code:
} else if (Key.isDown(Key.LEFT)) { gotoAndStop(2); _x -= walk;
That else is bad. This way going right is stronger than going left, for example if you are holding left and press right it will change direction, but if you're holding right and you press left it won't react. For the stopping problem, I'm not sure. What's the problem? When you press a key it sticks to the command?
yea, that was because it was as3 at first, cuz i always use external files and when I saw onclip event my poor tired brain associated it to as3's events.
I only gave code for an object because thats what he intends to do judging from the code he gave first, but yeah it can get very messy that way when you are dealing with lots of objects so it's better not to do that.
Also I use else often when the following code isn't necessary when the first condition is met, I can see how it might get confusing but I'm perfectly fine with it and I don't get confused that way but that's just me.
The thing with timeline coding is it gets really really long, as3 is much better because you can separate code into classes dunno if you can do that with as2.
one can use classes in AS2, but it's a bit more complicated actually, since the system was particularly intended for that type of work at the time (although was making that move) today, the system is based on a Class/Event model, which is much more powerful.
nothing wrong with the code above driejen - if/else is completely valid. although i often find now days that one runs into problems in 'capturing' all of the possible contingencies in this manner, because when you say: if(this) - else if(that) -else(other) you may have 'missed' the if(this & that) and it'll fall through to 'other' when that wasn't the intent - and part of the issue the OP has in this case
one other quick note: the use of booleans in that manner (as integers) works in 2, but will not in 3 as it is a stricter syntax - unless you use data type conversions: 'coercion' (implicit) or 'cast' (explicit) - as in:
I think you should set a jumpspeed var, subtract it from the y value, and decrease it a little in enterframe while he is in the air. this way the value will become negative and he will begin falling without a falling state. if you want to use a different animation for the faling youst play it if jumpspeed is negative.
right g - just like in 'real life' a gravity factor is good to give realism to the action - one way is to decrement the value on every frame by a factor, as in: