Comunidad de diseño web y desarrollo en internet online

keyboard events

Citar            
MensajeEscrito el 29 Jul 2012 01:39 am
hola a todas .. bueno tengo una pregunta bastante basica q se puede hacer facilmente en as2 pero no me sale en as3

tengo un objeto donde lo muevo con el teclado
mi idea es hacer uno de estos juegos tipos brawler pero lo q quiero hacer es q al apretar
Z reprodusca la animacion del golpe entera sin necesidad de mantener apretado el boton

el scrip es facil y entendible
sencillamente dice q si mantengo apretada la tecla va a reproducir la animación pero como hago q esto no suceda solo cuando apretó Z

horror ortografía EXTREME :(




Código ActionScript :

var derecha:Boolean = false;
var izquierda:Boolean = false;
var punch:Boolean = false;

function setup ()
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, onkey);
stage.addEventListener(Event.ENTER_FRAME, movechar);
stage.addEventListener(KeyboardEvent.KEY_UP, upkey);
}


setup();

function movechar (event:Event):void
{
   if (izquierda)
   {
      personaje.x -= 5;
      
   }
   if (derecha)
   {
      personaje.x += 5;
      
   }
   
   
   
   
}

function onkey (event:KeyboardEvent):void
{
   if (event.keyCode == 37)
   {
      izquierda = true;
      personaje.gotoAndStop("caminar");
   }
   if (event.keyCode == 39)
   {
      derecha = true;
      personaje.gotoAndStop("caminar");
   }
   if (event.keyCode == 90)
   {
      punch = true;
       personaje.gotoAndStop("punch");
   }
   
   
   
   
}


function upkey (event:KeyboardEvent):void
{
   if (event.keyCode == 37)
    {
       izquierda = false;
       personaje.gotoAndStop("stance");
       
    }
    
    if (event.keyCode == 39)
    {
       derecha = false;
       personaje.gotoAndStop("stance");
    }
    if (event.keyCode == 90)
    {
       punch = false;
       personaje.gotoAndStop("stance");
    }

    
   
}

Por burnsplash

14 de clabLevel



 

chrome
Citar            
MensajeEscrito el 30 Jul 2012 12:56 pm
Idea: usa un flag que pones a true en el primer evento de teclado, en el segundo si tienes el flag a true disparas la animación (y lo vuelves a false, sino se te disparará constantemente) Mas problemas luego, pero avanza a este punto.

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.