Quick Start Guide Part2

Modifying Your First Program

Before moving on to more advanced game development examples, let's make some simple changes to your program.

As you may have guessed, the second line of this program sets the color of the text that you created in the first line:

修改第一個程序

然後再進入到更先進的遊戲開發實例,讓我們做一些簡單的修改你的程序。

正如您可能已經猜到了,第二行程序設置文本的顏色,你創建的第一行

myText:setTextColor( 255,0,0 )

The color is specified by three numbers, indicating red, green and blue, with values ranging from 0 to 255. On this scale, the color black would be ( 0,0,0 ), white would be ( 255,255,255 ), and our current code specifies pure red ( 255,0,0 ).

指定顏色三個數字,顯示紅色,綠色和藍色的,值從0到255。在此範圍內,黑色為(0,0,0),白色將是(255,255,255),我們目前的代碼指定紅色(255,0,0)。

 

Go back to your file in TextWrangler, and change the second line to read as follows:

回到您的文件TextWrangler並更改第二行如下

myText:setTextColor( 150,25,180 )

Now switch back to the Corona Simulator, and choose "File > Relaunch". Your text should now be a deep purple:

現在切換電暈模擬器,選擇“文件“>重建經濟活力您的文字現在應該深紫色

Feel free to try other color values to see what happens. 

To test your changes quickly, you can press Command-R on the Mac keyboard to relaunch Corona instantly, rather than using the "Relaunch" menu item.

隨意嘗試其他顏色值,看看會發生什麼。


要測試你的變化快,可以按Command- R的Mac鍵盤上的電暈立即重新啟動,而不是使用“重振“菜單項。

Now let's look at the first line, which has a more complicated function:
 

現在讓我們看看在第一線,具有更複雜的功能:

myText = display.newText( "Hello, World!", 20, 40, native.systemFont, 36 )

This line creates a new piece of text and gives it the name "myText", a name that is then used by the line below. 

Within the text creation function, the first item controls what the text should say, which in this case is "Hello, World!" 

The next two numbers control the horizontal and vertical position of the text on the screen.

The next item specifies the font. In this case we've used the name native.systemFont, which automatically refers to whichever font is standard on the current device. For example, the iPhone's default font is Helvetica.

The final number is the font size. Note that many Corona functions you'll learn in the future will have optional values, but in this case, all five values must be specified.

 

行創建一個新的作品的文本,並將其命名為“MyText的“,一個名稱,然後使用下面的行

文本的創作功能,第一個項目控制什麼的文字應該說在這種情況下是“你好,世界!“

接下來的兩個數字控制水平和垂直位置的文字在屏幕上。

下一個項目指定的字體。在這種情況下,我們所使用的名稱 native.systemFont,自動字體為準當前設備上的標準例如,iPhone的默認字體為黑體

這個最後的數字是字體的大小。請注意,許多電暈功能,您將學習在未來將有可選值,但在這種情況下,所有五個值必須被指定。

 

Instead of the standard font, you can specify any font you have available. Try changing the first line to the following:

取而代之的是標準字體可以指定任何字體可用。試著改變第一線如下:

myText = display.newText( "Hello, World!", 20, 40, "Zapfino", 36 )

Press Command-R in the Corona Simulator to see the new font:

按Command- R在電暈模擬器看到新字體:

Finally, add the following two lines at the bottom of your program:

最後,添加以下兩行底部的程序

myText.yScale = 3.0
myText.rotation = 45

Press Command-R in the Corona Simulator to see the changes:

按Command- R在電暈模擬器看到的變化

 

The piece of text you created is an example of what Corona calls a display object, which simply refers to any object displayed on the screen, including text, lines, boxes, images, and even animations. All Corona display objects can be controlled by standard parameters, such as the yScale and rotation parameters above. Other standard display object parameters include xScale, alpha, and various other useful properties. If you'd like a complete list, see this documentation.

 

 

正如你可以看到,該文本已被拉伸到原始高度的三倍,並旋轉至45度。

