close

Images

Bitmap image objects are a type of DisplayObject.

圖片
Bitmap image物件 DisplayObject的

Loading an Image

display.newImage( filename [, baseDirectory] [, left, top] ) Returns an image object. It loads the image data from filename and by default looks in the system.ResourceDirectory for that file. If you specify the argument baseDirectory it will look in that directory instead (see system.pathForFile for valid values of baseDirectory). Both PNG and JPEG files are supported.


加載圖像
display.newImagefilename [,baseDirectory] [,left,top])返回一個image object它加載圖像數據文件,並且默認 system.ResourceDirectory中查找該文件如果指定的參數 baseDirectory就會在該目錄來代替( system.pathForFile有效的baseDirectory)。 PNG和JPEG文件支持

myImage = display.newImage( "image.png", 10, 20 )
myImage2 = display.newImage( "image.png" )

 

You can optionally specify that the image's top-left corner be located at the coordinate (left, top); if you don't supply both coordinates, the image will be centered about its local origin.
您可以選擇指定圖像的左上角設在坐標(左,上),如果你不提供兩個坐標,圖像將集中當地的起源。

The local origin is at the center of the image; the reference point is initialized to this point. This means that once the image is onscreen, any further access to x or y will refer to the center of the image, not to the top/left values optionally specified in display.newImage(). You can override this behavior by specifying a different reference point for the image.

當地的原產地在該中心形象;參考點被初始化了這一點。這就意味著,一旦屏幕上的圖像,任何進一步使用X或Y將參照該中心的形象,不到 top /left 值​​隨意指定 display.newImage()可以覆蓋此行為通過指定一個不同的參考圖像。

Loading the same image file more than once, as in the code above, does not use additional texture memory, since Corona will automatically re-use the texture data from the first instance of the image.

相同的圖像文件載入不止一次,如上面的代碼中,不使用額外的紋理內存,因為電暈將自動重新使用的紋理數據從第一個實例中的形象。

Image Autoscaling

圖片自動縮放

The default behavior of display.newImage() is to auto-scale large images. This is to conserve texture memory. However, there are times when you do not want to have images auto-scaled, and there is an optional boolean flag in the parameter list to control this manually.

的默認行為 display.newImage()自動規模較大的圖像這是為了保護紋理內存但是,有些時候不希望有圖片自動縮放,並有一個可選的布爾標誌,在參數列表來控制手動操作。

To override autoscaling and show the image at its full-resolution, use the optional isFullResolutionparameter. By default, it is false, but if you specify true, then the new image is loaded at its full resolution:
要覆蓋自動縮放顯示圖像在其全分辨率,使用可選的 isFullResolutionparameter默認情況下它是假的,但如果指定的話,那麼新的形象被載入到全分辨率

display.newImage( [parentGroup,] filename [, baseDirectory] [, x, y] [,isFullResolution] )

myImage = display.newImage( "image.png", 10, 20, true )

 

Limitations and known issues:

  • Indexed PNG image files are not supported.
  • Greyscale images are currently not supported; images must be RGB.
  • Images will still be autoscaled if they are larger than the maximum possible texture dimensions of the device. This is usually 1024x1024 (iPhone 3G) or 2048x2048 (iPhone 3GS, iPad).
  • If you reload the same image multiple times, the subsequent calls to display.newImage ignore the isFullResolution parameter and take on the value passed the first time. In other words, the way you load an image file the first time affects the auto-scaling setting the next time you load that same file. This is because Corona conserves texture memory by automatically re-using a texture that has already been loaded. As a result, you can use the same images as many times as you want without consuming additional texture memory.
限制和已知問題

*收錄 PNG圖像文件不被支持
*灰度圖像目前不支持;圖像必須是RGB
*圖像將autoscaled 如果他們仍然大於最大可能的紋理尺寸設備。這通常是1024x1024iPhone3G)的2048x2048iPhone3GS的,ipad公司)。
*如果你重載多次相同的圖像,隨後調用 display.newImage忽略isFullResolution參數,並就值傳遞第一次。換句話說,你的方式加載圖像文件的第一時間會影響自動縮放設置下一次您加載同一文件這是因為電暈節省紋理內存自動重新使用一個紋理,被載入。因此,您可以使用相同的圖像,只要你想多少次,而無需耗費額外的紋理內存。
  

Images with Dynamic Resolution 圖像的動態解決方案

