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 3602886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:48:11+00:00 2026-05-18T20:48:11+00:00

How to Stroke a line in Cocos2d? Is it possible to convert the stroke

  • 0

How to Stroke a line in Cocos2d? Is it possible to convert the stroke into sprite?

  • 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-18T20:48:12+00:00Added an answer on May 18, 2026 at 8:48 pm

    You can draw lines by overriding the “draw” method, which would in turn result in the “stroke” effect you appear to be after. The question is a bit lacking in detail, so I’ll try to make the best of it.

    Let’s say you want to draw a simple line on the screen, you could do the following:

    @interface MyLine: CCNode
    {
      CGRect lineRect;
    }
    @property(nonatomic) CGRect lineRect;
    +(id)lineWithRect:(CGRect)rect;
    @end
    
    @implementation MyLine
    @synthesize lineRect
    +(id)lineWithRect:(CGRect)rect
    {
      MyLine *node = [MyLine node];
      [node setRect: rect];
      return node];
    }
    -(void)draw
    {
      glEnable(GL_LINE_SMOOTH);
      ccDrawLine(ccp(rect.origin.x, rect.origin.y), ccp(rect.size.width, rect.size.height));
    }
    @end
    

    With this class, you’d be able to call:

    MyLine *line = [MyLine lineWithRect:CGRectMake(0, 0, winSize.width, winSize.height)];
    

    Which would then draw a line from the bottom left of the screen to the top right of the screen.

    You would not convert this into a “sprite”, as it would be unnecessary to do so – but you could then treat this as if it were any other graphic in your game, as it is now it’s own subclass of CCNode … containing all the goodness that comes with that (positioning, etc).

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

Sidebar

Related Questions

I'm trying to stroke my path by writing below line of code but its
I'm trying to draw a line on canvas and project it into a map
I use CGContextStrokePath painted on a straight line in a white background picture, stroke
I want to write a skin for BorderContainer with dashed line stroke. I haven't
I am using line array in that all lines having same stroke. but at
I want to add a new line into the svg when, the add button
This is the Line i'm using: <s:Line x=25 y=22 width=42> <s:stroke> <s:SolidColorStroke color=black weight=2
Does Unicode store stroke count information about Chinese, Japanese, or other stroke-based characters?
I want to stroke a path using a .png that I have but I
Whenever I stroke a path with rounded corners on iPhone, the rounded corners are

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.