I am developing a puzzle game.
In this game I have to draw custom lines on touch began to touch end points. For this I searched a lot, but all tutorials or links only tell us that how can we use drawLine method for line drawing.
Drawing line on touches moved in COCOS2D is one of them, but I want to draw custom lines over my background sprite. So any one can tell me that is there any method in cocos2d so that i could use my texture image for line drawing.
If this is possible then please refer me link.
Try using CCRibbon to draw a textured line
Edit to expand
I thought I'd looked into this previously :-) This code should be adaptable for your needs also non CCRibbon method (Though it won't be as smooth as multiple CCRibbon's)
Related
I want to Draw lines from one object to another object. Like a Matching object game. I want Swift language with UIKit Use. Here I attach the Sample Screenshot.
Does anyone have experience with this? then please help me.
You have a couple of choices.
You can create a custom subclass of UIView that implements the draw(_:) function to draw custom content. That view would need to big enough to enclose all of your custom drawing. You'd fill most of the view with clear, and then draw the lines you want using Core Graphics.
The other option is to use Core Animation layers. You could add a CAShapeLayer to your view's layer, set up the shape layer with the desired line thickness and color, and add a path to the layer containing the lines you want to draw. (Note that if you use CAShapeLayers, all the lines drawn in a single shape layer will be the same color. You'll need multiple shape layers in order to draw in multiple colors.)
Both approaches will require some research. Shape layers are more efficient and take better advantage of the graphics hardware on iOS devices, but using them has a fairly steep learning curve.
You should be able to google examples of both approaches. Try search phrases like "Custom drawing in a UIView" and "drawing with CAShapeLayer". I wrote a little demo app called OvalView that demonstrates how to create a UIView subclass that manages a shape layer.
Edit:
I adapted the code from my sample app into a demo called LinesBetweenViews. The new demo has a custom UIView that draws lines between any pairs of subviews you put into it.
Here is a screenshot of the demo:
If you answer my questions I can upload the demo app to Github so you can look at it.
Edit #2
See this Github repo for a sample project that draws lines between pairs of subviews.
I am trying to draw CGPaths using CAShapeLayer. I want to change the color of the parts where lines are intersected.
Following screenshots explain the goal easier.
http://a5.mzstatic.com/us/r1000/046/Purple/a3/9b/29/mzl.pocvbqdb.320x480-75.jpg
http://a3.mzstatic.com/us/r1000/037/Purple/1d/54/44/mzl.dpijulvx.320x480-75.jpg
Check #Alex Nichol's Answer on this post, How to determine intersection of CGPaths .
He developed an Open Source solution to CGPath collision detection, as well as a youtube video showing it in Action.
Hope this helps !
I'm looking for a way to draw a curve (perhaps a parametric function?) into a CGContext
The best example which I can think of is the Adobe Ideas iPad application. As the user drags their finger, the application draws lines for every touchesMoved: using CGContextAddLineToPoint. After the user picks up their finger at touchesEnded:, the application does some math and replaces all of the lines with a single, smoothed curve.
What I have is a list of CGPoints, and I am looking to draw a smooth curve which follows those CGPoints into the CGContext.
Any assistance?
I'd advise creating a CGPathRef and use the CGPathAddQuadCurveToPoint method.
Hope this helps!
I am trying to draw circles around the current location on MKMapview.I tryied many codes but however no success. can any one suggest any links which should I refer. I am new to Iphone so dont have much knowledge about Quartz 2D.
I would think the simplest method to achieve your goal would be to use a custom PNG image with transparency and set the image property of a MKAnnotationView that you add to your current MKMapView.
does anyone have a working sample project showing how can a user can draw simple sketches on the iPhone, with his finger? Something like the GLPaint, but easier, without Open GL.
Something just with the basic drawing functions. I know there was a FingerSketches sample time ago, but it appears it's no longer available.
You're right, there was a FingerSketch example; I'm not sure whether it still works, and I don't think it's a good idea to publish the entire example here. But I think you can use the Touches or MoveMe samples as a starting point to learn how to react to touches.
Basically, you have to remember the last position on each touch event, and draw a line from the last to the current position in touchesMoved and touchesEnded. As usual, FingerSketch doesn't draw directly to the screen, but to a separate drawing context, and then calls [self setNeedsDisplay] to redraw itself.