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 05-13-2010, 08:47 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 31
thyrgle is on a distinguished road
Question How to display ccDrawLine? (Cocos2d)

So, lets just say I have this -
Code:
	ccDrawLine(ccp(0.0, 0.0), ccp(1.0,1.0));
How do I display that? I mean I've tried assigning a variable to ccDrawLine() and displaying it on the screen using addChild... but that doesn't work because ccDrawLine() is void... How could I display ccDrawLine(ccp(point, point), ccp(point,point)) on the screen?
thyrgle is offline   Reply With Quote
Old 05-13-2010, 09:47 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

The function ccDrawLine does not return an object of any kind - it just draws. You should use it inside the draw method of a custom object of your own that inherits from CCSprite or CCNode:

Code:
-(void)draw: (ccTime) delta
{
	glColor4f(0.8, 1.0, 0.76, 1.0);
	glLineWidth(6.0f);
	ccDrawLine(ccp(0.0, 0.0), ccp(1.0,1.0));
}
__________________

Free Games!
smasher is offline   Reply With Quote
Old 05-13-2010, 11:25 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 31
thyrgle is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
The function ccDrawLine does not return an object of any kind - it just draws. You should use it inside the draw method of a custom object of your own that inherits from CCSprite or CCNode:

Code:
-(void)draw: (ccTime) delta
{
	glColor4f(0.8, 1.0, 0.76, 1.0);
	glLineWidth(6.0f);
	ccDrawLine(ccp(0.0, 0.0), ccp(1.0,1.0));
}
Hi, thank you for the quick response, but what is the (ccTime) delta for? Also, do I need to just override this method or do I need to call it or something because sorry if I sound newbish here, but copy and pasting it does not work.

Last edited by thyrgle; 05-13-2010 at 11:32 PM.
thyrgle is offline   Reply With Quote
Old 05-14-2010, 07:22 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 31
thyrgle is on a distinguished road
Default

Never mind actually, I got it to work... I just couldn't see the line...
thyrgle is offline   Reply With Quote
Old 05-13-2011, 08:43 PM   #5 (permalink)
***
 
huvan's Avatar
 
Join Date: May 2011
Location: Ho Chi Minh
Age: 25
Posts: 23
huvan is on a distinguished road
Default

Quote:
Originally Posted by thyrgle View Post
Never mind actually, I got it to work... I just couldn't see the line...
The correct code:
-(void)draw
{
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(6.0f);
ccDrawLine(ccp(0.0, 0.0), ccp(100.0,100.0));
}
huvan is offline   Reply With Quote
Old 08-05-2011, 02:04 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
mjmythili is on a distinguished road
Unhappy How to avoid continous lines while we use in CCTouches Moved

i have given 4 points. In ccTouches Moved, i want to draw lines between 1 and 2, then from 3 to 4 but not between 2 and 3.

if i touch at first point and then if i move to second point, i want to draw line between 1 and 2. Similarly if i touch at 3rd point and then if i move to 4th point, i want to draw line between 3 and 4.

I have seen the line connecting 2nd and 3rd point. l How to avoid that.
mjmythili is offline   Reply With Quote
Old 08-30-2011, 11:55 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 1
smase is on a distinguished road
Default

Quote:
Originally Posted by thyrgle View Post
So, lets just say I have this -
Code:
	ccDrawLine(ccp(0.0, 0.0), ccp(1.0,1.0));
How do I display that? I mean I've tried assigning a variable to ccDrawLine() and displaying it on the screen using addChild... but that doesn't work because ccDrawLine() is void... How could I display ccDrawLine(ccp(point, point), ccp(point,point)) on the screen?
You have to override the draw method
here is an example for using ccdrawpoint and ccdrawline in cocos2d
smase is offline   Reply With Quote
Reply

Bookmarks

Tags
ccdrawline, cocos2d

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: 312
11 members and 301 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, jbro, n00b, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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