绒毛,去除BOID绒毛、BOID

由网友(谁念西风独自凉)分享简介:这是我的羊群 code,为什么removeBoid无法正常工作公共职能羊群(){ArrayList的=新的Array(); //初始化ArrayList中}公共职能FRUN():无效{对于(VAR我:= 0; I< ArrayList.length;我++){ArrayList的[I] .brun(ArrayLi...

这是我的羊群 code,为什么removeBoid无法正常工作

 公共职能羊群(){
        ArrayList的=新的Array(); //初始化ArrayList中}

    公共职能FRUN():无效{
        对于(VAR我:= 0; I< ArrayList.length;我++){
            ArrayList的[I] .brun(ArrayList的); //传递boids每个BOID的整个列表单独}}

    公共职能addBoid(二:京东方投资):无效{
        ArrayList.push(B);
        的addChild(B); }
    公共职能GRUN():无效{
        对于(VAR我:= 0; I< ArrayList.length; I  - ){

        ArrayList的[I] .brun(ArrayList的); //传递boids的整个列表的每个BOID单独
        }}
 公共职能removeBoid(二:京东方投资):无效{
        ArrayList.push(B);
        removeChild之(二);}}}
 

我是新中航闪存AS3 Android的:)

解决方案

 公共职能removeBoid(二:京东方投资):无效{
    ArrayList.push(B);
 

那么你实际上是添加删除它一遍,而不是!你应该这样做:

  ArrayList.splice(ArrayList.indexOf(B),1);
 
如何区分绒布的好坏 绒布的特点作用

除了这个,我不明白为什么你传递整个羊群,但是这似乎是你需要做的事情:)

this my Flock code, why removeBoid not function

    public function Flock(){
        ArrayList = new Array();// Initialize the arraylist     }

    public function frun():void {
        for (var i:int = 0; i < ArrayList.length; i++){
            ArrayList[i].brun(ArrayList);// Passing the entire list of boids to each boid individually}}

    public function addBoid(b:Boid):void{
        ArrayList.push(b);
        addChild(b);        }
    public function grun():void{
        for (var i:int = 0; i < ArrayList.length; i--){

        ArrayList[i].brun(ArrayList);// Passing the entire list of boids to each boid individually
        }}
 public function removeBoid(b:Boid):void{
        ArrayList.push(b);
        removeChild(b);}} }

i am new in flash as3 in Air for Android :)

解决方案

public function removeBoid(b:Boid):void {
    ArrayList.push(b);

Well you are actually adding it AGAIN instead of removing it! You should do this:

ArrayList.splice(ArrayList.indexOf(b), 1);

Other than this I don't understand why you pass the entire flock, but this seems like something that you need to do :)

阅读全文

相关推荐

最新文章