Lost decade games tutorial




















For that reason we just want to store the user input for later instead of acting on it immediately. To accomplish this we simply have a variable keysDown which stores any event's keyCode. If a key code is in the object, the user is currently pressing that key. The reset function is called to begin a new game, or level, or whatever you'd like to call it.

It places the hero the player in the center of the screen and the monster somewhere randomly. This is the update function and is called every single interval execution. The first thing it does is checks the up, down, left, and right arrow keys to see if the user has pressed them. If so, the hero is moved in the corresponding direction. What may seem odd is the modifier argument passed into update. You'll see how this is referenced in the main function, but let me first explain it here.

If exactly one second has passed, the value will be 1 and the hero's speed will be multiplied by 1, meaning he will have moved pixels in that second. If one half of a second has passed, the value will be 0. And so forth. This function gets called so rapidly that the modifier value will typically be very low, but using this pattern will ensure that the hero will move the same speed no matter how fast or slowly! Now that we've moved the hero according to the player's input, we can check to see if it caused anything to happen.

If there was a collision with the hero and monster, that's it! That's pretty much the game. Games are more fun when you get to see the action going down, so let's draw everything to the screen. Here is what the game looks like click here to play it :. The structure of your game folder should look like this with the images folder containing the above three PNG images :. If you want to change the keys that are pressed on the keyboard to control the hero character , you can look up the key codes that can be used here.

On the same level as Resources , expand Classes by clicking the arrow icon. Then, in the list to the right under "File Name", double-click MainMenu. In Interface Builder, find the Library window and select the Objects tab. Scroll down to find a row labeled "Web View - A Coca WebView" hint: you can type "webview" into the text box at the bottom of this window to filter the results and drag it into the WebViewExample window.

More info on this in future tutorials. Find the "MainMenu. Find the tools window the one with six icons at the very top, it should be labeled "Web View Example App Delegate Identity". Switch to the "Connections" tab by pressing the second icon from the right -- it's a blue circle with a white arrow inside. Look under "Outlets". There should be only one row labeled "window". You'll come back to this in a moment. Go back to Interface Builder.



0コメント

  • 1000 / 1000