Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-05-2012, 02:46 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 19
francis is on a distinguished road
Default User Moving while shooting projectiles

i am experimenting on this open source app game with an old version of cocos2d

i have successfully inserted enemies and have collision detected also... now i want

is to put on some projectiles to make it look more awesome however i tried ray's tutorial

This one

but the projectiles still aren't shooting..

PS: my target is moving or jumping rather..

here is what i did:

Code:
-(void)TouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
   AtlasSprite *bird = (AtlasSprite *) [spriteManager getChildByTag:kBird];

   UITouch *touch = [touches anyObject];
   CGPoint location = [touch locationInView:[touch view]];
   location = [[Director sharedDirector]convertCoordinate:location];

   CGSize winSize = [[Director sharedDirector]winSize];
   Sprite *projectile = [Sprite spriteWithFile:@"psn.png"];
   projectile.position = ccp(bird.position.y,bird.position.x);

   int offX = location.x - projectile.position.x;
   int offY = location.y - projectile.position.y;

   [self addChild:projectile];

   int realX = winSize.width + (projectile.contentSize.width/2);
   float ratio = (float) offY / (float) offX;
   int realY = (realX *ratio) + projectile.position.y;
   CGPoint realDest = ccp(realX, realY);

   int offRealX = realX - projectile.position.x;
   int offRealY = realY - projectile.position.y;
   float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
   float velocity = 480/1;
   float realMoveDuration = length/velocity;

   [projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest],
                     [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
}
i hope someone could help and that would be great
francis is offline   Reply With Quote
Reply

Bookmarks

Tags
cocos2d, collision, pro

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 404
12 members and 392 guests
buggen, EvilElf, guusleijsten, j.b.rajesh@gmail.com, LunarMoon, morterbaher, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0