Esos tags son de la
negrita no es nada puesto en el codigo original mio, el error es que quise remarcarte donde estaba lo que yo creia que era que estaba mal y lo quise remarcar dentro de
Código :
sin saber que justamente estos tags son para escribir tags : P
Ya solucione el error, era porque la variable estaba declarada dentro de una funcion y entonces funcionaba solo para esa funcion, y la debia declarar afuera;
Por favor, chequea esto.
Este es el codigo entero
Código :
import flash.events.KeyboardEvent;
var coches:coche;
var rivaleses:rivales;
var velocidadJuego:uint;
var crearIDenemigo:uint;
var izquierda:Boolean;
var derecha:Boolean;
var arriba:Boolean;
var abajo:Boolean;
var timer:Timer = new Timer(1000,1);
var numerodevidas:Number= 3
var inclinadoIzq:Boolean;
var inclinadoDer:Boolean;
// PARA SABER CUANDO SUELTO TECLA Y NO ESTA PULSADA
var pulsadoLeft:Boolean;
var pulsadoRight:Boolean;
var bloqueadorRight:Boolean=true;
var bloqueadorLeft:Boolean=true;
function iniciarJuego():void {
coches=new coche();
coches.x=300;
coches.y=370;
addChild(coches);
velocidadJuego=500;
crearIDenemigo=setInterval(crearID,velocidadJuego);
Mouse.hide();
stage.stageFocusRect=false;
stage.focus=stage;
stage.addEventListener(KeyboardEvent.KEY_DOWN, presionoTecla, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, sueltoTecla, false, 0, true);
stage.addEventListener(Event.ENTER_FRAME, mover, false, 0, true);
}
function mover(e:Event):void {
if (derecha&&inclinadoDer==false) {
coches.rotation+=20;
inclinadoDer=true;
}
if (derecha) {
coches.x+=9;
coches.scaleX=+1;
pulsadoRight=true;
//SACO EL BLOQUEO
bloqueadorRight=false;
} else {
pulsadoRight=false;
}
if (pulsadoRight==false&&bloqueadorRight==false) {
coches.rotation-=20;
bloqueadorRight=true;
inclinadoDer=false;
}
//////////////////////TODO LO MISMO PARA LA IZQUIERDA AHORA
//////////////////////AL REVES EL MOV. EN X Y LA ROTACION
if (izquierda) {
coches.x-=9;
pulsadoLeft=true;
//SCALE EN -1 PORQUE LA RANA
//DE POR SI YA VIENE DE LADO DERECHO
coches.scaleX=-1;
bloqueadorLeft=false;
} else {
pulsadoLeft=false;
}
if (izquierda&&inclinadoIzq==false) {
coches.rotation-=20;
inclinadoIzq=true;
}
if (pulsadoLeft==false&&bloqueadorLeft==false) {
coches.rotation+=20;
bloqueadorLeft=true;
inclinadoIzq=false;
}
if (arriba) {
coches.y-=5;
}
if(abajo) {
coches.y+=4;
}
//PA QUE NO SE LAS PIQUE DEL STAGE
if (coches.x>stage.stageWidth-coches.width/2 - 95) {
coches.x-=10;
}
if (coches.x<coches.width/2 + 95) {
coches.x+=10;
}
if (coches.y>stage.stageHeight-coches.height/2) {
coches.y-=4;
}
if (coches.y<0 + coches.height/2) {
coches.y+=5;
}
}
function sueltoTecla(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.LEFT :
izquierda=false;
break;
case Keyboard.RIGHT :
derecha=false;
break;
case Keyboard.UP :
arriba=false;
break;
case Keyboard.DOWN :
abajo=false;
break;
default :
break;
}
}
function presionoTecla(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.LEFT :
izquierda=true;
break;
case Keyboard.RIGHT :
derecha=true;
break;
case Keyboard.UP :
arriba=true;
break;
case Keyboard.DOWN :
abajo=true;
break;
default :
break;
}
}
function crearID():void {
rivaleses=new rivales();
var espacioalaizq:int= 0 + pasto1.width + borde1.width + rivaleses.width/2;
var espacioalader:int= stage.stageWidth - (pasto2.width + borde2.width + rivaleses.width/2);
var num:int = Math.floor(Math.random() * (espacioalader - espacioalaizq + 1)) + espacioalaizq;
rivaleses.y=10;
rivaleses.x= num;
rivaleses.addEventListener(Event.ENTER_FRAME,dropEnemy);
miniauto.addEventListener(Event.ENTER_FRAME,avanzaMini);
addChild(rivaleses);
rivaleses.addEventListener(Event.ENTER_FRAME, vidas);
coches.addEventListener(Event.ENTER_FRAME, vidas);
stage.addEventListener(Event.ENTER_FRAME, vidas);
}
function dropEnemy(e:Event):void {
var caer:rivales=rivales(e.target);
caer.y+=10;
}
function avanzaMini(e:Event):void {
if(miniauto.hitTestObject(bandera.bandera_llegada)) {
miniauto.removeEventListener(Event.ENTER_FRAME,avanzaMini);
clearInterval(crearIDenemigo);
timer.addEventListener(TimerEvent.TIMER,llamame_a_la_otra);
timer.start();
}else{
miniauto.y-=0.5;
}
}
function llamame_a_la_otra(e:TimerEvent):void{
llegada_grande.addEventListener(Event.ENTER_FRAME,banderaCuadros);
}
function banderaCuadros(e:Event):void {
llegada_grande.y+=10;
if(coches.hitTestObject(llegada_grande.llegada)) {
llegada_grande.removeEventListener(Event.ENTER_FRAME,banderaCuadros);
rivaleses.removeEventListener(Event.ENTER_FRAME,dropEnemy);
removeChild(rivaleses);
stage.removeEventListener(Event.ENTER_FRAME, mover);
}
}
function vidas (e:Event):void{
if(coches.hitTestObject(rivaleses)){
coches.visible=false;
}
}
iniciarJuego()
Estoy tratando de que "coches" se haga invisible al colisionar con rivaleses, pero no se porque no funciona como yo quiero. No se hace invisible a menos que acerques "coches" casi hasta el punto cero del eje Y.
Yo creo que el problema esta en los EventListeners declarados dentro de la funcion CrearID,
pero he probado poniendolos por fuera de esta, asi como la solucion para el anterior problema que presente en este foro, y obtengo el mismo resultado indeseado. Como puedo hacer ???
I