la aplicación global de la función de movieclip

  • arliita
  • Born
  • Born
  • No Avatar
  • Registrado: Feb 13, 2009
  • Mensajes: 1
  • Status: Offline

Nota Febrero 13th, 2009, 4:30 pm

Im crear un juego donde el personaje permanece en el centro de la pantalla y el fondo de pergaminos pasado como se pulsan los botones. Tengo varios enemigos y de tal manera que yo quiero para desplazarse a la vista también.
He creado una función global:

Código: [ Select ]
_global.objects_move = function()
{
if (Key.isDown(Key.UP)) {
this._y -= 10;
}
if (Key.isDown(Key.DOWN)) {
this._y += 10;
}
if (Key.isDown(Key.LEFT)) {
this._x += 10;
}
if (Key.isDown(Key.RIGHT)) {
this._x -= 10;
}
};
  1. _global.objects_move = function()
  2. {
  3. if (Key.isDown(Key.UP)) {
  4. this._y -= 10;
  5. }
  6. if (Key.isDown(Key.DOWN)) {
  7. this._y += 10;
  8. }
  9. if (Key.isDown(Key.LEFT)) {
  10. this._x += 10;
  11. }
  12. if (Key.isDown(Key.RIGHT)) {
  13. this._x -= 10;
  14. }
  15. };


y quiero que se aplican a todos los movieclips enemigo diferente por lo que desplazarse a la vista.
Ive intentado añadir este código en los clips de película

Código: [ Select ]
onClipEvent (enterFrame)
{
this.objects_move();
}
  1. onClipEvent (enterFrame)
  2. {
  3. this.objects_move();
  4. }


y cosas similares, pero no puedo conseguir que funcione...
Moderator Remark: Added code tags
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Febrero 13th, 2009, 4:30 pm

  • ibrabdo
  • Novice
  • Novice
  • Avatar de Usuario
  • Registrado: Feb 23, 2009
  • Mensajes: 29
  • Status: Offline

Nota Febrero 23rd, 2009, 4:27 am

intente esto:
Código: [ Select ]
onClipEvent(load){
    VelX = 0 ; // world velocity on x axis
    VelY = 0 ; // world velocity on y axis
    PosX = _root.BackGround._x ; // the background position on x axis
    PosY = _root.BackGround._y ; // the background position on y axis
    PosX2 = _root.enemie._x; // the enimie position on x axis
    PosY2 = _root.enemie._y; // the enimie position on y axis
}
onClipEvent(enterFrame){
    VelX = VelX * 0.5;
    VelY = VelY * 0.5;
    PosX += VelX ;
    PosY += VelY ;
    PosX2 += VelX ;
    PosY2 += VelY ;
    if(Key.isDown(Key.LEFT)){
        VelX += 5;
    }
    if(Key.isDown(Key.RIGHT)){
        VelX -= 5;
    }
    if(Key.isDown(Key.UP)){
        VelY += 10;
    }
    if(Key.isDown(Key.DOWN)){
        VelY -= 10;
    }
    _root.BackGround._x = PosX;
    _root.BackGround._y = PosY;
    _root.enemie._x = PosX2;
    _root.enemie._y = PosY2;
}
  1. onClipEvent(load){
  2.     VelX = 0 ; // world velocity on x axis
  3.     VelY = 0 ; // world velocity on y axis
  4.     PosX = _root.BackGround._x ; // the background position on x axis
  5.     PosY = _root.BackGround._y ; // the background position on y axis
  6.     PosX2 = _root.enemie._x; // the enimie position on x axis
  7.     PosY2 = _root.enemie._y; // the enimie position on y axis
  8. }
  9. onClipEvent(enterFrame){
  10.     VelX = VelX * 0.5;
  11.     VelY = VelY * 0.5;
  12.     PosX += VelX ;
  13.     PosY += VelY ;
  14.     PosX2 += VelX ;
  15.     PosY2 += VelY ;
  16.     if(Key.isDown(Key.LEFT)){
  17.         VelX += 5;
  18.     }
  19.     if(Key.isDown(Key.RIGHT)){
  20.         VelX -= 5;
  21.     }
  22.     if(Key.isDown(Key.UP)){
  23.         VelY += 10;
  24.     }
  25.     if(Key.isDown(Key.DOWN)){
  26.         VelY -= 10;
  27.     }
  28.     _root.BackGround._x = PosX;
  29.     _root.BackGround._y = PosY;
  30.     _root.enemie._x = PosX2;
  31.     _root.enemie._y = PosY2;
  32. }


si u desea que el enemie movimiento mientras hes desplazamiento u have a darle una VelX difrent (VelXE) VelXE = 5 * dir (dir es la dirección de la enemie 1 o -1) entonces el movimiento total (VelXT) va a ser
VelXT = VelXE + VelX
y lo mismo en el eje _y

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 39 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC