Je suis peu à peu, se déplaçant péniblement de traitement à Flash afin de développer, espérons-jeux à un public plus large. Enfin, j'ai une application de travail en Flash qui permet à l'utilisateur de cliquer pour créer des blocs qui gravitent ensuite vers la souris. J'ai fait exactement la même chose dans Processing, juste pour comparer les vitesses. Cependant, lorsque je lance la version Flash et que j'ajoute environ 15-20 blocs, le framerate chute à 5-10 FPS. Dans la version de traitement, je peux ajouter ~ 60 sans ralentissement notable. Quel est le problème, Flash?application Flash test simple fonctionne très lentement par rapport à l'applet même traitement exacte
Liens vers la source de chaque version:
Voici la source pour chacun dans le cas où vous êtes un assistant et peut aider juste en glowering le code ton sévère et dire à se comporter:
Version Flash:
blocks.fla
import flash.events.Event;
import flash.display.MovieClip;
stage.addEventListener(Event.ENTER_FRAME, onenter);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onclick);
var main = this;
var lastFrame:Number;
var Blocks:Array = new Array();
function onenter(e:Event):void
{
var time:Number = getTimer();
for(var i = 0; i < Blocks.length; i++)
{
Blocks[ i ].run();
}
FrameRate.text = String(Blocks.length) + "\n" + String(1000/(time - lastFrame));
lastFrame = time;
}
function onclick(e:MouseEvent):void
{
var block1 = new Block(Blocks, main, mouseX, mouseY);
}
Block.as
package {
import flash.display.MovieClip;
import flash.geom.Vector3D;
public class Block extends MovieClip {
var velocity:Vector3D = new Vector3D(0, 0);
var position:Vector3D = new Vector3D(x, y);
var acceleration:Vector3D = new Vector3D(0, 0);
public function Block(Blocks:Array, This, x:Number, y:Number) {
Blocks.push(this);
This.addChild(this);
position.x = x;
position.y = y;
}
public function run()
{
x = position.x;
y = position.y;
//position.incrementBy(velocity);
position.x += velocity.x;
position.y += velocity.y;
acceleration.x = stage.mouseX - position.x;
acceleration.y = stage.mouseY - position.y;
acceleration.normalize();
//velocity.incrementBy(acceleration);
velocity.x += acceleration.x;
velocity.y += acceleration.y;
velocity.x *= 0.95;
velocity.y *= 0.95;
this.graphics.beginFill(0);
this.graphics.moveTo(-10, -10);
this.graphics.lineTo(10, -10);
this.graphics.lineTo(10, 10);
this.graphics.lineTo(-10, 10);
this.graphics.lineTo(-10, -10);
this.graphics.endFill();
}
}
}
version Traitement:
sketch_mar02b.pde
Block[] blocks = new Block[ 0 ];
void setup()
{
frameRate(60);
size(550, 400);
textFont(createFont("Verdana", 20));
}
void draw()
{
background(255);
for(int i = 0; i < blocks.length; i++)
{
blocks[ i ].run();
}
text(blocks.length + "\n" + frameRate, 0, 20);
}
void mousePressed()
{
new Block(mouseX, mouseY);
}
Block.pde
class Block
{
PVector position = new PVector(0, 0);
PVector velocity = new PVector(0, 0);
PVector acceleration = new PVector(0, 0);
Block(float x, float y)
{
position.set(x, y, 0);
blocks = (Block[]) append(blocks, this);
}
void run()
{
position.add(velocity);
acceleration.set(mouseX - position.x, mouseY - position.y, 0);
acceleration.normalize();
velocity.add(acceleration);
velocity.mult(0.95);
pushMatrix();
translate(position.x, position.y);
fill(0);
rect(-10, -10, 20, 20);
popMatrix();
}
}
Merci de votre aide!
'graphics.clear();' – www0z0k