ios - Updating Random Integers (swift, spritekit) -
i have random integer needs update every second, issue random int cannot defined outside of function because random int range of 0 screen size
var randomx = uint32(self.size.width)
i cannot use self.size.width outside of function. @ first thought maybe not updating because 1. declared in function didmovetoview() , 2. declared using "let" instead of "var". if declare in function updates every second, variable cannot used outside of function huge problem.
you can declare var
instance variable of class (outside method), update in method, , use anywhere else in instance of class.
class rtest { var randomx: uint32 init() { self.randomx = 2; } func rx5()->uint32 { return self.randomx * 5 } }
Comments
Post a Comment