|
-
Senior Member
[help] if (Key.isDown HELP!!!!
here is my code
Code:
if (Key.isDown(Key.LEFT)) {
gotoAndPlay(1);}
if (Key.isDown(Key.RIGHT)) {
gotoAndPlay(6);}
why is that afta playing about 10 secs of my game, flash player and flash MX both say there is action scipt in this movie that is cause flash to run slowly and says it might make ma computer unresponcive
Why?
the code is used for playing animations for my hero at frame 5 i put gotoAndPlay(1); so it loops that section of animation should i be doing things differnent??
-
Untitled-1.fla
Are you sure it's really the code above that is causing it?
-
curiouser and curiouser
where is this code placed? it looks like you're telling flash to gotoAndPlay frame 1 or 6 of the main timeline.
To just affect the hero animation, you'll need to use
heroMovieClipname.gotoAndPlay(1);
-
Senior Member
that code in placed on the hero MC i thought if it was placed on that it effects that unless i put _root. befor it???
well i think thats whats causing the problem, cose as soon as i take that code out there is no more problems...
i placed this code at just b4 end of all the code on ma MC.. dose it need to go in a specific place??
-
curiouser and curiouser
it's difficult without seeing the whole structure - have you tried code: this.gotoAndPlay(1)
and see if that fixes it?
-
Senior Member
it didnt work... should i try sumthing like
Code:
if (Key.isDown(Key.LEFT))
if(_currentframe>5) ;{
gotoAndPlay(1);}
if (Key.isDown(Key.RIGHT))
if(_currentframe <6) ;{
gotoAndPlay(6);}
or is there suposed to be an and in there
BTW frames 1 to 5 are the animation for going left and 6 to 10 are the ones for right
-
n00b
Here are two other possible solutions, depending on if your animation plays from that frame you want to goto or if it can be stopped at the specific frame.
Solution 1:
Code:
if (Key.isDown(Key.LEFT)) {
if (this._currentframe != 1) {
this.gotoAndStop(1);
}
}
if (Key.isDown(Key.RIGHT)) {
if (this._currentframe != 6) {
this.gotoAndStop(6);
}
}
Solution 2:
Code:
// Better saving a state of what our dude is doing
// This way you can play the animation without replaying it
// all the time while its still doing the same
var state = 0;
// generall state you need to reset to that if nothing of the below stuff is happening.
if (Key.isDown(Key.LEFT)) {
if (this.state != 1) {
this.gotoAndPlay(1);
this.state = 1;
}
}
if (Key.isDown(Key.RIGHT)) {
if (this.state != 6) {
this.gotoAndPlay(6);
this.state = 6;
}
}
EDIT: Oh from what you just posted solution two might be the one you will need .
And also the state does not need to be the same number as the frame. Lets say you have 5 player states. 0 for being idle, 1 for walking left, 2 for walking right, 3 for jumping, 4 for crouching. Then you just use that iteration and compare in which state the player is.
greets
Last edited by LeechmasterB; 08-25-2005 at 08:41 AM.
I do stuff that does stuff...
J-Force
-
Senior Member
dose the same thing as my first attemp cept now it lasts about 30 seconds... BTW it only happens when i press left or right... thats why i think it might hvae sumthing to do with ma code
this is my code including your seconds surgestion
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT) or Key.isDown(Key.UP)) {
if (_root.Level.hitTest(_x+_width/2, _y+_height+2, true)) {
force_y -= 1.5
} else { force_y -= 1}
}
if (Key.isDown(Key.LEFT)) {
if (_root.Level.hitTest(_x+_width/2, _y+_height+2, true)) {
force_x -= 1.5;
{
if (this.state != 1) {
this.gotoAndPlay(1);
this.state = 1;
}
}
} else {force_x -= 1;}
}
if (Key.isDown(Key.RIGHT)) {
if (_root.Level.hitTest(_x+_width/2, _y+_height+2, true)) {
force_x += 1.5;
if (Key.isDown(Key.RIGHT)) {
if (this.state != 6) {
this.gotoAndPlay(6);
this.state = 6;
}
}
} else {force_x += 1;}
}
if (Key.isDown(Key.DOWN)) {
if (_root.Level.hitTest(_x+_width/2, _y+_height+2, true)) {
force_y -= -1.5
} else { force_y -= -1}
}
were is there a mistake in there that might make this problem happen??
PS: if u want me to post the rest of the code i can....
Last edited by Gloo pot; 08-25-2005 at 08:50 AM.
-
n00b
Hum this code is a little bit splattered, I can't really format it. The best would be if you post a fla file where everything is the way you have it. That would make it easier to get the picture of it than this mess of code junks.
I do stuff that does stuff...
J-Force
-
M.D.
use these buttons often, they clean up the code and make everything nice and shiny
I used you code to try and re-create your situation. i added:
_x += force_x
_y += force_y
got no problems, worked fine.
Last edited by mr_malee; 08-25-2005 at 10:43 AM.
-
infidel!
post the fla.. or if is confidential, a similar one without graphix...
regards..
-
Senior Member
Here is the .fla
if u can plz figure out dat moving problem and also check out the following
1) can u fix the button so when the player lands on top of it to dose what the code says... right now i think it works only when u come from the bottom
2) same with the flag (the finish)
3) my player movable block i cant it to move up and down only side to side
thx peoples
Peace out
Last edited by Gloo pot; 08-26-2005 at 07:42 AM.
-
n00b
Well, I don't want to diss you but your whole code and game arangement is a bit messy. I fixed your problem, as it was very simple. The thing causing your game to freeze/run slow was that you had a gotoandstop in the robot animation that was telling the clip to go to the very same frame that contained the code!
Anyhow here is the fixed version but I suggest that you have a look at tonypas tilebased tutorials and redo the whole thing. Simply because you will learn a nicer way to arange your code and how to make things work. I don't really feel like explaining everything that bugged me about it because thats quiet a lot to explain so the best is if you have a look at some tutorials or tonypas stuff. One hint though, you don't need an on enterframe event for every single movieclip, you just need a single one! And if you have two enemies who are the same you only need to write the code for one and can attach as many of them as you want that use the same code. The different location and routes where they move are usually passed as initiating parameters. Like mentioned have a look at tonypas tutorials.
Here is your fixed fla:
robot3.fla
And here the link to tonypas tutorials:
http://www.tonypa.pri.ee/tbw/index.html
greets and good luck with your game
I do stuff that does stuff...
J-Force
-
Senior Member
thanks mate... i always figured my first few games were gona be crap, and i have also read tonypa's tut's and my first game was made from it... but im realy new to flash and could only able to do basic things with it, i wasnt experiaenced enough to add things or do the stuff i wanted so im just making other games to learn so maby in a year or so i might make a resonable game :P
also i used tonypa's tuts for my first game... because my tile based engine is his one (cose i learnt form his) am i or am i not aloud to put my game on my we site, will i get in trouble?
Peace out
-
Senior Member
 Originally Posted by Gloo pot
also i used tonypa's tuts for my first game... because my tile based engine is his one (cose i learnt form his) am i or am i not aloud to put my game on my we site, will i get in trouble?
Basically, if you use my tutorials you can only use it in your personal or educational site and you should mention the tutorials somewhere in the credits. Thats all I ask and its up to you to decide if you respect my wish.
-
Senior Member
Thanks mate,
and dun worry ill have your site in big bold letters with flashing signs and stuff pointing to it in the credits :P just so peepz wont miss it...
Thx guys for all your help in this thread, Much Apreciated
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
|