Flock, remove boid

匿名 (未验证) 提交于 2019-12-03 01:41:02

问题:

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 :)

回答1:

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 :)



文章来源: Flock, remove boid
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!