gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:46:34 24 4
gpt4 key购买 nike

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

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

<p>void setup()
{
size( 400, 400 );
}</p>

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

<p>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
}
}</p>

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

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

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

最佳答案

下面是一个简单的 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

球.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

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

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

关于java - 从Processing迁移到Flash CS5,我该如何开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4847405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com