使用 flash 实现 frogger

发布于 2024-07-18 02:15:55 字数 516 浏览 4 评论 0原文

对于初学者:我正在使用 Flash CS3 和 Actionscript 2.0

我正在尝试重新制作青蛙游戏,但我有点坚持将汽车放在屏幕上。

对于那些不了解 frogger 的人:http://www.actionscript.org /showMovie.php?id=1157,但我没有实现日志。

最大的问题是我有3辆车,它们都是库中的电影剪辑,我不会将它们放在舞台上。 多个实例必须同时出现。 这些车需要双向行驶,并且所有 3 辆车必须出现在所有车道上(我有 4 条车道) 当然,1条车道只有1个方向。

我可以使用 hitTest() 来查看我的青蛙是否撞到了其中一辆车,但我需要让它变得现实,这意味着我无法对每条车道上的汽车数量进行硬编码。

我似乎也找不到如何围绕其中心旋转影片剪辑......

For starters: I'm working with Flash CS3 and Actionscript 2.0

I'm trying to remake the frogger game, and I'm kinda stuck with putting the cars on the screen.

For those of you who don't know frogger: http://www.actionscript.org/showMovie.php?id=1157, but I'm not implementing the logs.

The big problem is that I have 3 cars, all of which are movieclips in the library, I won't place any of them on the stage. Multiple instances must appear at the same time. These cars need to drive in both directions and all 3 cars must appear in all lanes(I have 4 lanes)
Of course, 1 lane only has 1 direction.

I can use hitTest() to see if my frog has hit one of the cars, but I need to make it realistic, meaning I can't hard-code the amount of cars on each lane.

I also can't seem to find how to rotate a movieclip around its center...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-07-25 02:15:55

嗯,我可以建议几件事。

对于汽车,将每辆车创建为库中的单独对象(不要将它们放在舞台上)。 当您需要在屏幕上显示一个汽车时,请使用 AttachMovie() 创建您想要的汽车的实例。

为了使它们面向不同的方向(我相信你只需要向左和向右),你可以在库中为每辆车创建 2 个副本,一个面向每个方向。 或者,我认为如果将 xScale 值设置为 -100%,我认为这会水平翻转它,因此您可以为两者使用相同的库实例。 但是,如果每个方向都有单独的库实例,而不是在一个方向上进行旋转,那么处理可能会更容易。

Well, there are a couple things I can suggest.

For the cars, create each car as a separate object in the Library (don't put them on the stage). When you need to have one appear on the screen use attachMovie() to create an instance of the car you want.

For making them face different directions (I believe you just need left and right), you could either create 2 copies of each car in the Library, one facing each direction. Or, I think if you set xScale value to -100% I think that will flip it horizontally, so you could use the same Library instance for both. However, it would probably be easier to deal with if you had separate Library instances for each direction, instead of doing rotations on one.

眸中客 2024-07-25 02:15:55

为了回答有关旋转的问题,影片剪辑围绕其注册点旋转,而不是围绕其视觉中心旋转。 因此,当您创建剪辑时,请确保符号编辑屏幕上的十字线出现在中心。 十字准线是注册点,它基本上定义了剪辑上 x:0,y:0 的位置。

听起来你的问题实际上是关于如何使用 hitTest 来查看青蛙是否撞到了任何一辆汽车,无论是哪一辆,舞台上有多少辆汽车等等。所以我要做的是为汽车创建一个类一个静态成员,可以是指向青蛙的指针,然后让类检查它是否正在击中青蛙。

首先:

public class Car extends MovieClip{     
    public static var frog:MovieClip;
    private var interval;
    public function Car(){
        super();
        interval = setInterval(checkHit,500);
    }
    private function checkHit(){
            if(this.hitTest(frog)){
            trace("the frog hit the car");
            clearInterval(interval);
            //do what you need to do when the frog gets hit 
        }
    }
}

对于每辆单独的汽车,您可以扩展汽车类:

class Truck extends Car{
    public function Truck(){
        super();
    }
}

class Volkswagen extends Car{
    public function Volkswagen(){
        super();
    }
}

class Bus extends Car{
    public function Bus(){
        super();
    }
}

创建单独的类后,在每辆汽车的库符号上使用 Linkage。 (右键单击该符号,选择“链接”,然后在“类”字段中输入类名称)。

最后,将青蛙成员设置为舞台上的青蛙

var frog:MovieClip = attachMovie("frog_mc", frogMC, _root.getNextHighestDepth())
Car.frog = frog; //set the static var "frog" to your frog instance

,现在您的汽车应该全部检查是否撞到了青蛙。

另一种选择是在每个不同汽车影片剪辑的第一帧上编写 checkHit() 函数,而不是为每个影片使用类:

this.onEnterFrame = function(){
    if(this.hitTest(_root.frog)){
        trace("the frog hit the car");
        //do what you need to do when the frog gets hit 
        delete this.onEnterFrame;
    }
}

to answer your question about rotation, movie clips rotate around their registration point, not around their visual center. So when you create your clips, make sure that the crosshairs on the symbol-editing screen appear in the center. The crosshairs is the registration point, which basically defines where x:0,y:0 is on the clip.

It sounds like your question is really about how to use hitTest to see if the frog has hit any of the cars, regardless of which one, how many are on stage, etc. So what I would do is create a class for the car with a static member that can be a pointer to the frog, and then have the class check for whether it is hitting the frog.

So to start out:

public class Car extends MovieClip{     
    public static var frog:MovieClip;
    private var interval;
    public function Car(){
        super();
        interval = setInterval(checkHit,500);
    }
    private function checkHit(){
            if(this.hitTest(frog)){
            trace("the frog hit the car");
            clearInterval(interval);
            //do what you need to do when the frog gets hit 
        }
    }
}

For each individual car, you can extend the Car class:

class Truck extends Car{
    public function Truck(){
        super();
    }
}

class Volkswagen extends Car{
    public function Volkswagen(){
        super();
    }
}

class Bus extends Car{
    public function Bus(){
        super();
    }
}

After creating the individual classes, use Linkage on your Library symbols for each car. (rightclick on the symbol, select Linkage, and type your class name in the Class field).

Finally, set the frog member to your frog on stage

var frog:MovieClip = attachMovie("frog_mc", frogMC, _root.getNextHighestDepth())
Car.frog = frog; //set the static var "frog" to your frog instance

And now your cars should all check themselves for whether they're hitting the frog.

The other option is to code that checkHit() function on the first frame of each different car movieclip, rather than using classes for each:

this.onEnterFrame = function(){
    if(this.hitTest(_root.frog)){
        trace("the frog hit the car");
        //do what you need to do when the frog gets hit 
        delete this.onEnterFrame;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文