ios - Creating an SKShapeNode from CGPoint array that starts and ends on the edges of the screen rect -


okay, working on first ios game using spritekit , swift, , having hard time finding way accomplish 1 task. trying figure out how take cgpoint array contains user-made path going 1 edge of screen another. want figure out best way fill in space, perhaps skshapenode maybe theres better way. 1 important condition determine side of path filled, , should determined based on whether ball in game in area; want make area there no ball gets filled in. thinking of making skshapenode check if current position of ball inside node, realized i'm not sure how figure out how set node put against edges of screen. thing can think of adding screen corners messed if added of them, want know best way be. started writing function got stuck , have no idea now:

func fillinpolgyon(contactpoint: cgpoint) {     var framecontactpoint = contactpoint      if contactpoint.x < 3 && contactpoint.x > -3 {         framecontactpoint.x = 0     }     else if contactpoint.y < 3 && contactpoint.y > -3 {         framecontactpoint.y = 0     }     //println("ship hit bounds: \(framecontactpoint)")      var polygonpath = uibezierpath(cgpath: createtrailpath()!)     polygonpath.addlinetopoint(framecontactpoint)     polygonpath.closepath()      var polygonpathcg = polygonpath.cgpath     var balllocation = ball.position      if !polygonpath.containspoint(balllocation) {         let filledpolygonnode = skshapenode(path: polygonpathcg)         filledpolygonnode.name = filledpolygonname         filledpolygonnode.fillcolor = uicolor(red: 0, green: 1, blue: 0, alpha: 1)         addchild(filledpolygonnode)         filledpolygonnode.physicsbody = skphysicsbody(edgechainfrompath: polygonpathcg)         filledpolygonnode.physicsbody!.categorybitmask = filledpolygon         filledpolygonnode.physicsbody!.collisionbitmask = shipcategory | ballcategory         filledpolygonnode.physicsbody!.dynamic = false         var trailpoints: [cgpoint] = [contactpoint]     } } 

clearly have here sucks... doesn't fill out corners of screen , also, though have checking make sure doesn't have same contact point passed through (this function called whenever path hits walls of screen through didbegincontact function), points different anyways, resulting in creation of way many unwanted nodes, causing major performance issues. so, have ideas??? thank in advance.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -