[MX] Hittest in MX
A Flash Developer Resource Site

# Thread: [MX] Hittest in MX

1. ## [MX] Hittest in MX

hello. im used to using Flash 8 but i now have a class in school using flash. in school we only have the version MX. not 04. im trying to make a platform game to suprise my teacher and classmates. i have made them multiple times in flash 8 but im not familiar with AS in flash MX. do you think someone could provide me with codes for:

1. hittests (and could you just tell me how to do one for future use?)
2. jumping
3. gravity
4. (could you tell me how to do roots for MC's and other things also?)
5. platforms (so you could stay on them and not fall through)

and that should be it for now. you dont have to answer all, just 1 or 2 would be appreciated.

thanks have a nice day. bye

DC

2. Originally Posted by Dark Cloud
and that should be it for now
Just a few minor topics then Dark Cloud!

Hit Test All you are doing is using the condition to see if 2 objects are colliding - Put 2 movie clips on the stage red_mc & green_mc

code:
```_root.onEnterFrame = function() {
_root.red_mc._x += 10;
_root.green_mc._x -= 10;
if (red_mc.hitTest(_root.green_mc)) {
trace("Hit");
}
};```

Gravity The equation for gravity is:

F =G*(mass1*mass2)/distance*distance applying this in Flash will make blood come out our ears! A better & just as effective way is to come up with a value for gravity & then apply that every frame:

code:
```ymov=0;
//set gravity
gravity=2;
_root.onEnterFrame=function () {
ymov+=gravity;
ball._y+=ymov;
if (ball._y > 400) {
ball._y=400;
ymov*=-1;
}
}```

This adds to gravity as mentioned above an then checks the clips _y position if it is at the same level as the floor it reverses the clips downward motion.

Platforms Just set an absolute _y position for your games through which your charaters can not pass, along the lines of if (mans._y>=100){
mans._y=100.

Having said all that game design in Flash can be complex & complicated business for example to make platform games more efficient you would build your world out of tiles (both Platform & Iso) & check for the position/collision of a character using some pretty clever tricks. There are a few really good books on the subject I recommend Jobe Makar's "FlashMX Game design demystified" although written for MX(2000) the object orientated nature of his code should work well in 2000.

3. score

to use scoring and points you just need a varible.

on the first frame of your file put this in the actions:

score = 0
this creates the varible called score and makes its value 0

to display the score:

create a dynamic text feild and enter "score" into the "var:" box.

you can use various methods such as hittest to add to the score. using pup100's code from above for speed:

_root.onEnterFrame = function() {

_root.character_mc._x += 10;

_root.coin._x -= 10;

if (red_mc.hitTest(_root.green_mc)) {

score + 10 //change this to the number of points you want the player to //get when they hit the object

}

};

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap