I want to create a game where I will have to tap an image on which the image at the top Red, I want the player to tap the red character and if the image is blue, then I want the player to want to tap the blue character. If the person is falsifying the wrong character, then I want to finish the game. The problem with my code is that whenever the picture at the top changes the color, then I would like the character that the person also has to tap the change. If that does not make sense ... then say that when I started the game, the red image was shown at the top since the red image is on top, the player should tap the red character. When the image from the red to the top of the blue color, I want the person to want to tap the blue character instead of the red character. The problem is that if I tap the blue character in this case, then the player will lose the game. How can I fix this problem?
Function view: createScene (event) local group = self.view local tap = display. Tap NewText ("Tap:", 0, 0, "Helvetica", 36). X = 100 tap. Y = ScreenTop + 20 Group: Insert (Null) Local Image Files = {"redbox.png", "bluebox.png"} local imageFile = imageFiles [math.random (2)] Local Random Image = Display.newImage (imageFile, CenterX, ScreenTop + 20) Local Button 1 = display.newImage ("redbox.png") Button 1.x = centerX Button 1.y = centerY Group: Insert (button 1) Local Button 2 = display.newImage ("Bluebox .png ") button2.x = centerX button 2.y = centerY - 100 group: insert (button 2) local function and game (event) if imageFile ==" redbox.png "then button1.x = math.random (55 , 300) Button1.y = math.random (55, 300) button2.x = math.random (55, 300) button2.y = math.r Andom (55, 300) Local imageFile = imageFiles [math.random (2)] Local RandomImage = display.newImage (imageFile, centerX, screen + 20) Other storyboard.gotoScene ("restartEasy") End-end local function EndGame2 (event) If imageFile == "bluebox.png" then press the button 1.x = math.random (55, 300) button 1.y = math.random (55, 300) button 2.x = math.random (55, 300) button 2.y = math.random (55, 300) local imageFile = imageFiles [math.random (2)] Local Random Image = Display. Other storyboard.gotoScene ("restartEasy") end-end button 1: AddEventListener ("Tap", End Game) Button 2: Ad List Listener ("Tap", End Game 2)
According to my understanding, you will use imageFile var to type type user. Use the button 1 as the red box, the red box, button 2, and after each tap, if the correct button is pressed, change the button 1 and button 2 again, and reset the image to a new random type?If so, you'll need to remove the Local keyword in the endGame and endGame2 functions. ImageFile var performs a referee, but when you declare a local image file, it overwrites an external worker, and does not work.
No comments:
Post a Comment