Crop/Mask circular image node in sprite kit gives jagged edges
UPDATE:
Ok, so here's one solution I came up. Not super ideal but it works perfectly. Essentially, I have a to size/scale, and cut the image exactly the way it would go on the SKSpriteNode so I would not have to use SKCropNode or some variation of SKShapeNode.
I used these UIImage extensions by Leo Dabus to resize/shape the image exactly as needed. Cut a UIImage into a circle Swift(iOS)
var circle: UIImage? {
let square = CGSize(width: min(size.width, size.height), height: min(size.width, size.height))
let imageView = UIImageView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: square))
imageView.contentMode = .ScaleAspectFill
imageView.image = self
imageView.layer.cornerRadius = square.width/2
imageView.layer.masksToBounds = true
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
imageView.layer.renderInContext(context)
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
func resizedImageWithinRect(rectSize: CGSize) -> UIImage {
let widthFactor = size.width / rectSize.width
let heightFactor = size.height / rectSize.height
var resizeFactor = widthFactor
if size.height > size.width {
resizeFactor = heightFactor
}
let newSize = CGSizeMake(size.width/resizeFactor, size.height/resizeFactor)
let resized = resizedImage(newSize)
return resized
}The final codes look like this:
//create/shape image
let image = UIImage(named: "TestImage")
let scaledImage = image?.resizedImageWithinRect(CGSize(width: 100, height: 100))
let circleImage = scaledImage?.circle
//create sprite
let sprite = SKSpriteNode(texture: SKTexture(image: circleImage!))
sprite.position = CGPoint(x: view.frame.width/2, y: view.frame.height/2)
//set texture/image
sprite.texture = SKTexture(image: circleImage!)
sprite.physicsBody = SKPhysicsBody(texture: SKTexture(image: circleImage!), size: CGSizeMake(100, 100))
if let physics = sprite.physicsBody {
//add the physic properties
}
//scale node
sprite.setScale(1.0)
addChild(sprite)
So if you have a perfectly scaled asset/image, then you probably dont need to do all this work, but I'm getting images from the backend that could come in any sizes.
SKSpriteNode - create a round corner node?
To get a rounded corner node you can use 2 approaches, each of them requires use of SKShapeNode.
First way is to use SKShapeNode and set its path to be a rounded rectangle like this:
SKShapeNode* tile = [SKShapeNode node];
[tile setPath:CGPathCreateWithRoundedRect(CGRectMake(-15, -15, 30, 30), 4, 4, nil)];
tile.strokeColor = tile.fillColor = [UIColor colorWithRed:0.0/255.0
green:128.0/255.0
blue:255.0/255.0
alpha:1.0];
The other one uses sprite node,crop node and SKShapeNode with rounded rectangle as crop nodes mask:
SKSpriteNode *tile = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0.0/255.0
green:128.0/255.0
blue:255.0/255.0
alpha:1.0] size:CGSizeMake(30, 30)];
SKCropNode* cropNode = [SKCropNode node];
SKShapeNode* mask = [SKShapeNode node];
[mask setPath:CGPathCreateWithRoundedRect(CGRectMake(-15, -15, 30, 30), 4, 4, nil)];
[mask setFillColor:[SKColor whiteColor]];
[cropNode setMaskNode:mask];
[cropNode addChild:tile];
If your tiles are one solid colour, i suggest you go with the first approach.
Dynamic subversion repos via subdomains (in Apache)
In the interest of Open Source (yay!), I'll post my solution. I found no built-in solution to my problem, so I spent a few hours on the mod_dav_svn.so sources and came up with this patch:
Index: subversion/mod_dav_svn/mod_dav_svn.c
===================================================================
--- subversion/mod_dav_svn/mod_dav_svn.c (revision 1049733)
+++ subversion/mod_dav_svn/mod_dav_svn.c (working copy)
@@ -426,9 +426,14 @@
dav_svn__get_fs_parent_path(request_rec *r)
{
dir_conf_t *conf;
+ char *tokens, *subdomain, *last_str;
conf = ap_get_module_config(r->per_dir_config, &dav_svn_module);
- return conf->fs_parent_path;
+
+ tokens = apr_pstrdup(r->pool, r->hostname); // copy hostname
+ subdomain = apr_strtok(tokens, ".", &last_str);
+
+ return (const char *) apr_pstrcat(r->pool, conf->fs_parent_path, "/", subdomain, NULL);
}
Essentially, this grabs the current hostname (from the pending request 'request_rec'), slices away the first token (subdomain), and concatenates that with the proper SVNParentPath (conf->fs_parent_path) and voila! Everything works as it should. Here's my server config (notice how simple it is now):
<VirtualHost *:80 *:443>
ServerAdmin admin@domain.com
DocumentRoot "/server/www"
ServerName domain.com
ServerAlias *.domain.com www.domain.com domain.com
ErrorLog logs/domain-error_log
CustomLog logs/domain-access_log common
<Location /svn>
DAV svn
SVNParentPath /server/svn
SVNListParentPath on
</Location>
</VirtualHost>
Notes:
I hope that I used the apr_* functions correctly, if there are any caveats, I'd like some feedback :)
Tested on Centos with latest mod_dav_svn tree.
Related Topics
Type a Requires That Type B Be a Class Type Swift 4
Type of Optionals Cannot Be Inferred Correctly in Swift 2.2
Enum's Rawvalue Property Not Recognized
Swift iOS 9: Section Header Change Position After Reload Data
Swift Error: 'Sequence' Requires the Types 'T' and 'Arrayslice<T>' Be Equivalent
Difficulties to Assign Default Value to a Parameter of a Function
How to Animate Opacity Using Swift
Shows the Alert When Uitextfield's Are Full or Empty Swift
Crop/Mask Circular Image Node in Sprite Kit Gives Jagged Edges
Retrieving an Array from Firebase
Given a Function Parameter of Type [Int]; Can It Be Constrained to Not Be Empty
Difference Between Optional and Forced Unwrapping
Decode Dictionary with Random Initial Key
Why Do We Need to Set Delegate to Self? Why Isn't It Defaulted by the Compiler
Response Struct Does Not Like Codingkeys
Making Button Span Across VStack