Bomb man game development process (3) Show map

Source: Internet
Author: User

Objective

Above we have carried on the preliminary high level design, now we will realize the picture preload and the display map function demand. This article began with TDD development, you can see in the implementation of the process we will modify the design, modify the design and then modify the corresponding implementation code, this is a continuous iterative process. With the protection of the test suite, we can refactor it with confidence.

The purpose of this article

Master the technology of map drawing.

Review the domain model associated with the display map above

Development strategy

Use my control ypreloadimg to implement picture preload, combined with ProgressBar plug-ins, to display the load progress bar.

Just build a Showmap class, use this class to experiment, find a way to show the map, and then isolate the main class and the MapData data class when you refactor.

Reason

Because I am very unfamiliar with canvas, I need to focus on the use of canvas, rather than focus on architectural design.

Because I'm using TDD, I can refactor safely. You can extract the main and MapData classes after you implement the "Show Map" feature and then refactor it.

The development strategy is also iterative correction

The development strategy is just the approximate plan that is specified in the current knowledge and is refined and modified as the development progresses. The current development strategy does not take into account the addition of game classes when refactoring.

Pre-loading pictures

Pre-loading purpose

Downloads the picture to local memory.

Why preload

You must wait until the picture is fully loaded before you can use canvas to manipulate the picture. If you try to render the picture to canvas before it is fully loaded, canvas will not display any pictures.

If you do not use preload, you need to download the picture to local before using the picture. Even with browser optimization, the first time you use a picture, you need to download the picture, so the first time you use the picture, there will be a card feeling.

So before the game starts, start the game initialization and preload the pictures needed for the game.

How to Preload

Basic example:

var img = new Image ();     Callback (IMG);};

Pre-loading online tutorials

Pre-loading JS image

JS implementation picture preload

Pre-loading problems with browser heavy Pictures onload event

Show progress bar

The Ypreloadimg control combines the progress bar plug-in ProgressBar to display the progress bar.

Add Showmap class and implement pre-loading pictures

New Showmap class, using TDD to develop and implement preloaded pictures, you need to write test cases first.

Here is a brief introduction to the test-driven development steps:

Write a test case, verify the behavior

Run the test to see if the test case itself has an error (whether the test fails in the way that you expect).

Write implementation code that allows the test to pass

Refactoring code

Run the test to make the test pass

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.