Flash bitmap engine Solution

Source: Internet
Author: User
Overview

Anyone familiar with flash game engines knows that flash game development mainly uses two rendering methods to implement game logic.

  1. Display list
    The display unit is displayobject.
  2. Bitmap
    All display units are bitmapdata

We will not discuss which of the two methods is good or bad. If you are interested, you can search for "flash game engine ". The most famous ones are Pushbutton engine, flixel, and flashpunk.

Bitmap engine concept

It is a bitmapdata-based image buffering technology. developers can determine what content should be painted in graphic rendering. It can be understood as painting. We open a piece of paper and fill the screen with what we want. Suitable for drawing a large number of units, such as particle systems, shooting games, and parkour games.

Bitmap engine implementation
  • World cworld
    The world is a canvas, a bitmap buffer, where all the Genie of the game world exist.
  • Genie cworldsprite
    A display object in the world, such as a bullet or an airplane.
  • Camera cworldcamera
    If a world is large enough, it is impossible to display all the genie in one screen. Therefore, you need to scroll the screen to display the genie in different positions, that is, scroll.
Cworld is an inheritance class of Bitmap. It is mainly responsible for displaying the final rendering result to Sprite. In cworld, there is an array private VaR _ sprites: vector. <cworldsprite> = new vector. <cworldsprite> (); the array actually saves all the genie in the world, and the genie is finally drawn to the cworld buffer in the form of bitmapdata. For the bitmap engine, the camera is used to calculate the location where all the genie should draw to the world buffer zone. The cworld function is used to ultimately draw all the genie into the world buffer zone. Protected function rendersprites (G: igraphics, sprites: vector. <cworldsprite>): void {var X1: Int = getcamerax (); var Y1: Int = getcameray (); var X2: Int = getcamerax () + getcamerawidth (); vaR Y2: Int = getcameray () + getcameraheight (); For each (VAR spr: cworldsprite in sprites) {If (cmath. intersectrect (SPR. X + SPR. getanimates (). w_left, SPR. Y + SPR. getanimates (). w_top, SPR. X + SPR. getanimates (). w_rig HT, SPR. Y + SPR. getanimates (). w_bottom, X1, Y1, X2, Y2) {SPR. render (G, SPR. x-X1, SPR. y-Y1, SPR. getcurrentanimate (), SPR. getcurrentframe () ;}} cworldsprite. render, this method will eventually call the copypixels method or draw method of bitmapdata of cworld. Here, sourcebitmapdata is the image resource bitmapdata contained in the Genie. It copies or draws the sprite image to the buffer zone of the world. The above is the core idea and logic for implementing the bitmap engine.
Make the screen dynamic
The bitmap engine needs to repaint the buffer at each frame, so the enterframe event can meet this requirement. In the main Sprite, add the enterframe event listener. Create cworld and add it to the sprite container. Write Public Function update (E: Event) in your enterframe event: void {// logic of all genie in the New World (such as mobile, playing animated frames, etc .) Cworld. Update (); // redraw all the gems in the world cworld. Render ();} the game logic needs to be separated from the rendering logic to adapt to functions such as pause. Now, the main loop framework of a game comes out. You only need to manage the status of all the genie in cworld to control the game logic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.