官术网_书友最值得收藏!

You'll never go hungry again

A function is a piece of the script that can be executed, or called, over and over again. It's like having a sandwich that you can eat as many times as you want. We use functions to organize our code, and to house lines of code that we may need more than once.

The function we used is called Update . Just as there's an ongoing physics process in the background of our game that we can tap into to make our ball move and bounce, there's an ongoing Update loop as well. Update is eaten (or called) again and again and again while our game runs. Any script lines, or statements, that we put inside the Update function tap into that loop.

Notice the way the Update function is declared. On a restaurant menu, we might declare that our Street-Fightin' Hoagie is a scrumptious offering of mile-high pastrami with lettuce, tomatoes, bacon, and cucumbers, topped with a fried egg and slathered with mustard. We can declare a function much more simply. It starts with the word function, and adds the function name and a pair of round brackets. If our hoagie was a JavaScript function, it might look like this:

function Hoagie() {
}
主站蜘蛛池模板: 淮阳县| 牟定县| 伊金霍洛旗| 大埔区| 肇庆市| 拉萨市| 宣化县| 云梦县| 宜良县| 顺平县| 武宣县| 新巴尔虎左旗| 台东市| 绥芬河市| 鹤壁市| 类乌齐县| 介休市| 东乌珠穆沁旗| 汝南县| 云浮市| 泌阳县| 准格尔旗| 阜阳市| 靖江市| 吉安县| 东台市| 昔阳县| 宜宾市| 雷州市| 塔河县| 自治县| 临江市| 绥江县| 中江县| 兴山县| 嘉兴市| 武胜县| 合肥市| 信宜市| 景洪市| 贺兰县|