-
How can I change that parameter
Hi ! I have a game and i'm trying to make changes when a thing happens
I want to do this, when the "caught" flies rise up to "50" increase the value
for the flies falling frame per frame
so I tried this:
(I post the last part of the code because maybe my mistake could be there)
Code:
function crearID():void{
var enemigo:Cayendo=new Cayendo()
enemigo.y=-50;
enemigo.x=Math.random()*stage.stageWidth;
enemigo.addEventListener(Event.ENTER_FRAME,dropEnemy);
addChild(enemigo);
}
function dropEnemy(e:Event):void{
var mc:Cayendo=Cayendo(e.target);
//THIS IS WHAT I WANT TO CHANGE WHEN atrapadasText.text=="50"
mc.y+=10
//ONLY CHANGING mc.y+=10 to mc.y+=60 IS WHAT I WANT
if(mc.hitTestObject(agarrador)){
atrapadas(mc);
}else if(mc.y>stage.stageHeight){
erradas(mc);
/*THIS IS HOW I MEANT TO DO IT
if(atrapadasText.text=="50"){
mc.y+=60
}*/
}
function atrapadas(mc:Cayendo):void{
mc.removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChild(mc);
atrapadasText.text=String(Number(atrapadasText.text)+1);
if(atrapadasText.text=="50"){
nivel2.gotoAndPlay(1);
}
}
function erradas(mc:Cayendo):void{
mc.removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChild(mc);
erradasText.text=String(Number(erradasText.text)+1);
if(erradasText.text=="5"){
gameOver();
}
}
function gameOver():void{
score=Number(atrapadasText.text);
removeChild(agarrador);
clearInterval(crearIDenemigo);
removeChild(atrapadasText);
removeChild(erradasText);
while(numChildren>0){
getChildAt(0).removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChildAt(0);
}
stage.removeEventListener(KeyboardEvent.KEY_DOWN, presionoTecla);
stage.removeEventListener(KeyboardEvent.KEY_UP, sueltoTecla);
stage.removeEventListener(Event.ENTER_FRAME , mover);
gotoAndStop("game over");
Mouse.show();
}
iniciarJuego();
what i'm doing wrong'?
-
Instead of adding a constant 10, you can have a variable, and change that variable value.
You should also consider keeping int variables for all your numbers rather than using the text values in the textfields.
Code:
var dropSpeed:Number = 10;
var atrapadasNum:int = 0;
var erradasNum:int = 0;
function crearID():void{
var enemigo:Cayendo=new Cayendo()
enemigo.y=-50;
enemigo.x=Math.random()*stage.stageWidth;
enemigo.addEventListener(Event.ENTER_FRAME,dropEnemy);
addChild(enemigo);
}
function dropEnemy(e:Event):void{
var mc:Cayendo=Cayendo(e.target);
mc.y+=dropSpeed;
if(mc.hitTestObject(agarrador)){
atrapadas(mc);
}else if(mc.y>stage.stageHeight){
erradas(mc);
}
}
function atrapadas(mc:Cayendo):void{
mc.removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChild(mc);
atrapadasNum++;
atrapadasText.text=String(atrapadasNum);
if(atrapadasNum == 50){
dropSpeed = 60;
nivel2.gotoAndPlay(1);
}
}
function erradas(mc:Cayendo):void{
mc.removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChild(mc);
erradasNum++;
erradasText.text=String(erradasNum);
if(erradasNum == 5){
gameOver();
}
}
function gameOver():void{
score=atrapadasNum;
removeChild(agarrador);
clearInterval(crearIDenemigo);
removeChild(atrapadasText);
removeChild(erradasText);
while(numChildren>0){
getChildAt(0).removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChildAt(0);
}
stage.removeEventListener(KeyboardEvent.KEY_DOWN, presionoTecla);
stage.removeEventListener(KeyboardEvent.KEY_UP, sueltoTecla);
stage.removeEventListener(Event.ENTER_FRAME , mover);
gotoAndStop("game over");
Mouse.show();
}
iniciarJuego();
You should also consider using a Timer rather than setInterval/clearInterval.
Tags for this Thread
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
|