這件作品文本創建的一個例子是什麼電暈來電顯示對象,它僅僅是指任何物體在屏幕上顯示,包括文字,線條,框,圖片,甚至動畫。所有電暈顯示對象可控制標準參數,如yScale旋轉參數以上。其他標準參數包括XScale的顯示對象,Alpha和其他各種有用的屬性如果想要一個完整列表,請參閱此文檔。

What is a Corona Project?

At minimum, a Corona project is just a folder containing a text file named "main.lua". You'll notice that all the Corona sample code follows this pattern, although most of the samples contain other files in addition to main.lua.

This special filename "main.lua" is required to tell Corona where to start. This main file may in turn load other code files, or other program resources such as sounds or graphics. The file extension ".lua" indicates that the file is written in Lua, which is the language you'll use to create apps in Corona.

Lua is a simple yet very powerful scripting language. Even if you have little or no coding experience, you'll find that Lua is quite easy to get started with.

If you've downloaded the sample library mentioned above, look inside the "HelloWorld" folder in the "GettingStarted" directory (or download the project here). You'll see that there are four files in the project:

什麼是電暈項目?

至少,電暈計劃只是一個文件夾包含一個文本文件名為“main.lua“。會發現,所有的示例代碼電暈遵循這種模式雖然大部分的樣品中含有的其他文件,除main.lua

這種特殊的文件名“main.lua“須告訴電暈從哪裡開始主要文件可能反過來加載其他代碼文件,或其他程序資源,如聲音或圖形。文件擴展名“。盧阿“表示該文件是寫在Lua中,這是將使用的語言來創建應用程序電暈

Lua是一個簡單但很強大的腳本語言。即使你有很少或沒有編碼的經驗,你會發現,Lua是相當容易上手。

如果你下載了上述樣品庫,看看裡面的的“HelloWorld“文件夾中的“GettingStarted“目錄(或下載該項目在這裡)。你會看到有四個文件中的項目:

 

 

  • config.lua - a configuration file for different screen sizes
  • Icon.png - the project's iPhone icon
  • main.lua - a slightly different version of the "Hello World" code you wrote above
  • world.png - a large image of the Earth

config.lua-一個配置文件不同屏幕尺寸
Icon.png- 項目iPhone圖標
main.lua-略有不同版本的“Hello World“的代碼,你上面
world.png- 一個大地球圖像

You can open this project in the Corona Simulator to see the fancy version of "Hello World":
您可以打開該項目中電暈模擬器看到花式版本的“Hello World“:

Also, you can preview the project on different devices using the Simulator. For example, choose "Window > View As > NexusOne" or "Window > View As > iPad" to see the following:

此外,您可以預覽該項目在不同的設備使用模擬器。例如,選擇窗口“>查看為“>NexusOne“或”窗口“>查看為“> iPad的“看到以下內容:

 

Note

Even though these devices have different screen shapes and sizes, Corona can automatically adjust the content to fill each device screen. More on Content Scaling.

注意:

雖然這些設備具有不同的屏幕形狀和大小,電暈可以自動調整內容來填充每個設備屏幕。有關內容尺度

If you open this version of main.lua in TextWrangler, you'll notice a new function that puts an image on the screen using just a single line of code:
如果您打開此版本main.luaTextWrangler,你會發現一個新功能,使得圖像在屏幕上只用一行代碼:

background = display.newImage( "world.png" )

In most of the Corona samples, you'll notice that the word "local" appears before variables and objects. This is a good practice in Lua to save memory and resources, but in simple programs it doesn't make any difference, and so you can omit the "local" keyword if you're just starting out.

在大多數的電暈樣品,你會發現,單詞“local前出現的變量和對象。這是一個很好的做法在Lua節省內存資源,但在簡單的程序作任何區別,所以你可以省略“local關鍵字,如果你剛剛起步

Further Resources

Dr. Brian Burton, a Texas educator and consultant, has created this useful tutorial for getting started with Corona.

更多資源

布萊恩伯頓博士德州教育家和顧問,創造了這個有用的入門教程電暈

arrow
arrow
    全站熱搜

    createps 發表在 痞客邦 留言(0) 人氣()