As code for Flash game map display

Source: Internet
Author: User
Tags define
Show

Today we look at the Flash game map display technology.

Step 1: Create a new movie, it doesn't matter how big the scene is.

Step 2: Create an empty movie clip, the entity name is ALLMC, and then drag to the upper-left corner of the scene, with the x-coordinate 0,y coordinates 0.

Step 3: Create a new movie clip, the entity name is SMAP and dragged to any position in the scene. Into the SMAP, draw a small map background (that is, a color block bar), note: If the registration point in the upper left corner, then this color block position will be entered 0, 0, if the registration point in the center, Then the color block is just as good as the color block width and height of the half. For example, the color block width is 30, the height is 30, then its coordinates are set to 15,15. When you're done, press the color block to F8 to the movie clip, named entity name: SMAPMC.

Step 4, establish control of MC and small map display of MC. Set up an MC, used to control, named box, and then set up an MC, used in the small map display, named Cir. Don't pull them into the scene. You just need to make a connection name for them. The Connection name is box and CIR respectively.
Step 5:as section, copy code at home scene first frame.

Map scale conversion As, absolute moment April 3, 2007///////
var sd:number = 5;
Define Speed
var BOXMC = Allmc.attachmovie ("box", "Nbox", 1);
Load the controlled component dynamically into the movie clip ALLMC and give the variable BOXMC
boxmc._x = Math.random () *stage.width;
BOXMC contains the nbox, now defines its x-coordinate, stage.width is the width of the main scene, allowing boxmc._x random x-axis positions in the main scene
Boxmc._y = Math.random () *stage.height;
Ditto, but here's the random y-axis.
var xpos:number = boxmc._x;
Initially, the x coordinates of the BOXMC are displayed and passed on to the dynamic text basket xpos
var ypos:number = boxmc._y;
Ditto, here's the y-coordinate.
Smap.attachmovie ("Cir", "Cir", 1);
Dynamically load CIR This component and load it into the SMAP movie clip, which is displayed in the small map of the MC
smap.cir._x = BOXMC._X/10;
Define the x-coordinate of the CIR in SMAP, because the map size is scaled by 10 times times, so the speed and position of the walk should be 10.
smap.cir._y = BOXMC._Y/10;
Ditto, the y-coordinate is defined here
var sw:number = stage.width;
The width of the total scene gives variable SW
var sh:number = stage.height;
The high given variable SW for the total scene
Smap.smapmc._width = SW/10;
In order to make the SMAP.SMAPMC. Wide proportional zoom out (taking into account that no matter how the main scene size can be scaled to reduce the small map), so should also/10, is why
Two lines of code to get the width and height of the main scene
Smap.smapmc._height = SH/10;
Ditto, here is the Judge high
smap.smapmc._x = SMAP.SMAPMC._WIDTH/2;
In order to make SMAP.SMAPMC, whether magnified or shrinking, always stay in the smap._x=0 position, so/own half
smap.smapmc._y = SMAP.SMAPMC._HEIGHT/2;
Ditto, here is the definition of y-coordinate
Onenterframe = function () {
Xpos = boxmc._x;
Constantly passing the BOXMC x coordinates to the dynamic text xpos
Ypos = boxmc._y;
Ditto, this is the y-coordinate transfer.
if (Key.isdown (68)) {
boxmc._x = SD;
Smap.cir._x + = SD/10;
BOXMC each move 10 pixel so small map of the MC will move 1 pixels, so take boxmc speed/10, or in addition to 10, multiple
}
if (Key.isdown (65)) {
boxmc._x-= SD;
Smap.cir._x-= SD/10;
Ditto
}
if (Key.isdown (87)) {
Boxmc._y-= SD;
Smap.cir._y-= SD/10;
Ditto
}
if (Key.isdown (83)) {
boxmc._y = SD;
Smap.cir._y + = SD/10;
Ditto
}
This is the effect.: Click here to download the source file

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.