swift3 - How can I call a class method without creating a new instance of the class? -


let me try explain situation.

i attempting create basic tower defense game. have gamescene file , tower file. in tower file, specify tower , range. in gamescene file, create tower. when tap tower, range appears. want range disappear when touch outside of tower (which works) , when touch different tower (doesn't work).

my problem is, touch on tower not recognized in gamescene, having hard time telling game scene dismiss old tower's range when touch new tower.

here code displays range when tower tapped (if statement determines if tap lands on existing range, in case range should go away):

tower.swift

if (location.y > theight || location.y < -theight) || (location.x > twidth || location.x < -twidth) {     dismissrange() } else {     showrange() } 

now, handle taps outside of existing towers, use:

gamescene.swift

func deselecttowers() {     self.enumeratechildnodes(withname: "placedtower1", using: {         node, stop in         let tower = node as! tower         tower.dismissrange()     }) } 

both of work. tricky bit when tower selected after tower selected. have tried

tower.swift

if (location.y > theight || location.y < -theight) || (location.x > twidth || location.x < -twidth) {     dismissrange() } else {     gamescene().deselecttowers()     showrange() } 

i searched around bit find out why wasn't working, , discovered because creates new instance of gamescene, means there no towers enumerate when call function.

how can call function influence current gamescene? if isn't possible, have techniques/tricks/suggestions adopt achieve goal through method?

thank you!


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -