从Processing迁移到Flash CS5,我该如何开始?

发布于 2024-10-15 04:47:52 字数 856 浏览 5 评论 0原文

我已经使用Processing大约两年了,我真的很喜欢它。不过,我觉得 Flash 对于编写游戏更有用,因为它更通用、更灵活。我开始觉得我不知道自己在做什么,而且我真的不明白任何概念,比如电影剪辑和舞台等等。在处理过程中,为了制作一个球,我可能会这样做:

Ball[] ballArray = new Ball[ 0 ]; //Array to store each ball in

无效设置() { 大小( 400, 400 ); 无效

绘制() { 背景(255); for( int i = 0; i < ballArray.length; i++ ) { ballArray[ i ].display(); //每个时间步运行每个球的显示代码 } }

球类 { PV矢量位置; //存储球位置的向量 球 ( int x, int y ) { 位置 = new PVector( x, y ); ballArray = ( Ball[] ) 追加 ( ballArray, this ); //将这个球添加到数组中 } 无效显示() { 填充(0); 椭圆(位置.x,位置.y); //在它的位置显示这个球 } }

无效 mousePressed() { 新球(鼠标X,鼠标Y); //在鼠标位置创建一个新球 }

这将让我可以在任何我喜欢的地方创建任意数量的实例。 我对如何在 Flash 中制作类似的小程序一无所知。 我尝试在单独的 .as 文件中创建一个“ball”类,但它给了我一个关于参数太多的错误。我也不知道如何直接在屏幕上绘制形状。

有人可以在 Flash 中制作出类似的东西,这样我就可以开始了吗? 如果我能得到一些针对闪存菜鸟的推荐读物,那就太棒了, 或者开发人员从 Java 转向 Flash。

I've been using Processing for around two years now, and I really like it. However, I feel like Flash is a bit more useful for coding games, as it's more universal and flexible. I'm starting to feel like I have no idea what I'm doing, and I really don't get any of the concepts like movie clips and the stage and so forth. In Processing, to make, say, a ball, I might make this:

Ball[] ballArray = new Ball[ 0 ]; //Array to store each ball in

void setup() { size( 400, 400 ); }

void draw() { background( 255 ); for( int i = 0; i < ballArray.length; i++ ) { ballArray[ i ].display(); //Run each ball's display code every time step } }

class Ball { PVector location; //Vector to store this ball's location in Ball( int x, int y ) { location = new PVector( x, y ); ballArray = ( Ball[] ) append( ballArray, this ); //Add this ball to the array } void display() { fill( 0 ); ellipse( location.x, location.y ); //Display this ball at its location } }

void mousePressed() { new Ball( mouseX, mouseY ); //Create a new ball at the mouse location }

And that would let me create as many instances as I like, anywhere I like.
I haven't the faintest clue how to make a comparable applet in Flash.
I've tried making a 'ball' class in a separate .as file, but it gives me an error about too many arguments. I also don't know how to draw a shape directly to the screen.

Can somebody whip up an equivalent of this in Flash so I have something to start from?
It'd also be fantastic if I could get some recommended reading for total flash noobs,
or developers moving from Java to Flash.

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

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

发布评论

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

评论(2

小…楫夜泊 2024-10-22 04:47:52

以下是一个简单的 Flash 影片/应用程序,它创建 Ball 的新实例,并在您在舞台上单击鼠标时将其添加到舞台。此外,每次创建 Ball 的新实例时,都会将其附加到名为 _ballsBall 对象数组中。

Main.as(文档类):

package
{
    import com.display.Ball;
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    public class Main extends Sprite
    {
        private var _balls:Array;

        public function Main()
        {
            init();

        }// end function

        private function init():void
        {
            _balls = new Array();

            stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);

        }// end function

        private function onStageMouseClick(e:MouseEvent):void
        {
            createBall(e.stageX, e.stageY); 

        }// end function

        private function createBall(p_x:Number, p_y:Number):void
        {
            var ball:Ball = new Ball(p_x, p_y);
            addChild(ball);
            _balls.push(ball);

        }// end function

    }// end class

}// end package

Ball.as:

package com.display
{
    import flash.display.Sprite;

    public class Ball extends Sprite
    {
        private var _radius:Number = 50;
        private var _x:Number;
        private var _y:Number;
        private var _color:uint = 0xFF0000; // red

        public function Ball(p_x:Number, p_y:Number)
        {
            _x = p_x;
            _y = p_y;

            init();

        }// end function

        public function init():void
        {
            draw();

        }// end function

        public function draw():void
        {
            this.graphics.beginFill(_color);
            this.graphics.drawCircle(_x, _y, _radius);
            this.graphics.endFill();

        }// end function

    }// end class

}// end package

我建议阅读“Roger Braunstein 的 ActionScript 3.0 Bible”一书,了解 Flash(以及 Flex)“菜鸟”。此外,即使您熟悉 ActionScript 3,它也可以作为一本很好的参考书。

此外,一旦您开始很好地掌握 ActionScript 3,您可能会考虑进入设计模式领域。将设计模式简化为一个简单的句子,可能是它们是“应对软件设计和开发中不断变化的工具”。我建议阅读“O'Reilly,William Sanders 和 Chandima Cumaranatunge 所著的 ActionScript 3.0 设计模式”。

The following is a simple flash movie/app that creates a new instance of Ball and adds it to the stage when and where you click the mouse on the stage. Also upon each creation of a new instance of Ball, its appended to an array of Ball objects called _balls.

Main.as(document class):

package
{
    import com.display.Ball;
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    public class Main extends Sprite
    {
        private var _balls:Array;

        public function Main()
        {
            init();

        }// end function

        private function init():void
        {
            _balls = new Array();

            stage.addEventListener(MouseEvent.CLICK, onStageMouseClick);

        }// end function

        private function onStageMouseClick(e:MouseEvent):void
        {
            createBall(e.stageX, e.stageY); 

        }// end function

        private function createBall(p_x:Number, p_y:Number):void
        {
            var ball:Ball = new Ball(p_x, p_y);
            addChild(ball);
            _balls.push(ball);

        }// end function

    }// end class

}// end package

Ball.as:

package com.display
{
    import flash.display.Sprite;

    public class Ball extends Sprite
    {
        private var _radius:Number = 50;
        private var _x:Number;
        private var _y:Number;
        private var _color:uint = 0xFF0000; // red

        public function Ball(p_x:Number, p_y:Number)
        {
            _x = p_x;
            _y = p_y;

            init();

        }// end function

        public function init():void
        {
            draw();

        }// end function

        public function draw():void
        {
            this.graphics.beginFill(_color);
            this.graphics.drawCircle(_x, _y, _radius);
            this.graphics.endFill();

        }// end function

    }// end class

}// end package

I recommend reading the "ActionScript 3.0 Bible by Roger Braunstein" book for flash(as well as flex) "noobs". Also, even if you are experienced with ActionScript 3, it serves as a good reference book.

Also once you start to get a good grip on ActionScript 3, you may want to consider entering the realm of design patterns. To simplfy design patterns into a simple sentence it would probably be that they're "tools for coping with constant change in software design and development". I recommend reading "O'Reilly, ActionScript 3.0 Design Patterns by William Sanders & Chandima Cumaranatunge".

囚你心 2024-10-22 04:47:52

查看 Colin Mook 的 Lost Actionscript Week End 视频教程,这将使您对 Actionscript 有一个很好的概述,并有足够的了解将您的处理知识应用到 Flash。请记住,在Processing 中,许多方法对您来说是隐藏的,您可能需要编写更多代码才能使Processing 概念适应AS3。

http://tv.adobe.com/show/colin-moocks-丢失动作脚本周末/

Check Colin Mook's Lost Actionscript Week End video tutorial , this will give you a good overview of Actionscript and enough understanding to apply your Processing knowledge to Flash. Bear in mind that in Processing a lot of the methods are hidden from you and you may have to write a lot more code in order to adapt Processing concepts to AS3.

http://tv.adobe.com/show/colin-moocks-lost-actionscript-weekend/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文