Nape get collision points plus effects

Source: Internet
Author: User
Tags mul

Package {ImportNape.phys.Body; ImportNape.shape.Shape; Importnape.shape.Circle; ImportFlash.display.MovieClip; ImportFlash.utils.getDefinitionByName; ImportNape.callbacks.CbType; ImportNape.callbacks.PreListener; ImportNape.callbacks.InteractionType; ImportNape.callbacks.PreCallback; ImportNape.dynamics.CollisionArbiter; Importnape.geom.Vec2; ImportNape.callbacks.InteractionListener; Importnape.callbacks.CbEvent; ImportNape.callbacks.InteractionCallback; ImportNape.phys.BodyType; ImportNape.shape.Polygon; Importnape.dynamics.Contact; Importnape.dynamics.ContactList;  Public classMainextendsBasemain { Public functionMain () {Super({gravity:{x:0,y:0}}); }                Private var_ccbtype:cbtype=NewCbtype (); Private var_rcbtype:cbtype=NewCbtype (); Override protectedfunctionCreatebodies ():void {            //some rigid bodies for collisions             for(vari:int=0;i<20;i++){                varB:body; if(Math.random () >0.5) B=createbox (50,2,stage.stagewidth*math.random (), stage.stageheight*math.random ()); ElseB=createcircle (25,stage.stagewidth*math.random (), stage.stageheight*math.random ()); B.rotation= 2*math.pi*Math.random (); B.type=bodytype.static; B.space=_space; }                        //round            varC:body = Createcircle (20,stage.stagewidth>>1,stage.stageheight>>1);            C.cbtypes.add (_ccbtype); C.space=_space; C.velocity.setxy (500,500); _space.listeners.add (NewInteractionlistener (Cbevent.begin,interactiontype.collision,_ccbtype,cbtype.any_body,circlehitbeginhandler                        )); //Rectangle            varR:body = Createbox (40,40,stage.stagewidth>>1-100,stage.stageheight>>1);            R.cbtypes.add (_rcbtype); R.space=_space; R.velocity.setxy (-500,-500); _space.listeners.add (NewInteractionlistener (Cbevent.begin,interactiontype.collision,_rcbtype,cbtype.any_body,boxhitbeginhandler)); }                Private functionCirclehitbeginhandler (Cb:interactioncallback):void{            varColarb:collisionarbiter = cb.arbiters.length>0?cb.arbiters.at (0) as Collisionarbiter:NULL; if(!colarb)return; //Trace ("Circle Collision point:" +colarb.contacts.length);//always have only one bump            varHITPOS:VEC2 = colArb.contacts.at (0). Position;            AddEffect (HITPOS.X,HITPOS.Y); //Bounce            varNORMAL:VEC2 =Colarb.normal; Cb.int1.castBody.velocity.Set(Normal.mul (500)); }                Private functionBoxhitbeginhandler (Cb:interactioncallback):void{            varColarb:collisionarbiter = cb.arbiters.length>0?cb.arbiters.at (0) as Collisionarbiter:NULL; if(!colarb)return; //Trace ("Rectangle Collision point:" +colarb.contacts.length);//Multiple collision points appear            varShape2:nape.shape.Shape = ColArb.shape2.body = = Cb.int2.castBody?ColArb.shape2:colArb.shape1; //find the point of a real collision            varContact:contact =gethitshapecontact (colarb.contacts,shape2); if(Contact) {varHITPOS:VEC2 =contact.position; if(Hitpos) AddEffect (HITPOS.X,HITPOS.Y); }            //Bounce            varNORMAL:VEC2 =Colarb.normal; Cb.int1.castBody.velocity.Set(Normal.mul (500)); }                Private functiongethitshapecontact (contacts:contactlist,shape:nape.shape.shape): contact{varI:int =contacts.length;  while(--i>=0){                if(Shape.contains (contacts.at (i). Position))returncontacts.at (i); }            return NULL; }                Private functionAddEffect (x: NumberY: Number):void{            var_class:class = Flash.utils.getDefinitionByName ("Effect") as Class; varEffMovieClip= (New_class ()) asMovieClip; Eff.x=x; Eff.y=y;  This. AddChild (EFF); }    }    }

Source:

Http://yunpan.cn/cd8GasJG5rkUp Access Password 6873

Nape get collision points plus effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.