Motion paths drawn by finger [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am interested in making path with finger (like connecting objects) between two elements. I am not sure how would I start on this.
I know that I could use Bezier path to create lines, but I am not sure how to create that line with finger. Does anyone have some good example?
I tried to google it, but I can't find anything like that made.
Thanks

I answered a question recently about slow/laggy performance on a similar setup. I.E. Drawing UIBezierPaths in CALayer. The answer contains a subclass of UIView which you can drop into a storyboard and will pretty much get you started. The header file is not shown in the answer, but it is literally a subclass of UIView (just add a UIView Subclass to your project). You should be able to copy the rest into your implementation file. Obviously you'll want to take out the performance testing code.
touchesMoved drawing in CAShapeLayer slow/laggy
If you simply want to Add a single line, you just need to get the starting point in touchesBegan, and build the path in touchesMoved. The commitCurrentRendering simply renders the touch points accumulated, then clears the UIBezierPath. This improves the performance as there wass a notable slowdown when UIBezierPath reached around 2000 points (touchesMoved will feed you a succession of points as your finger moves).

Related

iOS: How to partially change the color of text [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was playing with iOS built-in Compass app and the UI do make me curious.
Here is the interesting part:
The color of text (even the circle) can be partially and dynamically changed.
I have made a lot of search, but the results are all about attributed string. How to implement the effect like this?
Edited:
I have tried to add two UILabels (whiteLabel and blackLabel) as whitelabel at the bottom and blackLabel at the top with the same frame. Then I set the circle as the mask of blackLabel.
The problem is 'whiteLabel' is totally covered by blackLabel, and if the circle do not intersect with 'blackLabel', both labels are not visible.
I imagine that there are two "14" labels in the same place. The bottom one is white and unmasked, and the top one is black and has a layer mask that contains two circles, so it's only visible where the circles are.
Achieving this has most probably nothing to do with NSAttributedStrings, like Woodstock said.
I'd say it's the UILabel's layer that is recolored live, depending on what other layer it intersects with, and the overlaying area of said intersection.
Once you figure those common points, you just apply a mask that inverts colors from there.
Now it's a little bit more complicated than that since there appears to be two circles (hence two layers to find intersections with), but in the end, it's "just a list of coordinates" that the label's coordinates intersects or not.
That could be an interesting exercise ; it would probably take me a decent amount of tries to mimic that behaviour, but I'm pretty confident my reasoning is on point. (get it? :o)

How can I throw in sprites from both sides of the screen in Swift? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to apply a sort of impulse onto a sprite and have it thrown onto the screen from the side. However, when it is after the screen I want the impulse to stop and for the regular physics to be applied to it, so I would be able to drag it around. Its difficult to explain but if anyone can help out it would be very much appreciated. Thanks!
Apple docs show that a we can influence the physicsBody of a sprite with these instance methods:
- applyForce:
- applyTorque:
- applyForce:atPoint:
- applyImpulse:
- applyAngularImpulse:
- applyImpulse:atPoint:
As for "throwing it on the screen from the side", you can have the sprite spawn outside your current skViews bounds, and have the force be applied to it accordingly (if the sprite is located outside the north side of the screen, you'll want to applyImpulse downward).
With respect to "regular physics" upon entrance of the skView, you can have a check in update:(CFTimeInterval)currentTime for those types of sprites entering the skViews frame OR define a protocol within your sprite's class, and have your SKScene subclass conform to that protocol; then have your sprite fire a method when entering a certain frame (skView.frame), which your SKScene will be able to respond to. You can then apply counter forces or impulses to that sprite.

"Collision Map" in SpriteKit [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm building a 2D game using SpriteKit and this is what I would like to achieve.
Imagine a vertically scrolling SKSpriteNode which represents a tall building. Building is represented using simple image and has a physics body set with + (SKPhysicsBody *)bodyWithTexture:(SKTexture*)texture size:(CGSize)size; (introduced with iOS 8) so it is closely following the building's path.
Some parts of the building are special. Colliding with those parts should be yielding a special collision action. For example, touching the wall of the building would fire an action 1 but touching any of the windows would fire an action 2.
What I haven't been able to do is in some way define those "special blocks" of the building.
I was thinking about making some kind of a "Collision Map" for each of the building's sprite images which would be basically a transparent image with non-transparent blocks determining a collideable parts of the building. Simple example shown bellow (left: building image, right: collision map image):
The problem with this approach is that when setting a SKPhysicsBody on a "Collision Map" image like the one above, the body is not applied to all blocks but it wraps around just one of those separate blocks. In other words: one physics body can be applied to only one, continuous block in image.
To conclude, I would like to know which approach are you using when determining non-continuous collision maps.
P.s.: building's SKSpriteNode is represented with multiple unique texture images which are scrolling vertically, one after another.
Thank you in advance.
Just an idea:
Can't you use two Sprites for the building which are positioned at the same place:
- one represents the physics body of your building (the left one from your image)
- invert your collision map image to get a single physics body block. The special areas should overlap the non special area by one pixel
Hope you understood what I mean. It's just an idea

What is the difference between CGPath and UIBezierPath()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
At the moment, I'm trying to work out how to animate a custom button which I have an image of and have the coordinates of but I've found that you can create a button/object both by using the CGPath class or the UIBezierPath class. Can somebody please tell me what the difference between the two are?
CGPath is an opaque type from the CoreGraphics library, while UIBezierPath is an Obj-C class in UIKit. UIBezierPath is a wrapper around CGPath (you can convert between them easily), with a more object-oriented interface and a few convenience methods. Using CGPath may be marginally faster as it doesn't have to go through Obj-C (although who knows how it works with Swift) and it has more advanced functions like CGPathApply. Importantly, UIBezierPath conforms to NSCoding, meaning you get serialization/deserialization for free.
tl;dr: use UIBezierPath unless you have some reason not to.
To expand a bit on what jtbandes wrote, there's another distinction: CGPath is just a mathematical description of a shape. It has no drawing-specific properties or capabilities. Instead, drawing properties are part of the CGContext as is the actual drawing operation. You set things like color, line width, etc. on the context before the drawing operation, but those are not part of the path itself.
By contrast, UIBezierPath has drawing properties and drawing operations.

iOS - Change CCFile Sprite Image Programmatically [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm using Cocoa2Ds to make a game for iOS. I know it's probably simple, but is there a way to change a CCFile's sprite images programmatically?
I created a hero sprite object and then dragged it into the main scene utilizing SpriteBuilder.
Ultimately, I would like to change the hero sprite object to another image that is animating (moving) as well.
You asked about changing a "CCFile" image, but I assume you meant "CCSprite" image. If so, changing a sprite image can be done by first creating a sprite frame and then assigning it to the sprite:
CCSpriteFrame * frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:#"NameOfFrame"];
[mySprite setDisplayFrame:frame];
For this to work the image you are referencing must already be loaded into memory, such as through a sprite sheet:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"SpriteSheetFileName.plist"];
You mentioned animation. If you are trying to animate a sprite, and all the images are loaded into memory and they have the same name except for a sequential number appended to them, then you can have a sprite move through these images, thus animating it, as follows:
NSString * animateCycle = [NSString stringWithFormat:#"ImageName 00%%02d.png"];
The image names would be along the lines of "ImageName 0001.png", "ImageName 0002.png", and so on.
CCActionInterval * action = [CCAnimate actionWithSpriteSequence:animateCycle numFrames:8 delay:.1 restoreOriginalFrame:YES];
[mySprite runAction:action];
This will cycle through the images based on the designated delay.
I hope this helps.

Resources