ios - SpriteKit, SKSpriteNode scale with bouncing -
i need scale skspritenode(with physicsbody) bouncing.
i don't want create 3(for example) skaction make it.
does know scale method taking account restitution property of phisicsbody?
thank in advance
my variant below
class openplayerscene : skscene { private var openfromframe: cgrect? private var logoimage: uiimage! let ballcategory: uint32 = 1 let wallcategory: uint32 = 2 convenience init(size: cgsize, openfromframe: cgrect, imageforopen:uiimage!) { self.init(size:size) self.backgroundcolor = skcolor.clearcolor() self.scalemode = .aspectfit self.physicsbody = skphysicsbody(edgeloopfromrect: self.frame) self.physicsbody?.categorybitmask = wallcategory self.openfromframe = openfromframe self.logoimage = imageforopen } override init(size: cgsize) { super.init(size: size) } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } func initlogonode (logoimage: uiimage!) { let texture = sktexture(image: logoimage!) let size = openfromframe?.size let imagenode = skspritenode(texture: texture, size: size!) imagenode.name = "logonode" imagenode.physicsbody = skphysicsbody(rectangleofsize: size!) imagenode.physicsbody?.dynamic = true imagenode.physicsbody?.restitution = 0.7 imagenode.physicsbody?.affectedbygravity = false imagenode.physicsbody!.categorybitmask = ballcategory let startposition = cgpointmake(openfromframe!.origin.x + openfromframe!.size.width / 2, self.size.height - (openfromframe!.origin.y + openfromframe!.size.height / 2)) imagenode.position = startposition self.addchild(imagenode) } override func didmovetoview(view: skview) { self.runanimation() } override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { self.runanimation() } func runanimation () { if let oldnote = self.childnodewithname("logonode") { oldnote.removefromparent() } self.initlogonode(self.logoimage) if let imagenode = self.childnodewithname("logonode") { let scalevalue = cgrectgetheight(self.view!.frame) / cgrectgetheight(imagenode.frame) let scale = skaction.scaleto(scalevalue * 0.95, duration: 0.5) let movetox = skaction.movetox(275, duration: 0.5) let group = skaction.group([scale, movetox]) let movetox2 = skaction.movetox(225, duration: 1) let scale2 = skaction.scaleto(scalevalue * 0.8, duration: 1) let group2 = skaction.group([scale2, movetox2]) let movetox3 = skaction.movetox(230, duration: 0.5) let scale3 = skaction.scaleto(scalevalue * 0.82, duration: 0.5) let group3 = skaction.group([scale3, movetox3]) let movesequence = skaction.sequence([group, group2, group3]) imagenode.runaction(movesequence, completion: { () -> void in }) } } }
Comments
Post a Comment