Copy link to clipboard
Copied
I have an ENTER_FRAME event which is supossed to run every frame but it just runs when an if statement is true and only once and not every single frame.
- public function update(e:Event):void
- {
- if(canFire == true)
- {
- trace("The two statements are true");
- var newBullet:Bullet;
- newBullet = new Bullet(gadjet.x, gadjet.y);
- bulletsArray.push(newBullet);
- mcGameStage.addChild(newBullet);
- newBullet.firebullet(); /* as long as this function is executing inside an enter frame's event
- it will make the bullet look moving */
- // this is the Bullet's class firebullet() function
- /*public function firebullet():void
- {
- x = x + 5; // this makes the bullet look moving when using an ENTER_FRAME event
- }*/
- }
- }
Entire class at pastebin:
[ActionScript 3] AvoiderGame4 - Pastebin.com
1 Correct answer
because that boolean is changing to false.
Copy link to clipboard
Copied
is there a question?
is anything unexpected happening?
ie, your title is incorrect, but your first sentence may well be correct.
Copy link to clipboard
Copied
Maybe I'm missing something, but how is "x = x + 5" working? Shouldn't that equation be referring to something like "this.x" or "newBullet.x"?
Copy link to clipboard
Copied
the bullet's x position will increment 5 pixels every frame, it doesn't matter if you put this.x = x +5; or bullet.x = x + 5; the idea is to move it 5 pixels every frame, this way the bullet will look moving, but the enterframe's function only does it just one frame.
Copy link to clipboard
Copied
But you're adding a new bullet to the stage on each frame. Is it supposed to be a machine gun? 🙂
Copy link to clipboard
Copied
kinda like, i need to shut a bullet every time I press the space bar, i.e when the if stament is true
Copy link to clipboard
Copied
again,
is there a question?
is anything unexpected happening?
ie, your title is incorrect, but your first sentence may well be correct.
Copy link to clipboard
Copied
the question is why my bullet just moves one time and not every frame, the unexpected is that the bullet doesn't look like it is moving. the enter_frame event is acting like a "only the first frame is listenig"
Copy link to clipboard
Copied
because that boolean is changing to false.
Copy link to clipboard
Copied
so if I put a while instead of an if and keep my space bar pressed it will be moving?
Copy link to clipboard
Copied
no. you can't use for-loops, while-loops or do-loops to animate objects. those loops execute from beginning to end before anything is updated on-stage.
you should check why your boolean is changing, if that's unexpected.
Copy link to clipboard
Copied
Thanks.
Copy link to clipboard
Copied
you're welcome.
p.s when using the adobe forums, please mark helpful/correct responses, if there are any.
Copy link to clipboard
Copied
I think you jumped the gun asking him to mark an answer as correct, since no one has as yet given him a correct answer. This is one reason I never ask people to do this, even if I am sure I have provided them with the correct answer.
It seems to me that the OP is expecting for the fireBullet() function to continue to fire on ENTER_FRAME. Even if the Boolean changes, this will not happen. The reason behind that is that fireBullet() is only being called on the particular bullet that was just created, not on all bullets that have ever been created. So the function needs to either loop through all of the bullets in the Array or fireBullet() needs to be written in such a way that it's self-sustaining (does its own ENTER_FRAME checking, which opens you up to the possibility of a memory leak due to the nature of that particular event).
Copy link to clipboard
Copied
I dont actually know how to mark it as helpfull because I dont see that option anywhere
Copy link to clipboard
Copied
I can understand that a new bullet needs to be drawn each time you press the space bar, but it looks like you are drawing a new bullet on every frame. Are you setting "canFire" to 'false' anywhere in your code? Because, if you are, then I agree with KGLAD that your issue lies there.
Copy link to clipboard
Copied
Yes I set it to false
Copy link to clipboard
Copied
Well, somehow that's probably your issue. It is being set to false at the wrong time and the function stops performing. I would temporarily comment out the place where it is set to false, and see if the problem goes away.
Copy link to clipboard
Copied
Okey thank you

