iphone - How to move an Object using Slingshot in different Angles? -


i'm beginner in iphone application development , xcode , i'm developing small game using box2d has slingshot effect. need moving body in respective angles when sling shot used. slingshot drawn using ccdrawline , body placed on it.

in project object moves haphazardly in different directions when sling shot used. know how fix this?

my code:

draw slingshot:

-(void)draw {     //nslog(@"in dra");     //gldisable(gl_texture_2d);     //gldisableclientstate(gl_color_array);     //gldisableclientstate(gl_texture_coord_array);      _world->drawdebugdata();      glenable(gl_texture_2d);     glenableclientstate(gl_color_array);     //glenableclientstate(gl_texture_coord_array);      glcolor4f(0.6, 0.4, 0.2, 1.0);     gllinewidth(4.0f);      //glenable(gl_line_smooth);     ccdrawline( ccp(80, 75),ccp(pt1,pt2));     ccdrawline(ccp(pt1,pt2), ccp(240,75));     ccdrawline(ccp(80,75),ccp(80,0));     ccdrawline(ccp(240,75),ccp(240,0));     } 

place object on sling:

-(void)addsprite2 {     stone=[ccsprite spritewithfile:@"rock.png"];     stone.position=ccp(160,80);     stone.tag=1;     [self addchild:stone]; } 

i'm trying create , add angles manually.

angle creation:

    if (stone.position.y < 80 && stone.position.y >= 70)     {         ft = abs(tp2)/ptm_ratio;     }      else if(stone.position.y < 70 && stone.position.y >=60)     {         ft = (abs(tp2)+90)/ptm_ratio;     }      else if(stone.position.y < 60 && stone.position.y >= 50)     {         ft = (abs(tp2)+110)/ptm_ratio;     }      else if(stone.position.y < 50 && stone.position.y >= 40)     {         ft = (abs(tp2)+140) 

you can use bezier curve implement projectile curve effect in 2d space. set the first , second control points , end point depending on pull distance.

this simplest way implement projectile curve.

also move object may use touchesmoved function , set position of object same of touchesmoved point.

object.position = pulling.position; 

this allow move object move finger.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -