ios - Swift 3 create game hit before time is up -
i building game have random emoji appear in top corner , emoji appear on page. player should hit emoji before time , when emoji in page appears 1 in corner going lose. know have make emoji button , created array of image. how can link both emoji invoked each time randomly array?
here code:
class viewcontroller: uiviewcontroller { @iboutlet var mybutton: uibutton! var timer:timer? @ibaction func pressed(_ sender: any) { let imagearray:[uiimage] = [uiimage(named: "1.png")!, uiimage(named: "2.png")!, uiimage(named: "3.png")!, uiimage(named: "4.png")!, uiimage(named: "5.png")!, uiimage(named: "6.png")!, uiimage(named: "7.png")!, uiimage(named: "8.png")!, uiimage(named: "9.png")!, uiimage(named: "10.png")!] let mybutton = uibutton(type: .custom) let imagearray:uiimage = mybutton.image(for: uicontrolstate.normal)! uiimage // let mybutton = uibutton(type: uibuttontype.custom) uibutton mybutton.setimage(uiimage(named: "10.png"), for: .normal) // button.frame = cgrectmake(100, 100, 100, 100) mybutton.addtarget(self, action: "btntouched:", for:.touchupinside) self.view.addsubview(mybutton) print ("hi") } func randomvaluebetween(min: int , max: int) -> int { var = min var b = max if > b { swap(&a, &b) } return int(arc4random_uniform(uint32(b - + 1))) + } }
if correctly understanding you, need randomly show image of 1 of ten images of emojis, , have trouble creating image appear onscreen. if so, need call imagearray[int(arc4random_uniform(10))]
whenever need make image appear.
Comments
Post a Comment