xcode - applying gravity of zero to only one sprite in the world -


i have world in cocos2d box2d, has gravity. in order add body each sprite, calling function , send sprite.

sprite1, has move according gravity, sprite2 has static,without gravity, until sprite1 hit it,then world forces should affect him.

how set sprite1/body gravity 0 'til other sprite hit him ?

my problem sprites using same function body:

- (void)addboxbodyforsprite:(ccsprite *)sprite {      b2bodydef spritebodydef;     spritebodydef.type = b2_dynamicbody;     spritebodydef.position.set(sprite.position.x/ptm_ratio,sprite.position.y/ptm_ratio);     spritebodydef.userdata = sprite;     spritebody = world->createbody(&spritebodydef);      b2polygonshape spriteshape;     spriteshape.setasbox(sprite.contentsize.width/ptm_ratio/2,sprite.contentsize.height/ptm_ratio/2);     b2fixturedef spriteshapedef;     spriteshapedef.shape = &spriteshape;     spriteshapedef.density = 10.0;     spriteshapedef.issensor = true;     spritebody->createfixture(&spriteshapedef);  } 

i want apply gravity @ start on sprite1, want create body sprite2 also, because later affected world.

so, after create 2 bodies @ start, how stop sprite2 falling ?
lot.

i use setactive() most, needs think setawake() want.

b2body.h

/// can disable sleeping on body. if disable sleeping, /// body woken. void setsleepingallowed(bool flag);  /// body allowed sleep bool issleepingallowed() const;  /// set sleep state of body. sleeping body has /// low cpu cost. /// @param flag set true put body sleep, false wake it. void setawake(bool flag);  /// sleeping state of body. /// @return true if body sleeping. bool isawake() const;  /// set active state of body. inactive body not /// simulated , cannot collided or woken up. /// if pass flag of true, fixtures added /// broad-phase. /// if pass flag of false, fixtures removed /// broad-phase , contacts destroyed. /// fixtures , joints otherwise unaffected. may continue /// create/destroy fixtures , joints on inactive bodies. /// fixtures on inactive body implicitly inactive , /// not participate in collisions, ray-casts, or queries. /// joints connected inactive body implicitly inactive. /// inactive body still owned b2world object , remains /// in body list. void setactive(bool flag);  /// active state of body. bool isactive() const; 

that should need.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -