blueSquare = UIView(frame: CGRectMake(25, self.view.frame.height - 70, 70, 70))
blueSquare?.backgroundColor = UIColor.blueColor()
redSquare = UIView(frame: CGRectMake(93, 25, 90, 90))
redSquare?.backgroundColor = UIColor.redColor()
animator = UIDynamicAnimator(referenceView: self.view)
let gravity = UIGravityBehavior(items: [redSquare!])
gravity.gravityDirection = CGVectorMake(0, 1)
let boundaries = UICollisionBehavior(items: [blueSquare!, redSquare!])
boundaries.translatesReferenceBoundsIntoBoundary = true
let bounce = UIDynamicItemBehavior(items: [redSquare!, blueSquare!])
bounce.elasticity = 1
Tutorial 30 - Collision Detection
· March 20, 2015
Hi, thanks for the great explanation videos. Do you know if the UICollisionBehavior can be improved some more with any function calls to make it more accurate? I put a block station at the bottom of the screen and another block fall and bounce on it. It will just fall right through the other block if the 2 blocks hit each other at 2 pixels or under like nothing is there. Is it possible to tweak it so that they will collide at 1 pixel or less? Here's the code I'm talking about: Blue square x-position from 25 to 95, red square x-position from 93-183.
Post a Reply
Nothing to see here.
iOS Development / Swift
This forum is for questions, comments, and general discussion about iOS Development and Swift.
|Bucky Roberts Administrator|