Dynamic-resolution images are similar to the ordinary images above, except that Corona can automatically substitute higher-resolution assets on higher-resolution devices. This lets you swap in double-resolution images on the iPhone 4, while maintaining your code and layout from the older iPhones. But this feature also lets you handle more complex multi-screen deployment cases, including cases where the screen resolutions of different devices do not fall into a simple 2:1 ratio.

Dynamic image resolution works in conjunction with dynamic content scaling, which is discussed in the"Configuring Projects" section of the API Reference.

動態清晰度的圖像類似於普通圖像上面,除了可以自動替代電暈分辨率更高的資產的更高分辨率的設備。這可以讓你在雙高分辨率圖像iPhone4,同時保持你的代碼和佈局,從的iPhone。但是,此功能還可以讓處理更複雜的多屏部署案件,包括情況下,不同設備的屏幕分辨率不屬於一個簡單的比例為 2:1。

工程動態圖像分辨率動態內容一起縮放,這是討論中的“配置項目“一節中的API參考

Loading an Dynamic Resoultion Image

載入一個圖像的動態 Resoultion
Syntax: display.newImageRect( [parentGroup,] filename [, baseDirectory] w, h ), where:
語法:display.newImageRect([parentGroup]文件名[,baseDirectory]寬,高),其中:
  • w is the content width of the image, which is the width in the reference screen of the content.
  • h is the content height of the image, which is the height in the reference screen of the content.

The actual image chosen will depend on the current content scale determined by Corona, which is the ratio between the current screen and the base content dimensions defined in config.lua. Based on this scale, Corona uses the imageSuffix table (also defined in config.lua), which lists the suffixes for the same family of images, to find the best match from the image choices available. For example, you may define an image suffix of "@2" to indicate 2x resolution images, but you can also choose any other naming suffix and resolution multiplier.


w為內容的寬度的圖像,這是屏幕的參考內容
h為內容的高度的形象,這是高度的參考畫面的內容
實際圖像選擇將取決於目前的內容規模確定電暈,這是當前屏幕之間的比例尺寸定義的基本內容config.lua在此基礎上規模,電暈使用imageSuffix表(也定義在config.lua),其中列出了後綴同一家庭的圖像,找到最佳匹配圖像可供選擇例如,可以定義一個形象後綴@ 2“表示2倍分辨率的圖片,但您也可以選擇任何其他命名後綴和解決的倍增器。

myDynamicImage = display.newImageRect( "baseImage.png", 100, 100 ) 

 

It is important to remember that the two numerical values represent the base image size, not the onscreen position of the image. This base size must be defined at load time, so that Corona knows how to render the higher-resolution alternative images.

For a full discussion of how to use this feature, see the documentation on dynamic image resolution in the "Configuring Projects" section.

重要的是要記住這兩個數值代表了相應的圖像的大小,而不是屏幕上的位置的​​圖像。該基地規模必須定義在加載時間,以便知道如何呈現電暈分辨率更高的替代圖像。

對於一個充分討論如何使用此功能,請參閱文檔動態圖像的分辨率,在“配置項目“一節。

Creating Shapes

Shapes in Corona are created using vector objects. Vector objects are a special type of DisplayObject. The following return Lua tables representing rectangle, rounded rectangle, and circle, respectively:

創建形狀
形狀各異的科羅納是使用向量的對象。矢量對象是一個特殊類型的DisplayObject。下面的返回的Lua代表矩形,圓角矩形和圓形,分別為:

display.newRect( [parentGroup,] left, top, width, height ) creates a width by height rectangle with the top-left corner at (left, top). The local origin is at the center of the rectangle; the reference point is initialized to this local origin. By default, there is no fill or stroke color.

display.newRect( [parentGroup,] left, top, width, height )創建一個寬度高度的矩形左上角在(左,上)。當地的原產地在該中心的矩形;參考點初始化為這個地區的起源。默認情況下,沒有任何填充或描邊顏色

display.newRoundedRect( [parentGroup,] left, top, width, height, cornerRadius ) creates a width byheight rounded rectangle with the top-left corner at (left, top). The corners are rounded by quarter circles of radius cornerRadius. The local origin is at the center of the rectangle; the reference point is initialized to this local origin. By default, there is no fill or stroke color.

display.newRoundedRect( [parentGroup,] left, top, width, height, cornerRadius ) 創建一個圓角矩形寬度 byheight左上角在(左,上)。圓潤邊角按季度半徑 cornerRadius當地的原產地在該中心的矩形;參考點初始化為這個地區的起源。默認情況下,沒有任何填充或描邊顏色

