Draw a Line with texture or sprite - iphone

In my app i required a line with some texture in it. I draw a simple line with..
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );
But I required to add texture in it.
Thanks,

Here is tutorial by Ray Wenderlich which teaches how to add textures using opengl.

Related

Exporting Pictures from Illustrator into SpriteKit

I am very new to creating graphics for sprite kit.
I have drawn some vectoring graphics (simple arrows) in illustrator. They look smooth and nice. However, when I export them as a PNG24 file, and load them into Xcode and run my game, the edges of the arrows are not smooth....?
Is this a sprite kit rendering problem? If not, how can I export pictures from illustrator and have them look the best in sprite kit?
note: My game does scroll...maybe this will effect the graphics..?
Any guidance! Thanks :)

Sprite Kit draw method like Cocos2d

Is there a sprite kit way to do the Cocos2d draw method?
-(void)draw
{
ccDrawColor4B(255, 255, 255, 255);
ccDrawCircle(mySprite.position, attackRange, 360, 30, false);
[super draw];
}
Thank you!
There's no custom OpenGL drawing in Sprite Kit (as of iOS 7.1).
While you can draw circles and other shapes using SKShapeNode, they are meant primarily for debugging purposes (analog to the ccDraw functions in cocos2d). The main problem being that shape nodes are not drawn in batches (inefficiently), unlike sprites.

How to create a CCSprite that is a Polygon shape

What I want is for the user to draw a polygon and for a sprite to be made in the shape of the polygon. I already have all the programming done for the user to create the polygon, so I can read the vertices of any image drawn. However, I seem to only be able to make sprites that are rectangular, using CGRectMake. Is there a way to create a sprite image from a file that is polygonal in shape. Like a CGPolyMake where I give it the vertices or something like that.
I don't know what shape the user will draw so I can't premake polygon sprites. Thanks for any help!
Cocos2D has no dedicated CCNode class for this purpose. You need to create a CCNode subclass and implement the draw-method yourself. That requires some knowledge about OpenGL ES.
You'll also have to triangulate the polygon so that you can fill it with a given texture.
You could use this C++ code for that: http://www.flipcode.com/archives/triangulate.cpp
This thread in the cocos2d forum is very helpful: http://www.cocos2d-iphone.org/forum/topic/8142

"Beveled" Shapes with cocos2d

I would like to draw 2d shapes like this in an iPhone app:
alt text http://www.shaggyfrog.com/junk/beveled-circle.jpg
I asked a similar question here to see if I could do it easily with Quartz, but didn't get a solution. So I got to thinking that I might be able to leverage an exsiting 2d library out there, and then I thought of cocos2d.
The goal is to draw these kinds of beveled shapes dynamically, i.e., using arbitrary colours, and possibly with the highlight/bevel drawn at an arbitrary position.
Is this possible with cocos2d?
As far as my knowledge of cocos2d goes, cocos2d will not enable you to do this in any other way than OpenGL would allow you to do. Cocos2d uses OpenGL under the hood. Cocos2d comes with no built-in set for creating such graphics.
Since the bevel is used to create a 3D effect, perhaps you shouldn't be looking at simulating it with 2D drawing, but instead use a 3D drawing library? OpenGL would certainly be capable of drawing such shapes. Cocos2d focuses on 2D drawing instead of 3D.
I'm not sure if Cocos2D would allow for a custom object to draw 3D using the underlying OpenGL mechanism. I have never tried.
Wouldn't it instead be easier to create the image in photoshop and adjust colors dynamicly? I'm not sure what you are trying to do.
You could also create a mask shape with a transparent "bevel effect" and scale that along with the image you need to have shine?
Aside from the bevel effect, if you want to "colorize" each semi-circle, you can use [sprite setColor:] or sprite.color = ccc3(r,g,b)
CCSprite *sprite = [CCSprite spriteWithSpriteSheet:sheet rect:CGRectMake(32 * idx,0,128,32)];
[sprite setColor:ccc3(CCRANDOM_0_1()*255,CCRANDOM_0_1()*255,CCRANDOM_0_1()*255)];
You would design a "white semicircle" with beveled (gray) edges. Then you can make sprites and color each separately.

OpenGL iPhone Sprite Sheet

I have a sprite sheet of images of differnet width and height, which i have the coordinates to. I need to render only a specific sprite and is wondering how to go about doing it. Can anyone help me?
If you are using OpenGL for the rendering, then I expect you will be using your sprite sheet as a texture. You can provide texture coordinates (in the range from 0 to 1) to specify which parts are used.
There is a good tutorial on texturing in opengl here...
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06