-
switch between walk, run, crawl, and creep.
Okay, I have a character I am coding for a platform game, all of my controls work except for the ones I listed above. By not working I mean they go to the frame but won't play the animation. The following code I have applied to the character:
Code:
if ( Key.isDown ( Key.LEFT)){
This.gotoAndStop ("walking");
_x -= power;
this. _xscale =100;
justPressedL = true;
} else if ( Key.isDown ( Key.RIGHT ) ) {
this.gotoAndStop ("walking");
_x+= power;
this._xscale =-100;
justPressedR = true;
}
if (! Key.isDown ( Key.LEFT ) and justPressedL == true ) {
this.gotoAndStop ("standing");
justPressedL = false;
} else if (! Key.isDown ( Key.RIGHT ) and justPressedR == true ) {
this.gotoAndStop ("standing");
justPressedR = false;
}
if ( Key.isDown ( Key.RIGHT )&& Key.isDown ( Key.SHIFT)){
this.gotoAndStop ("run");
_x += power;
_x += speed;
this. _xscale = -100;
}
If ( Key.isDown ( Key.LEFT)&& Key.isDown ( Key.SHIFT )){
this.gotoAndStop ("run");
_x -= power;
_x -= speed;
this._xscale = -100;
}
if ( Key.isDown (Key.LEFT) && Key.isDown ( Key.UP) || Key.isDown ( Key.RIGHT ) && (Key.isDown ( Key.UP)){
this.gotoAndStop ("creeping");
this.walking.enabled = false;
}
if ( Key.isDown ( Key.LEFT )&& Key.isDown ( Key.DOWN ) || Key.isDown ( Key.RIGHT) && Key.isDown ( Key.DOWN )){
this.gotoAndStop ("crawling");
this.walking.enabled = false;
}
I think my intent as to what I was trying to do is fairly evident with my code. The code is applied to my character movie clip and points to animations nested in movie clips on the character_mc timeline. My walking code plays perfectly, as for the others, they will go to the frame they are supposed to but won't play past the first frame. I believe that it has something to do with the fact that all of the animations rely on the arrow keys to steer them right and left and that flash is getting confused. Honestly, coming from someone who is on the brink of baldness after the stress of dealing with this issue for a week now, my hunches, if worth crakers, would make me a hippo. This is why I have brought this issue forth praying someone has a thought as to a solution. Any suggestions would be greatly appreciated.
-
.
Hi,
This is why it would be better if you can attach your *.fla so we can see the problems in action rather than trying to imagine it.
I would guess that you have a stop(); command on the first frame of each animation, so you tell the character to go to frame("run") for example, which it does then it doesnt run??
which suggests to me there is another stop(); somewhere.
-
Client Software Programmer
Hey fruitbeard I made you this, fruitbeard v2 xD http://i.imgur.com/dB4KIlh.png
-
I have uploaded my file below
Sorry, please forgive my reluctance to upload my file, I have nothing against it, I have just been wrestling with my computer which is blinded to my tablet which is debilitating when passing files to and from pc to tablet as my tablet is my only internet. Yes I am surrendering my pc to a technician next week. Anyhow, boring life story aside I have found a strange way to pass my fla. file to my tablet though when I tried to upload it here, I kept getting upload errors so I am sorry it is on an external site. You can download it here: http://www.megafileupload.com/amo/myproject.fla. I appreciate any help you can offer. Yes, before you judge my skill in flash is limited. Thanks again,
PS. I use cs4 for what it's worth.
-
.
Hi,
I had a quick look at your file and its simple case of too many conflicting key press / non press values. making things stay where they are.
There is too much going on for me to help you
-
.
Hi,
Mess around with this, its not completely fixed but neither is your file fully done.
I hope it will make it easier for you.
just swap the code for this and tweak/add whatever you want
PHP Code:
onClipEvent (load) { var speed = 6; var isJumping = false; var jumpSpeed = 0; var startY = _y; var ground:MovieClip = _root.ground; var grav:Number = 0; var gravity:Number = 2; var speed:Number = 15; var maxJump:Number = -12; var touchingGround:Boolean = false; var standing:Boolean = true; var keysDown:Boolean = false; var timer:Number = 0; var CheckJump:Boolean = false; _global.EndJump = true; _global.PlayMovieClip = true; _global.CharacterPunch = true; } onClipEvent (enterFrame) {
// ENERGY _y += grav; grav += gravity; while (ground.hitTest(_x, _y, true)) { _y -= gravity; grav = 0; touchingGround = true; }
if (Key.isDown(Key.SHIFT)) { if (energy > 0) { trace(energy); energy = 150; i = energy -= 6; power = 8; } if (Key.isDown(Key.LEFT)) { this.gotoAndStop("run"); _x -= power; _x -= speed; this._xscale = 100; } if (Key.isDown(Key.RIGHT)) { this.gotoAndStop("run"); _x += power; _x += speed; this._xscale = -100; } } else { energy += 2; power = 3; _root.vcam.energyBar.currentFrame = (energy); if (energy > 150) { energy = 150; } //if (energy == 0) { //break; }
// GRAVITY CONTROLS if (Key.isDown(Key.SPACE)) { if (touchingGround) { grav = maxJump; trace("Jumpimg"); toucingGround = false; }
if (Key.isDown(Key.LEFT)) { _x -= speed; this._xscale = 100; }
if (Key.isDown(Key.RIGHT)) { _x += speed; this._xscale = -100; }
if (_global.EndJump && (timer == 0) && _global.PlayMovieClip == true) { _global.PlayMovieClip = false; _global.EndJump = false; _global.CharacterJump = true; this.gotoAndStop("jump"); isJumping = true; jumpSpeed = -5; speed = 6; timer = 0; timer++; countupInterval = setInterval(countup, 1000); } else if (timer > 0) { break; } }
if (Key.isDown(Key.SPACE)) { if (Key.isDown(Key.LEFT)) { this.gotoAndStop("walking"); _x -= power; this._xscale = 100; justPressedL = true; }
if (Key.isDown(Key.RIGHT)) { this.gotoAndStop("walking"); _x += power; this._xscale = -100; justPressedR = true; } } // LEFT WALK if (Key.isDown(Key.LEFT)) { if (!justPressedL) { this.gotoAndStop("walking"); this._xscale = 100; justPressedL = true; } } // RIGHT WALK if (Key.isDown(Key.RIGHT)) { if (!justPressedR) { this.gotoAndStop("walking"); this._xscale = -100; justPressedR = true; } } // CRAWLING if (Key.isDown(Key.DOWN)) { if (Key.isDown(Key.LEFT)) { this.gotoAndStop("crawl"); this._xscale = 100; justPressedDucking = false; } else if (Key.isDown(Key.RIGHT)) { this.gotoAndStop("crawl"); this._xscale = -100; justPressedDucking = false; } else { this.gotoAndStop("ducking"); justPressedDucking = true; } } // CREEPING if (Key.isDown(Key.UP)) { if (Key.isDown(Key.LEFT)) { this.gotoAndStop("creeping"); this._xscale = 100; } if (Key.isDown(Key.RIGHT)) { this.gotoAndStop("creeping"); this._xscale = -100; } } // GROUND STUFF if (ground.hitTest(_x + (_width / 2), _y - (_height / 2), true)) { _x -= speed; trace("a"); } if (ground.hitTest(_x - (_width / 2), _y - (_height / 2), true)) { _x += speed; trace("b"); } if (ground.hitTest(_x, _y - (height), true)) { grav = 3; trace("c"); } // JUMPING if (isJumping) { _y += jumpSpeed; jumpSpeed += 1; if (_y >= startY) { _y = startY; isJumping = false; speed = 6; } } // PUNCHING if (Key.isDown(Key.ENTER) && _global.PlayMovieClip == true) { //_global.PlayMovieClip = false; //_global.CharacterPunch = true; this.gotoAndStop("fists"); } // AXE if (Key.isDown(Key.CONTROL) && _global.PlayMovieClip == true) { //_global.PlayMovieClip = true; //_global.CharacterAxe = true; this.gotoAndStop("axe"); } // BOW if (Key.isDown(Key.ALT) && _global.PlayMovieClip == true) { //_global.PlayMovieClip = true; //_global.CharacterBow = true; this.gotoAndStop("bow"); } }
/////////////////////////////////////ON KEY UP EVENT///////////////////////////////////////// onClipEvent (keyUp) { this.gotoAndStop("standing"); justPressedL = false; justPressedR = false; if (!Key.isDown(Key.SPACE)) { clearInterval(countupInterval); timer = 0; _global.EndJump = true; } }
obviously make a copy of your file if you need to revert, as there are still a few conflicting things going on
Last edited by fruitbeard; 04-03-2015 at 11:39 AM.
-
Bless you fruitbeard. I can't even put it in words how grateful I am you are a god send. As for tge tweaks I usually do that anyways. When I first started I tried to calm my unease at the unfamiliarity of the code by saying I will just copy sample codes until I figure stuff out. By day two, I was already rebuilding the code bottom up, but hey, it is an excellent learning experience. Two weeks later here you find me blessing you to China and back for you talent and wisdom... I could kiss your shoe as I bow before you. No I have always saved when something worked as to have a fall back 'cause I always seem to muck things up. You take care and bless you for all you have done.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|