actionscript-3 flash air

actionscript 3 - Intercambio de repetición sin fin Fondo as3 Adobe Air



actionscript-3 flash (2)

Soy nuevo en el guión de acción. Traté de crear un fondo de desplazamiento infinito que vaya de arriba abajo del escenario, verticalmente, por supuesto. Traté de hacerlo con la creación de un clip de película, poner la imagen en un clip de película y aplicar algún código, funcionó como un amuleto, pero noté algunas filtraciones. Por lo tanto, probé otro método que encontré en el comité de pila, el cual sugería usar el nuevo método BitmapData. La pregunta que encontré consistió en que un fondo se moverá de izquierda a derecha, lo intenté, fue perfecto.
Traté de comprender todas las variables y factores en él para poder cambiarlo y hacer que se desplazara de arriba a abajo, pero me atasco cada vez con un comportamiento extraño del archivo flash. Estoy seguro de que estoy haciendo algo mal. Realmente agradecería la ayuda. Estoy ansioso por aprender.
Este es el enlace del comité fuente de la pila, obtuve la respuesta de:
El enlace y la respuesta

Aquí está el mismo código que estoy tratando de implementar, copiado desde el enlace:

package { import flash.display.MovieClip; import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.Event; import flash.geom.Rectangle; import flash.geom.Point; public class EndlessBG extends MovieClip{ //this one stays stationary, we''re getting the pixels for the right side of the pic from here private var _source:BitmapData; //this is the one moving to the left (the pixels for the right side are not visible except for once a cycle); private var _movingPixels:BitmapData; private var _canvas:Bitmap; private var _xOffset:int = 0; private var _rect:Rectangle = new Rectangle();; private var _point:Point = new Point(); public function EndlessBG() { super(); _source = new BathroomStillLife(); _canvas = new Bitmap(new BitmapData(_source.width, _source.height)); _canvas.bitmapData.draw(_source); _canvas.x = stage.stageWidth/2 - _canvas.width/2; _canvas.y = 5; addChild(_canvas); addEventListener(Event.ENTER_FRAME, gameLoop); setGeometryDefaults(); _movingPixels = new BitmapData(_source.width, _source.height); _movingPixels.copyPixels(_source, _rect, _point); //turn this on to watch red pixels be drawn where the source pixels are coming in //_source = new BitmapData(_source.width, _source.height, false, 0xFF0000); } private function gameLoop(e:Event):void { _xOffset--;//where the background is moving to if (_xOffset < -_source.width) { _xOffset = 0; //this doesn''t seem to work correctly: //_movingPixels.scroll(_source.width, 0); _movingPixels = new BitmapData(_source.width, _source.height); _movingPixels.copyPixels(_source, _rect, _point); } trace(_xOffset); setGeometryDefaults(); _movingPixels.scroll(-1, 0); //draw the moved part of the canvas _canvas.bitmapData.copyPixels(_movingPixels, _rect, _point); //If we stop here, we get a smear to the right //so, get the remaining pixels directly from the source //1) reset our rect and point to be to the right side _rect.x = 0; _rect.width = -_xOffset; _point.x = _source.width + _xOffset; //2) copy from the source _canvas.bitmapData.copyPixels(_source, _rect, _point); } private function setGeometryDefaults():void { _rect.x=0; _rect.y=0; _rect.width = _source.width; _rect.height = _source.height; _point.x = 0; _point.y = 0; } } }

Realmente aprecio la ayuda ... con ganas de aprender.


No estoy muy familiarizado con Adobe Air, pero este fue un problema que también tuve. Estoy usando flashdevelop, sin embargo, junto con la biblioteca FlashPunk (ambos son totalmente gratuitos) y encontré una solución aquí .

¡La mejor de las suertes!


En general, solo desea mover o mostrar y ocultar mapas de bits cuando se está ejecutando su animación. No deberías dibujar o copypixels cuando la animación se está ejecutando. Haces eso durante la "carga" porque puede ralentizar tu fps. Convierta todo en mapas de bits y elimine todos los gráficos fuente (jpg, png, texto e imágenes vectoriales) antes de que comience su animación.

Para un fondo de desplazamiento, debe usar dos copias de un mapa de bits en un clip de película y mover el clip de película.

Debería poner la imagen de fondo repetible (jpg, png) en un clip de película o crear el fondo en un clip de película usando vectores. Dibuje ese clip de película a un mapa de bits. Retire el clip de película original. Haga dos copias de bitmapdata. Apila los dos extremo a extremo en un clip de película. A continuación, deslice el clip de película a lo largo de la imagen de fondo: comience en 0 y desplácese hasta que la segunda copia del fondo llegue a 0. A continuación, restablezca el primero en 0.

Aquí está el código de ejemplo que hace lo anterior:

public function Main() { nBackgroundSpeed = 1; iBitmapWidth = mcBackground.mcBackgroundSource.width; iBitmapHeight = mcBackground.mcBackgroundSource.height; var bdBackground: BitmapData = new BitmapData(iBitmapWidth, iBitmapHeight, true, 0x00000000); bdBackground.draw(mcBackground.mcBackgroundSource, null, null, null, null, true); var bmpBackground0: Bitmap = new Bitmap(bdBackground, "auto", false); var bmpBackground1: Bitmap = new Bitmap(bdBackground, "auto", false); mcBackground.removeChild(mcBackground.mcBackgroundSource); mcBackground.mcBackgroundSource = null; mcBackground.addChild(bmpBackground0); bmpBackground0.x = 0; bmpBackground0.y = 0; mcBackground.addChild(bmpBackground1); bmpBackground1.x = 0; bmpBackground1.y = iBitmapHeight; addEventListener(Event.ENTER_FRAME, fEnterFrame); } private function fEnterFrame(event: Event): void { if (mcBackground.y > (0 - iBitmapHeight)) { mcBackground.y -= nBackgroundSpeed; } else { mcBackground.y = 0; } }

Déjame saber de cualquier pregunta.