1st POST...
hi, i'm trying to create a game (duh) but i'm already hitting some problems rite at the start. I'm just starting to learn flash so forgive me. I'll first show you the code below.
i'm just testing out the code first so this ain't the real thing. this code is on a movieclip called "ball". within the ball clip i have 3 layers, one for code one for labels and one to change the look of the clip when the arrow keys are pressed. the jumping code i got from somewhere else and tried to adapt it to suit me.Code:onClipEvent (load) {startspeed = 10; gravity = 10.8; jumping = 0; speed = 6; } onClipEvent (enterFrame) { if (this.speed < 0) {this.gotoAndStop("still"); } else if(Key.isDown(Key.RIGHT)) {this._x += speed; this.gotoAndStop("right"); } else if(Key.isDown(Key.LEFT)) {this._x -= speed; this.gotoAndStop("left"); } else if(Key.isDown(Key.UP)and jumping==0) {jumping = 1; starttime = getTimer()/1000; startposition = _y; this.gotoAndStop("jump") } if (jumping==1) { time = getTimer()/1000-starttime; _y = _y-(startspeed-gravity*time); if (_y>startposition) { _y = startposition; jumping = 0; } } else {this.gotoAndStop("still") } }
On the root scene i have two layers one for the ball and one with code that is "jumping = 0". Now the ball move when i use the arrows and it also jumps but when you press an arrow key and then nothing else the look will stay the same(e.g. if i press right and then leave it it will stay on the frame that make it look going right)
The problem it that it doesn't go back to it's original look of being still when no other keys are pressed. I just added the bottom else bit to show you the code for it to go back to original state. If i don't have this code the ball will change appearence but if i have this code the it will stay like a circle but when you jump and press left or right it changes.
+Hopefully u understood this
*is there any easier way to code it to jump
*If anyone could please help me i woule be very greatful
*if you didn't understand anything please tell me
THANK YOU