Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:18:13+00:00 2026-05-28T04:18:13+00:00

i am following a tutorial on a simple cocos2d game . however on that

  • 0

i am following a tutorial on a simple cocos2d game.

however on that tutorial the bullets that the user fires is only on one direction

what can i do to make it fire on all directions not just one sided?

here is the code of the direction.

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]];

all help will be greatly appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:18:14+00:00Added an answer on May 28, 2026 at 4:18 am

    Assuming you are creating the projectile at the location of your character, you just need to figure out the direction before calculating the end point.

    After adding the projectile:

    [self addChild:projectile];
    

    Add a scalar float:

    float scalarX = 1.0f;
    

    And make it negative if the touch is left of the character:

    if (offX < 0.0f) scalar = -1.0f;
    

    Then just multiply the realX by this scalar to make it point the correct way

    int realX = scalar * (winSize.width + (projectile.contentSize.width/2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following a simple tutorial that creates a class which extends from SQLiteOpenHelper and
I'm following a tutorial here It's fairly straight forward and simple, only 2 steps.
I'm doing this simple tutorial on the following website: http://www.phpeasystep.com/phptu/6.html Is the code that
I have the following class (from a simple Spring tutorial) public class CarValidator implements
I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both
I am following a tutorial for building a very simple rails app. I have
Im trying to create a simple dll file.Im following the tutorial http://java.sun.com/docs/books/jni/html/start.html when i
I'm following this tutorial to add a simple jquery tooltip. The tutorial uses three
Am following the tutorial here on creating a simple todo list app: http://www.mydroid.apnafundaz.com/2010/07/todolist-application-in-android-step-by-step-guide-with-screen-shots/ Have
I've just been following the tutorial on the CakePHP website to create a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.