Corona Images, Shapes, and Text About Display Objects Part1
About Display Objects
All
drawing that occurs on the screen is accomplished by creating DisplayObjects
. Anything that appears
on the screen is an instance of a DisplayObject
. You don’t actually
create these objects directly. Instead, you create special kinds of DisplayObject
such as rectangles, circles, images, text,
etc.
關於顯示對象
所有的繪製發生在屏幕上通過創建的DisplayObject。凡是出現在屏幕上是一個實例DisplayObject的。你實際上並不直接創建這些對象。相反,你建立特殊類型DisplayObject的如矩形,圓形,圖像,文字等
These objects are all first-class citizens. You can animate them, turn them into buttons, etc.
這些對象都是一等公民。你可以動畫他們,把他們融入按鈕等
You
create a DisplayObject
by calling a special kind of function called
a constructor. This implicitly adds the object above all other objects you have
created. DisplayObjects
are designed to organize common
functionality, but you never create a DisplayObject
explicitly.
您創建一個 DisplayObject通過調用一種特殊的構造函數調用。這隱含對象添加上述所有其他對象已創建。的DisplayObject旨在共同組織的功能,但是你從來沒有明確地創建一個 DisplayObject。
Instead,
there are constructors for each specific kind of DisplayObject
, e.g. display.newRect()
creates a VectorObject.
相反,有構造為每個特定的DisplayObject種,如display.newRect()創建一個VectorObject。
All display object constructors implicitly set the parent of the new objects to be the current stage object. (Currently, there is only one stage in Corona. Groups can be created to act like additonal stages for grouping objects.) Most have an optional parentGroup parameter that overrides this behavior and instead sets the parent to a specified group.
所有顯示對象構造隱式設置的父新對象是當前階段的對象。 (目前,只有一個階段,電暈。團體可以創建像產生額外階段的分組對象。)大多數有一個可選參數parentGroup重寫此行為,而不是設置家長到指定的組。
All
instances of DisplayObject
behave similarly to normal Lua tables. This
means you can add your own properties to the object as long as they don't
conflict with the properties and method names below. Group objects (and stage
objects) have some slight quirks, as discussed below; also see the more detailed
technical discussion in "Display Objects vs. Tables" at the end of this
section.
所有的實例 DisplayObject的行為同樣正常的Lua表。這意味著你可以添加自己的屬性的對象,只要他們不衝突的屬性和方法名以下。組對象(和舞台上的對象)有一些輕微的怪癖,討論如下,還可以看到更為詳細的技術討論,在“顯示對象對比表“,在本節結束。
In addition, all display objects have the following properties and object methods in common:
此外,所有顯示對象具有以下屬性和對象的方法的共同點:
Properties
are accessed via the dot operator. For example, if we have a 屬性是訪問通過點操作符。例如,如果我們有一個 DisplayObject變量所代表的對象,我們可以改變它的alpha為 50%:object.alpha =
0.5。 Below
are the common properties shared by all display objects. 以下是在共同財產的共同所有顯示對象。 object.alpha is the object's opacity. A value of 0 is
transparent and 1.0 is opaque. The default value is 1.0. Note
that this is a different alpha property than the optional "alpha" component
found in each color specification of the form (r, g, b [, a]). In the latter
case, the alpha range is 0-255, just like the red, green and blue ranges,
because the resulting value set specifies a 32-bit color with 8 bits per
channel. object.alpha是對象的不透明度。一個 0值是透明的,1.0是不透明的。默認值是1.0。 object.height is in local coordinates object.height在局部坐標 object.isVisible controls whether the object is
visible on the screen. true is visible and false is not. object.isVisible控制對象是否是可見的屏幕上。真正是不可見的和虛假的。 object.isHitTestable allows an object to continue to receive hit events even if it is not visible. If true, objects will receive hit events
regardless of visibility; if false, events are only sent to visible
objects. object.isHitTestable允許一個對象,繼續收到 hit
事件,即使收到它是不可見的。如果情況屬實,對象將接收的襲擊事件,無論知名度;如有不實,事件只發送到可視對象。 object.length [read-only] is deprecated in favor of object.length
[只讀]贊成不贊成使用group.numChildren。對於組對象,這是多少兒童;否則為
0。 object.parent [read-only] returns the parent group of the
object. object.parent [只讀]返回母集團的對象。 object.rotation is the current rotation angle (in
degrees). object.rotation是當前的旋轉角(度)。 object.contentBounds is a table with properties object.contentBounds是一個表與屬性的形式:Xmin,xMax,Ymin成員,yMax的在屏幕坐標。一般用於映射對象在一個小組,在屏幕上的坐標。 object.contentHeight is the height in screen coordinates. object.contentHeight是在屏幕坐標的高度。 object.contentWidth is the width in screen coordinates. object.contentWidth是寬屏幕坐標。 object.width is in local coordinates object.width在局部坐標 object.x specifies the x-position (in local
coordinates) of the object relative to the parent — the parent’s origin to be
precise. Specifically, it provides the x-position of the object’s reference
point relative to the parent. Changing the value of this will move the object in
the x-direction. Changing the object's reference point will change the object's
x and y points without moving the object. object.x指定的X -位置(在本地坐標)的對象相對於父 -
父的原產地是準確的。具體來說,它提供的X -位置的對象的參考點相對於父。改變這個值將移動的物體在x方向。改變對象的參考點會改變對象的X和Y點不動的對象。 object.xOrigin specifies the x-position of the object’s
origin relative to the parent’s origin. It is in the object’s local coordinates.
Changing the value of this will move the object in the x-direction. object.xOrigin指定的X位置的對象的原產地相對於父的起源。它是在對象的本地坐標。改變這個值將移動的物體在x方向。 object.xReference defines the x-position of the reference
point relative to the object’s local origin. It is relative to another point in
the object, not to its parent. Conceptually, the reference point is the location
about which scaling and rotations occur. Sometimes this is referred to as the
registration point. For most display objects, this value defaults to 0, meaning
the x-position of the origin and the reference point are the same. This merely
defines the reference point, so changing the value of this property does not
change the position of the object. object.xReference定義的X位置的參考點相對於對象的本地起源。它是相對於另一個點的對象,而不是其父母。在概念上,參考點是哪個位置的縮放和旋轉發生。有時這被稱為註冊點。對於大多數的顯示對象,此值默認為 0,這意味著 x位置的起源和參考點是相同的。這只是定義了參考點,所以改變這個屬性的值不會改變位置的對象。 object.xScale gets or sets the X scaling factor. A value
of 0.5 will scale the object to 50% in the X direction. object.xScale獲取或設置 x比例因子。將一個價值 0.5縮放對象的50%在X方向。 object.y specifies the y-position (in local
coordinates) of the object relative to the parent — the parent’s origin to be
precise. Specifically, it provides the y-position of the object’s reference
point relative to the parent. Changing the value of this will move the object in
the y-direction. Changing the object's reference point will change the object's
x and y points without moving the object. object.y指定Y方向的位置(在本地坐標)的對象相對於父 -
父的原產地是準確的。具體來說,它提供的Y位置的對象的參考點相對於父。改變這個值將移動的物體在y方向。改變對象的參考點會改變對象的X和Y點不動的對象。 object.yOrigin specifies the y-position of the object’s
origin relative to the parent’s origin. It is in the object’s local coordinates.
Changing the value of this will move the object in the y-direction. object.yOrigin指定Y方向的位置對象的原產地相對於父的起源。它是在對象的本地坐標。改變這個值將移動的物體在y方向。 object.yReference defines the y-position of the reference
point relative to the object’s local origin. It is relative to another point in
the object, not to its parent. Conceptually, the reference point is the location
about which scaling and rotations occur. Sometimes this is referred to as the
registration point. For most display objects, this value defaults to 0, meaning
the y-position of the origin and the reference point are the same. This merely
defines the reference point, so changing the value of this property does not
change the position of the object. object.yReference定義的Y位置的參考點相對於對象的本地起源。它是相對於另一個點的對象,而不是其父母。在概念上,參考點是哪個位置的縮放和旋轉發生。有時這被稱為註冊點。對於大多數的顯示對象,此值默認為 0,這意味著 Y方向的位置的起源和參考點是相同的。這只是定義了參考點,所以改變這個屬性的值不會改變位置的對象。 object.yScale gets or sets the Y scaling factor. A value
of 0.5 will scale the object to 50% in the Y direction. object.yScale獲取或設置 y縮放因子。將一個價值 0.5縮放對象的50%,Y方向。Common Properties 通用屬性
DisplayObject
represented by the variable object
, we can change its alpha to
50%: object.alpha=0.5
.
請注意,這是一個不同的alpha屬性比可選的“alpha”組成部分的每個顏色規範的形式(001克,乙[,1])。在後一種情況下,alpha範圍是0-255,只是喜歡紅色,綠色和藍色的範圍,因為結果值設置指定一個
32位元色8位元每通道。group.numChildren
. For Group Objects,
this is the number of children; 0 otherwise.xMin
, xMax
, yMin
, yMax
in screen coordinates. Generally used to map
the object in a group to the screen coordinates.