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

  • Home
  • SEARCH
  • 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 8159029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:28+00:00 2026-06-06T17:47:28+00:00

I have a line, which is a sprite made by using this code CGPoint

  • 0

I have a line, which is a sprite made by using this code

CGPoint diff = ccpSub(startLocation, endLocation);
float rads = atan2f( diff.y, diff.x);
float degs = -CC_RADIANS_TO_DEGREES(rads);
float dist = ccpDistance(endLocation, startLocation);
CCSprite *line = [CCSprite spriteWithFile:@"line.png"];
[line setAnchorPoint:ccp(0.0f, 0.5f)];
[line setPosition:endLocation];
[line setScaleX:dist / line.boundingBox.size.width];
[line setRotation: degs];

line.tag = 1;
[_lines addObject:line];
[self addChild:line];

Now in my collision detection code I use the following code to create a CGRect:

        CGRect lineRect = CGRectMake(
        line.position.x - (line.contentSize.width/2), 
        line.position.y - (line.contentSize.height/2), 
        line.contentSize.width, 
        line.contentSize.height);

This of course is faulty because the line is made using an angle.

I’m trying to compare a rectangle, a square sprite, with this rectangle.
The idea is that a character is moving and the player can draw a line, if the character hits the line it’s bounces of in the opposite direction.

I have the angle, the x&y position of one side of the line and the length of the line.
How do I get the other x&y position of the other side of the line?

Hope you guys can help me out.

Thanks in advance!

  • 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-06-06T17:47:29+00:00Added an answer on June 6, 2026 at 5:47 pm

    It’s a little hard to know if I understand you correctly, but when you say “…the other x&y position of the other side of the line,” I’m assuming you meant what is the coordinates of the opposite endpoint of the line.

    If so, I believe the actual formula you may be looking for is:

    1. {x1, y1} = starting point that you already have
    2. {x2, y2] = point you’re looking to find

      • x2 = x1 + (distance * cosA)
      • y2 = y1 + (distance * sinA)

    But as I mentioned earlier, I’m a little unsure whether this would give you exactly what you needed. If you’re actually looking for the points of the vertices of the opposite side of the bounding box for the Line.png, then perhaps you could still use that formula, but change the degrees by 90 to determine the coordinates offset from the x&y that you already know.

    Anyway, I hope that at least helps put you in a helpful direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web app I have a line which looks like this: small textbox
I have one line of code which seems commented. Basically the thing I want
I have made a simple Line Chart: Which is showing 4 grid-lines at points
I have the following line of code which when compiled with GHC it goes
I have the following line of code which works fine locally, but breaks when
I have this Jquery line which finds the cell I would like to input
I have this line of javascript which creates a listing of store locations, and
I have this line which successfully select all elements of classmyclass on my page:
This is a simple one :) I have this line which works great: $listing['biz_description']
I have a script in which I have a line which does put the

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.