display.newCircle( [parentGroup,] xCenter, yCenter, radius ) creates a circle with radius radiuscentered at (xCenter, yCenter). The local origin is at the center of the circle; the reference point is initialized to this local origin. By default, there is no fill or stroke color.

display.newCircle( [parentGroup,] xCenter, yCenter, radius )建立一個圓,半徑為 radiuscentered在(xCenteryCenter)。當地的原產地在該中心的圓;參考點初始化為這個地區的起源。默認情況下,沒有任何填充或描邊顏色

Setting the Stroke Width, Fill Color and Stroke Color

設置畫筆的寬度填充顏色和筆觸顏色

object.strokeWidth sets the stroke width in pixels. Note that stroke widths are broken up to inner and outer parts. The stroke is centered on the boundaries of the object, but when the stroke width is odd, Corona does an integer divide by 2 (e.g. 3 / 2 = 1; 1 / 2 = 0) and set the inner width to that; the remainder is the outer width. This avoids blurring around the edges of the stroke. For example, a stroke width of 3 results in an inner width of 1 and an outer width of 2.

設置畫筆的寬度以像素為單位請注意,中風寬度被分解到內部和外部零件。中風集中在邊界的對象,但是當筆劃寬度為奇數,電暈除以2的整數(如3/ 2 =1,1 /2 =0),並設置內部寬度,其餘是最外層的寬度。這就避免了模糊的邊緣,中風例如,筆劃寬度3結果內部寬度為 1和一個外2。

One specific consequence is that if a rectangle fills the screen, a stroke width of 1 will be drawn entirely offscreen. Also, adding a stroke increases the width and height of the object by twice the amount of the outer stroke.


一個具體的結果是,如果一個矩形填充屏幕,筆劃寬度1繪製完全離屏此外,增加了中風增加了寬度和高度的對象的2倍金額中風。

object:setFillColor( r, g, b [, a] ) All components must be between 0 and 255. Alpha is optional and is 255 (opaque) by default.

所有組件必須介於0和255之間。Alpha 是可選的255(不透明)默認情況下。

object:setStrokeColor( r, g, b [, a] ) All components must be between 0 and 255. Alpha is optional and is 255 (opaque) by default.

所有組件必須介於0和255之間。Alpha 是可選的255(不透明)默認情況下。

 

Polylines  折線

display.newLine( )

The Polylines API draws connected line segments, with any color and stroke width, using the Corona vector engine. The resulting object is a standard Corona display object, and can be independently moved and scaled like any other display object. The stroke and color properties can also be changed after the object has been drawn.

Polylines are a series of vertices specifying endpoints of line segments. The lines have a stroke width, specified in a "width" parameter. Currently, multiple line segments have miter joins. In other words, an angle joint comes to a point, as opposed to being rounded. The start and end have butt caps.

The current Polyline API is as follows:

折線的API繪製線段連接與任何顏色筆劃寬度,採用電暈矢量發動機。由此產生的對象是一個標準的電暈顯示對象,可以獨立移動和縮放像任何其他顯示對象。筆觸和顏色屬性也可以改變該對象後已經繪就。

折線一系列的頂點指定端點的線段中風的線條寬度,指定在“寬度“參數。目前,多線段尖角連接。換言之,一個角聯合來到一個點,而不是被四捨五入。開始和結束對接上限。

當前折線的API如下

newLine:Draw a line from one point to another. Optionally, append points to the end of the line.

畫一條從一個點到另一個。或者,追加點到行尾

append:
   Append one or more segments to an existing display.newLine object.
 附加一個或多個細分市場現有 display.newLine對象
  One or more x,y pairs specifying a new point to extent the existing line.
  一個或更多的x,y指定一個新的起點現有生產線的程度

local a = display.newLine( [parent,] x1,y1, x2,y2 )
a:setColor( r, g, b, a )
a:append( x, y [,... ] )
a.width = strokeWidth
Code example:
local star = display.newLine( 0,-110, 27,-35 )  
star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110 )  --最後兩個點連回第一個點(0,-100)
--因為1個星星有由10個點組成,每個點有2個座標(x和y)

star:setColor( 255, 102, 102, 255 )  
star.width = 3
See the Graphics/PolyLines sample code for an animated demo that runs on iPhone and iPad.
Graphics /PolyLines 示例代碼的動畫演示,運行在iPhone和iPad



 

 

 

 

 

 

 

 

 

arrow
arrow
    全站熱搜

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