close

Corona Images, Shapes, and Text About Display Objects Part2

Common Object Methods

通用對象的方法

Object methods are accessed via the colon operator. For example, if we have a DisplayObject represented by the variable object, we can translate the object 10 pixels to the right (of it's current position): object:translate( 100 ).

訪問對象的方法是通過結腸運營商。例如,如果我們有一個 DisplayObject變量所代表的對象,我們可以翻譯的對象 10像素到右邊(可以把它的當前位置):object:翻譯(10,0)。

Below are the common methods shared by all display objects:

下面是常用的方法共享所有顯示對象:

object:getParent() is deprecated in favor or object.parent. (Yes, you should ignore the fact that sample code continues to use this API).

object:getParent()已過時贊成或object.parent。 (是的,你應該忽視這樣一個事實,樣本代碼繼續使用此API)。

object:rotate( deltaAngle ) effectively adds deltaAngle (in degrees) to the current rotation property.

objectrotate(deltaAngle)有效地增加了deltaAngle(度)到目前的旋轉屬性。

object:scale( sx, sy ) effectively multiplies xScale and yScale properties by sx and sy respectively. If the current xScale and yScale values are 0.5 and sx and sy are also 0.5, the resulting scale will be 0.25 for xScale and yScale. This scales the object from 50% of it's original size to 25%.

objectscale(sx,sy)有效地繁殖性能的xScale和yScale sx和sy分別。如果目前的XScale和yScale值分別為 0.5和SX和SY也是0.5,由此產生的規模將是0.25 XScale和yScale。這個尺度上的對象,從 50%它的原始大小的25%。

object:setReferencePoint( referencePoint ) sets the reference point either to the center of the object (default) or to one of several convenient points along the bounding box of the object. The argumentreferencePoint should be one of:

object:setReferencePoint(referencePoint)設置參考點無論對中心的對象(默認)或一個點的幾家便利沿邊界框對象的。這個論點 referencePoint應該之一:

  • display.CenterReferencePoint
  • display.TopLeftReferencePoint
  • display.TopCenterReferencePoint
  • display.TopRightReferencePoint
  • display.CenterRightReferencePoint
  • display.BottomRightReferencePoint
  • display.BottomCenterReferencePoint
  • display.BottomLeftReferencePoint
  • display.CenterLeftReferencePoint

By design, an object's reference point is statically positioned relative to the object's local origin. This means that if you explicitly set an object's reference point using setReferencePoint() and then later modify the height or width of the object, the reference point may no longer refer to the same point.

按照設計,一個對象的參考點是相對於靜態定位對象的本地起源。這意味著,如果你明確地設置一個對象的參考點使用setReferencePoint(),然後以後修改的高度或寬度的對象,參考點可能不再指向同一個點。

display.CenterReferencePoint
display.TopLeftReferencePoint
display.TopCenterReferencePoint
display.TopRightReferencePoint
display.CenterRightReferencePoint
display.BottomRightReferencePoint
display.BottomCenterReferencePoint
display.BottomLeftReferencePoint
display.CenterLeftReferencePoint
Changing the object's reference point will change the object's x and y values without moving the object.

改變對象的參考點會改變物件的x和y值不用移動物件

 This can cause unexpected results, especially when working with text objects: assigning a different string to the object's text property changes the object's width, but not its reference point, which changes the object's alignment. The workaround is to reset the object's reference point and x-position after assigning the new string. The following code illustrates this behavior and workaround. (These concepts also apply to other types of display objects, such as image and shapes.)

這可能會導致意想不到的結果,特別是當工作與文本對象:分配一個不同的字符串對象的text屬性更改對象的寬度,但不是它的參考點,從而改變對象的對齊方式。解決辦法是重置對象的參考點和X位置後分配新的字符串。下面的代碼說明了這種行為,並因應措施。 (這些概念也適用於其他類型的顯示對象,如圖像和形狀。)
  
-- A text object is created and is aligned left at point x=20
--創建一個文本對象是左對齊,並點 x= 20
local textObj = display.newText("A short string", 0,0, nil, 14);
textObj:setReferencePoint(display.CenterLeftReferencePoint);
textObj.x = 20;
 
-- Later, the textObj.text property is assigned a new string value of different length,
-- causing the object's width to change, but not its reference point.
-- Consequently, the text is no longer aligned left at point x =20
-後來,textObj.text屬性分配一個新的字符串值不同長度
- 導致物件的寬度變化,但不是它的參考點
-因此,text不再是左對齊點 x= 20
textObj.text = "This string has several more characters than before..."
 
-- Work-around: 
-- Reset the text object's reference point and x position
-- after you update its text property:
-解決方法:
- 重置text物件的參考點和X位置
-在更新它的Text屬性:
textObj.text = "This string has several more characters than before..." textObj:setReferencePoint(display.CenterLeftReferencePoint); textObj.x = 20

 

object:translate( deltaX, deltaY ) effectively adds deltaX and deltaY to the x and y properties respectively. This will move the object from it's current position.

objecttranslatedeltaXdeltaY)有效地增加了deltaXdeltaYx和y屬性分別這將移動物體從它的當前位置。

object:removeSelf( ) removes the display object and frees its memory, assuming there are no other references to it. This is equivalent to calling group:remove(IndexOrChild) on the same display object, but is syntactically simpler. The removeSelf() syntax is also supported in other cases, such as removing physics joints in Physics.

objectremoveSelf()刪除顯示物件並釋放其內存,假設沒有其他對它的引用。這等同於調用組:remove(IndexOrChild)在相同的顯示對象,但在語法簡單。 removeSelf()語法也支持在其他情況下,如取消物理接頭物理。

See the section on removing objects properly in the Application Programming Guide for more on memory management and display object removal.

一節中正確刪除對象的應用編程指南的更多的內存管理和顯示對象刪除。

 

arrow
arrow
    全站熱搜

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