PIXNET Logo登入

遊戲人生 人生遊戲

跳到主文

如果工作是玩樂就太好了

部落格全站分類:攝影寫真

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 5月 18 週三 201113:54
  • Corona object:addEventListener

object:addEventListener


Description:
Adds a listener to the object’s list of listeners. When the named event occurs, the listener will be invoked and be supplied with a table representing the event.
添加一個監聽對象的名單聽眾。當指定的事件發生時,監聽器將被調用,並提供與表代表事件。


Syntax:
object:addEventListener( eventName, listener )


Example:
Listeners can be either functions or table objects.
Listeners可以是函數或表對象。


When a function listener is invoked, it is passed a table representing the event:
當一個函數被調用監聽器,它是通過一個表代表事件:
----------------------
local myListener = function( event )
        print( "Listener called with event of type " .. event.name )
end
Runtime:addEventListener( "touch", myListener )
Runtime:addEventListener( "enterFrame", myListener )
-----------------------
Sometimes a function listener is not convenient because certain variables are not in scope when the listener is triggered (invoked). In these situations, object listeners should be used. Object listeners must have an instance method with a name corresponding to the event name:
有時候,一個函數監聽不方便,因為某些變量沒有範圍時,監聽器被觸發(調用)。在這種情況下,應使用對象聽眾。聽眾必須有一個對象實例的方法名稱與相應的事件名稱:
---------------------------------------------------
-- assume MyClass and MyClass:new() already exist 假設 MyClass and MyClass:new() 已經存在
 
function MyClass:enterFrame( event )
        print( "enterFrame called at time: " .. event.time )
end
 
function MyClass:touch( event )
        print( "touch occurred at ("..event.x..","..event.y..")" )
end
 
local myObject = MyClass:new()
 
Runtime:addEventListener( "touch", myObject )
Runtime:addEventListener( "enterFrame", myObject )
---------------------------------------------------
Parameters:


eventName
String specifying the name of the event to listen for.
字串指定名稱的事件監聽。


listener
If the event's event.name matches this string, listener will be invoked. Event listeners are either functions or objects (a.k.a. table listeners).
如果事件的event.name匹配此字符串,監聽器將被調用。事件監聽器是函數或對象(又稱表位聽眾)。


Returns:
Nothing.


Remarks:
Note: You cannot add an object event listener within the listener event for that object. You should add the listener event outside of the current listener using the timer.performWithDelay() API. Failing to do so will cause the new listener to be called immediately after the current listener returns.
注意:您不能添加一個事件監聽器對象在監聽事件的對象。你應該加入目前監聽器以外的事件監聽器,目前使用timer.performWithDelay()的API。如果不這樣做將導致新的監聽器被稱為當前監聽後立即返回。


Another solution to the problem is using a single event listener for the object and adding a "state" variable to control what function is performed when invoked.
另一種解決問題的辦法是使用一個單獨的事件偵聽器對象,並增加了"狀態"變量來控制函數執行時調用。
--------------------------------
local addListener1, addListener2        -- forward references
 
-- create a large button
local rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
rect:setFillColor( 128, 64, 64 )
 
-- state1
function state1Cb( event )
    print("state1")
    rect:removeEventListener( "tap", state1Cb )
    --rect:addEventListener( "tap", state2Cb )  -- ** Don't do this
    timer.performWithDelay( 1, addListener2 )   -- ** Do this instead
    return true   
end
 
-- state2
function state2Cb( event )
    print("state2")
    rect:removeEventListener( "tap", state2Cb )
    --rect:addEventListener( "tap", state1Cb )  -- ** Don't do this
    timer.performWithDelay( 1, addListener1 )   -- ** Do this instead
    return true   
end
 
function addListener2( )
    rect:addEventListener( "tap", state2Cb )
end
 
function addListener1()
    rect:addEventListener( "tap", state1Cb )
end
 
-- start
addListener1()  -- add first listener


------------------------------------------
Supported on operating systems and platforms for build numbers shown:


Mac OS X:Corona SDK 1.0
Windows: Corona SDK 2.0
iOS: Corona SDK 1.0
Android: Corona SDK 2.0
Related:

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 18 週三 201113:39
  • Corona event.phase事件階段

event.phase事件階段


Description:

Specifies the collision phase and can be one of the following values:
指定碰撞階段,可以是以下值:


"began" -- Indicates a collision between two bodies has started initial contact.
"ended" -- Indicates a collision between two bodies has completed.
“開始“- 表示這兩個機構之間的碰撞已經開始初步接觸。
“結束“- 表示這兩個機構之間的碰撞已經完成。


Syntax:


event.phase


Example:
--------------------------------
local crate1 = display.newImage( "crate.png", 100, 200 )
physics.addBody( crate1, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate1.myName = "first crate"
 
local crate2 = display.newImage( "crate.png", 100, 120 )
physics.addBody( crate2, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate2.myName = "second crate"
 
local function onCollision( event )
        if ( event.phase == "began" ) then
 
                print( "began: " .. event.object1.myName .. " & " .. event.object2.myName )
 
        elseif ( event.phase == "ended" ) then
 
                print( "ended: " .. event.object1.myName .. " & " .. event.object2.myName )
 
        end
end
 
Runtime:addEventListener( "collision", onCollision )
---------------------------------


Parameters:
None.


Returns:
Nothing.


Remarks:
Note: The objects involved in the collision should not be removed or any of it's properties altered during a collision event. You should use timer.performWithDelay() if they want to modify object position values or other properties within the collision events.
注:參與的對象碰撞不應刪除或它的任何屬性的改變在發生碰撞時。您應該使用timer.performWithDelay()如果他們想修改對象位置值或其他財產在碰撞事件。


Removing the object or modifying the properties in the collision event could cause the simulator to crash.
刪除或修改對象的屬性在發生碰撞時可能會導致模擬器崩潰。


Supported on operating systems and platforms for build numbers shown:


Mac OS X:Build 2010.222
Windows: Build 2010.222
iOS: Build 2010.222
Android: Build 2010.222
Related:

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 17 週二 201122:25
  • Corona physics.addBody

physics.addBody()

Description:

Allows you to turn any Corona display object into a simulated physical object with one line of code, including the assignment of physical properties.
可讓您在任何顯示對象Corona成模擬的物理對象一行代碼,包括分配的物理特性。


If no shape information is specified, then the body boundaries will snap to the rectangular boundaries of the display object used to create the physics body.
如果沒有指定形狀的信息,然後身體邊界將捕捉到的矩形邊界的顯示對象,用於創建物理身體。


If a radius is specified, then the body boundaries will be circular, centered at the middle of the display object used to create the physics body.
如果指定的半徑,那麼身體邊界將被通知,集中在中間的顯示對象,用於創建物理身體。


If a shape is specified, then the body boundaries will follow the polygon provided by the shape. Note that the maximum number of sides per shape is eight, and all angles must be convex. (Specifying a shape will override the radius property, if both radius and shape are specified in the same element.)
如果指定了一個形狀,然後身體邊界將按照所提供的多邊形形狀。請注意,每邊最多的形狀是八,所有的角度必須是凸起。 (指定的形狀將覆蓋半徑屬性,如果兩個半徑和形狀相同的元素中指定。)


A body shape is simply a table of local (x,y) coordinates, relative to the center of the display object; see example below.
一個身材只是一個表地方(的x,y)坐標,相對於中心的顯示對象,見下面的例子。


Finally, a more complex body may be constructed by specifying multiple body elements and shapes. In cases where the overall shape of the object is concave, or the shape has more than eight sides, you can use multiple body elements to construct it.
最後,一個更複雜的身體構造,可通過指定多個體元素和形狀。在情況下,整體造型的對象是凹的,或形狀有超過八個方面,可以使用多種元素來構造它的身體。


Each body element may have its own physical properties, and the body element index is reported as part of each collision event -- so it is possible to detect which part of a complex body was involved in a collision.
每個 body元素可以有自己的物理性質,和身體元素的索引報導的一部分,每一個碰撞事件- 因此它可以檢測哪部分是一個複雜的機構參與了衝突。


For further information, see Physics Bodies.
如需進一步信息,請參閱物理機構。


Syntax:語法


physics.addBody(object, [bodyType,] {density=d, friction=f, bounce=b [,radius=r]})
physics.addBody(object, [bodyType,] {density=d, friction=f, bounce=b [,shape=s]})


-- For a complex body (multiple body elements) 對於一個複雜的身體(身體多個元素)
 
physics.addBody(object, [bodyType,]
   {density=d1, friction=f1, bounce=b1, shape=s1},
   {density=d2, friction=f2, bounce=b2, shape=s2},
   {density=d3, friction=f3, bounce=b3, shape=s3}
)
----------------------------------
Example:
Default (rectangular) bodies
local physics = require( "physics" )
physics.start()
 
local sky = display.newImage( "bkg_clouds.png" )
sky.x = 160; sky.y = 195
 
local ground = display.newImage( "ground.png" )
ground.x = 160; ground.y = 445
 
physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } )
 
local crate = display.newImage( "crate.png" )
crate.x = 180; crate.y = -50; crate.rotation = 5
 
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )
Circular bodies
local ball = display.newImage("ball.png")
 
physics.addBody( ball, { density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 } )
Polygon bodies
local pentagon = display.newImage("pentagon.png")
 
pentagonShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
 
physics.addBody( pentagon, { density=3.0, friction=0.8, bounce=0.3, shape=pentagonShape } )
------------------------------------------------
Parameters:


object
object: A display object.


bodyType
string: The body type may be specified in an optional string parameter before the first body element. The possible types are “static”, “dynamic” and “kinematic”, and the default type is “dynamic” if no value is specified.
字串:身型,可以在一個可選的字符串參數在第一個 body元素。可能的類型是“靜態“,“動態”和“運動“,而默認類型是“動態“如果沒有指定值。


density 密度
number: Multiplied by the area of the body’s shape to determine mass. Based on a standard value of 1.0 for water. Lighter materials (such as wood) have a density below 1.0, and heavier materials (such as stone) have a density greater than 1.0. Default value is 1.0.
數值:乘以面積身體的形狀,以確定質量。基於對標準值1.0的水。更輕的材料(如木材)的密度小於 1.0,和重的材料(如石頭)有密度大於1.0。默認值是1.0。


friction
number: May be any non-negative value; a value of 0 means no friction and 1.0 means fairly strong friction. The default value is 0.3.
摩擦力
數值:可以是任何非負價值;值0意味著沒有摩擦,1.0表示比較強烈的摩擦。默認值是0.3。


bounce
number: Determines how much of an object’s velocity is returned after a collision. The default value is 0.2.
彈跳
數值:確定一個物件的速度發生碰撞後返回的值。默認值是0.2,數字越小,彈跳越小


radius半徑
number: Radius of the bounding circle.
數值:圓的半徑邊界。


shape
number: Shape value in the form of a table with the shape vertices, {x1,y1,x2,y2,...,xn,yn}. For example: squareShape = { -20,-10, 20,-10, 20,10, -20,10 }
形狀
數值:形狀值表的形式與形狀頂點,{x1,y1,x2,y2,...,xn,yn}。例如:squareShape={-20,-10,20,-10,20,10,-20,10}


Returns:
None
沒有回傳值


Remarks:
Supported on operating systems and platforms for build numbers shown:
備註:
支持的操作系統和平台,建立數字所示:
Mac OS X:Build 2010.222
Windows: Build 2010.222
iOS: Build 2010.222
Android: Build 2010.222

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 17 週二 201117:19
  • Corona Physics Joints 物理節點

Physics Joints 物理節點


Joints節點的

Joints are used to assemble more complex game objects from multiple rigid bodes. For example, joints would be used to join the limbs of a ragdoll figure, or the wheels of a car.
接頭是用來組裝更複雜的遊戲對象從多個剛性好兆頭。例如,將用於關節四肢加入一個布娃娃形象,或者是輪子的汽車。


Box2D includes a number of different joint types, each with different parameters and functions. Some joint types can be powered by motors, and others are subject to various physical restrictions in their ranges of motion.
Box2D中包括了一些不同類型的聯合,每一個不同的參數和功能。一些合資類型可以由電動機驅動,和其他人受到各種物理限制其活動範圍的議案。


The simplest joint type is the “pivot” joint, which joins two objects at a single pivot point, and is illustrated in the “Bridge” and “Chains” sample projects.
最簡單的聯合,一種是“支點“的聯合,它連接兩個對象在一個單一的支點,並體現在“Bridge“和“Chains“樣本項目。


To construct a joint, first construct the bodies that will be joined, and then submit those bodies to the desired joint constructor function.
要構造一個關節,首先構造的機構將被加入,然後提交這些機構所需的關節構造函數。


Pivot joint樞軸接頭


A pivot joint (also known as a “revolute joint” in Box2D terms) joins two bodies at an overlapping point. The initial arguments are the two bodies joined, followed by an anchor point in the global coordinates of the world.
一個支點聯合(也稱為“旋轉關節“在Box2D計算)連接兩個機構在一個重疊點。最初的參數是兩個機構的加盟,其次是錨點在全球坐標世界。


Pivot joints can optionally be constrained in their range of rotation. For example, if constructing a “ragdoll” figure, the head/neck joint would have a limited range of angular motion.
樞軸接頭可以選擇受限制的範圍內旋轉。例如,如果構建一個“布娃娃“的人物,頭部/頸部的聯合將有一個有限的範圍內的角運動。
----------------------
myJoint = physics.newJoint( "pivot", crateA, crateB, 200,300 )
-----------------------
Joint motors 聯合馬達


myJoint.isMotorEnabled -- (boolean)
myJoint.motorSpeed
myJoint.motorTorque  -- (get-only)
myJoint.maxMotorTorque  -- (set-only)
By default, joint motors have a fairly weak maximum torque, and therefore setting motorSpeed may appear to have little visible effect. Therefore, you should generally set maxMotorTorque to a high value (such as 100000) if you are trying to move any significant mass, such as rotating a wheel to power a car.
默認情況下,聯合電機有一個比較脆弱的最大扭矩,因此設置 motorSpeed​​可能似乎沒有什麼明顯的影響。因此,你應該設置 maxMotorTorque一般為較高的值(如100000),如果你試圖移動任何重大質量,如旋轉的輪子來驅動汽車。


Rotation limits旋轉限制


Pivot joints can optionally be constrained in their range of rotation. For example, if constructing a "ragdoll" figure, the head/neck joint would have a limited range of angular motion. These rotation limits are specified in degrees:
樞軸接頭可以選擇受限制的範圍內旋轉。例如,如果構建一個“布娃娃“的人物,頭部/頸部的聯合將有一個有限的範圍內的角運動。這些限制指定旋轉度:
---------------------------
myJoint.isLimitEnabled = true -- (boolean)
 myJoint:setRotationLimits( -45, 45 )
a1, a2 = myJoint:getRotationLimits()
--------------------------
Other attributes: 其它屬性
-------------------
myJoint.jointAngle -- (get-only; value in degrees)
myJoint.jointSpeed -- (get only; value in degrees per second)
-------------------
Distance joint距離聯合


A distance joint joins two bodies at a fixed distance. The initial arguments are the two bodies joined, followed by an (x,y) anchor point for each body. Anchor points are declared in the world coordinates.
加入聯合的距離兩個機構在一個固定的距離。最初的參數是兩個機構的加盟,其次是從(x,y)的定位點為每個機構。錨點宣布在世界上的坐標。
-----------------------
myJoint = physics.newJoint( "distance", crateA, crateB, crateA.x,crateA.y, crateB.x,crateB.y )
---------------------
Other attributes:其它屬性


myJoint.length
myJoint.frequency
myJoint.dampingRatio
length is the distance between the anchor points, which should not be zero or very short (you should use a pivot joint if you need to directly anchor one body to another).
長度是定位點之間的距離,不應是零或非常短(你應該使用一個樞軸接頭,如果您需要直接錨一體到另一個)。
frequency is the mass-spring damping frequency (in Hz)
頻率是質量彈簧阻尼頻率(赫茲)


dampingRatio ranges from 0, for no damping, to 1, for critical damping.
dampingRatio範圍為0,沒有阻尼,為 1,臨界阻尼。


Piston joint活塞聯合


A piston joint (also known as a “prismatic joint” in Box2D terms) joins two bodies along a single, restricted axis of motion, like the pistons or a shock absorber in a car. The initial arguments are the two bodies joined, followed by an anchor point in the first body and a vector defining the axis along which motion is allowed.
一個活塞聯合(也稱為“棱柱聯合“在Box2D計算)沿著連接兩個機構單一,限制軸的運動,如活塞或在汽車減震器。最初的參數是兩個機構的加盟,其次是錨點在首體與向量定義軸沿此議案是允許的。
-----------------------------
myJoint = physics.newJoint( "piston", crateA, crateB, crateA.x,crateA.y, axisDistanceX,axisDistanceY )
(Note: at least one of the bodies should be dynamic, with non-fixed rotation.)
-----------------------------
Joint  motors聯合馬達
A piston joint may also be driven by a motor. Unlike the pivot joint, this motion will be linear, along the specified axis, rather than rotational.
一個聯合也可能是活塞驅動電機。不同的是樞軸接頭,這項議案將是線性的,沿指定軸,而不是轉動。
-------------------------------------
myJoint.isMotorEnabled -- (boolean)
myJoint.motorSpeed -- (linear speed, in units of pixels per second)
myJoint.motorForce  -- (get-only)
myJoint.maxMotorForce  -- (set-only)
-------------------------------------
Motion limits極限運動
In addition, limits on its range of linear motion may be specified:
此外,它的範圍限制在直線運動可以指定:
-----------------------
myJoint.isLimitEnabled = true -- (boolean)
myJoint:setLimits( 100, 200 )
p1, p2 = myJoint:getLimits()
-----------------------
Other attributes:其它屬性
-------------------------------
myJoint.jointTranslation -- (get-only; linear value in pixels)
myJoint.jointSpeed -- (get only; value in pixels per second)
-------------------------------


Friction joint聯合摩擦
A friction joint is a special kind of pivot joint that resists motion, and is therefore “sticky”:
摩擦聯合是一種特殊類型的支點聯合抵制運動,因而是“粘“:
-------------------------
myJoint = physics.newJoint( "friction", crateA, crateB, 200,300 )
-------------------------
It exposes only two attributes:
它暴露了只有兩個屬性:
--------------------
myJoint.maxForce
myJoint.maxTorque
--------------------


Weld joint焊接接頭
A weld joint “welds” two bodies together at a specified point in world coordinates:
一個焊接接頭“焊接“兩個機構共同在一個指定的點在世界坐標:
------------------------
myJoint = physics.newJoint( "weld", crateA, crateB, 200,300 )
--------------------------
This joint does not move or rotate at all, and so it exposes no attributes.
However, due to mathematical approximation, this joint may appear slightly “soft” during motion, and so if you want to rigidly bond multiple shapes together, you may want to specify them as multiple body elements within a single complex body, rather than using weld joints.
這一聯合並不在所有移動或旋轉,因此它沒有公開的屬性。
然而,由於數學近似,這一聯合可能出現輕微的“軟”運動期間,因此如果你想多個形狀硬性粘結在一起,你可能要指定它們作為多體元素在一個複雜的機構,而不是用焊接頭。


Wheel joint輪子聯合
A wheel joint (also known as a “line joint” in Box2D terms) combines a piston and a pivot joint, like a wheel mounted on the shock absorber of a car. Most of its properties are inherited from the standard piston joint; the difference is that the body at the end of the axis is allowed to rotate freely.
一個輪聯合(也稱為“行聯合“在Box2D計算)結合了活塞和一個支點聯合,像一個車輪安裝在減震器的汽車。它的大部分特性都繼承自標準活塞關節;所不同的是,該機構在結束軸可以自由旋轉。
-------------------
myJoint = physics.newJoint( "wheel", crateA, crateB, crateA.x,crateA.y, axisDistanceX,axisDistanceY )
---------------------


Joint motors聯合馬達
Like a piston joint, the “shock absorber” portion of a wheel joint may be driven by a joint motor. This motion will be linear, along the specified axis, rather than rotational.
像活塞聯合,“減震器”輪聯合部分可能是由聯合汽車。這項議案將是線性的,沿指定軸,而不是轉動。
--------------------------
myJoint.isMotorEnabled -- (boolean)
myJoint.motorSpeed -- (linear speed, in units of pixels per second)
myJoint.motorForce  -- (get-only)
-- myJoint.maxMotorForce  -- (not currently supported in Box2D library; known bug)
----------------------------


Motion limits極限運動
In addition, limits on its range of linear motion may be specified:
此外,它的範圍限制在直線運動可以指定:
-----------------
myJoint.isLimitEnabled = true -- (boolean)
myJoint:setLimits( 100, 200 )
p1, p2 = myJoint:getLimits()
----------------------------
Other attributes:
-----------------------
myJoint.jointTranslation -- (get-only; linear value in pixels)
myJoint.jointSpeed -- (get only; value in pixels per second)
--------------------------


Pulley joint 滑輪聯合


A pulley joint attaches two bodies with an imaginary rope whose length remains constant: if one body is pulled down, the other one will move up.
滑輪兩個機構聯合重視與一個假想的繩子的長度保持不變:如果一個人身體拉下來,其他人會向上移動。


This constructor is a bit complicated, because it must specify a joint anchor point within each body, and also a stationary anchor point in world coordinates for each side of the “rope” to hang from. Finally, there is a “ratio” property to optionally simulate a block and tackle arrangement, in which one side of the rope moves faster than the other. By default, this ratio is 1.0, which simulates a simple pulley.
此構造是一個有點複雜,因為它必須指定一個聯合機構在每個定位點,也是一個固定的定位點在世界坐標,每一方的“繩索“,以懸掛。最後,有一個“比“屬性有選擇地模擬塊和解決的安排,其中一側的繩索移動速度比其他。默認情況下,這個比例是1.0,它模擬一個簡單的滑輪。
-------------------------
myJoint = physics.newJoint( "pulley", crateA, crateB, anchorA_x,anchorA_y, anchorB_x,anchorB_y, crateA.x,crateA.y, crateB.x,crateB.y, 1.0 )
-------------------------


It exposes the following read-only attributes:
它暴露了以下只讀屬性:
myJoint.length1 -- (get-only; value in pixels)
myJoint.length2 -- (get-only; value in pixels)
myJoint.ratio -- (get-only)
----------------------------

Touch joint觸摸聯合

A touch joint (based on the Box2D “mouse joint”) connects a single object to the current position of an onscreen touch. This connection is an elastic joint with specifiable strength and behavior, but since it is impossible to apply infinite forces to the simulation, the dragged object may "lag behind" a rapidly moving touch. However, this method allows far more realistic behavior than the non-physical drag method demonstrated in the earlier "DragPlatforms" sample.
一個觸摸聯合(基於 Box2D的“鼠標聯合“​​)連接一個對象到目前位置屏幕上的觸摸。這種連接是一種具有彈性關節可指定的力量和行為,但因為它是無窮的力量無法適用於模擬,拖動的對象可能“落後“快速移動的接觸。然而,這種方法允許更為現實的行為比非物理拖動方法表現在早期的“DragPlatforms“樣本。


For an example of touch joints, including their use with multitouch, see the "DebugDraw" sample code.
舉個例子觸摸關節,包括他們使用多點觸控,看到“DebugDraw“示例代碼。
--------------------
myJoint = physics.newJoint( "touch", crate, targetX,targetY )

---------------------------


The initial values of targetX and targetY should be given in world coordinates, but represent the target point on the object. For example, to drag the above object by its center point, you could do the following:
初始值targetX和targetY應在世界坐標,而是代表目標指向的對象。例如,要拖動上述對象的中心點,你可以做以下幾點:
----------------
touchJount = physics.newJoint( "touch", crate, crate.x, crate.y )
------------------------


Alternatively, to drag an object by the point it was touched on:
另外,要拖動的對象由點上它被碰到:
----------------
touchJount = physics.newJoint( "touch", crate, event.x, event.y )
------------------------
...where the "event" is passed by a touch listener. This behavior is illustrated in the "DebugDraw" sample code.
..這裡的“事件“是通過一個觸摸聽眾。這種現象是說明了“DebugDraw“示例代碼。
Note: because the touch joint can follow any (x,y) values, it can also be used for things besides tracking a touch: for example, it could be used to make an object follow a path, if that path was specified as a series of (x,y) values. This should make it useful for Flight Control-style line following applications, among other things.
注意:因為觸摸關節可以按照任何(的x,y)值,也可用於跟踪的東西,除了一個觸摸:例如,它可以用來使物體遵循的路徑,如果路徑被指定為一系列(的x,y)值。這應該是有用的飛控式線以下的申請,除其他事情。


In general, a touch joint creates a temporary elastic joint between the object and your finger, which makes the object attempt to follow the touch. But since the object remains under simulation, its motion may be stopped by other solid objects, and will interact fully with the other bodies in the world. Also, the object will rotate realistically under gravity when "picked up by one end". (To avoid this behavior, you can connect the touch joint to the object's center of mass rather than to the specific point on the object that you touched.)
一般來說,觸摸聯合創建一個臨時對象之間的彈性關節和你的手指,這使得該對象企圖跟隨接觸。但由於對象仍然處於模擬,其運動可能會停止其他固體物體,並將充分互動與其他機構在世界上。此外,該對象將在重力作用下旋轉切實當“拾起一結束“。 (為了避免這種行為,您可以觸摸到該對象聯合的質心,而不是具體的指向對象,你感動。)


Joint target聯合目標

The touch-following behavior of touch joints is created by passing the current touch (x,y) position to the joint:
觸摸觸摸關節以下行為是創建通過目前的接觸(的x,y)位置的聯合:


myJoint:setTarget( targetX, targetY )


While the updated (targetX, targetY) values will normally come from a touch, any values can be passed. For example, the object could be made to follow another object, or track the points of a path.
而最新的(targetX,targetY)值通常來自觸覺,可以傳遞任何值。例如,對象可以是另一個對象作出跟進,或追踪點的道路。


The current target values can also be accessed:
目前的目標價值,也可訪問:
-------------------------
targetX, targetY = myJoint:getTarget()
-------------------------


Maximum force最大力量


The overall speed or "lag" of the joint depends on the force exerted:
整體速度或“滯後“的聯合取決於施加的力:
-------------------
myJoint.maxForce = 10000
force = myJoint.maxForce
------------------------
By default, this attribute is set to 1000 times the mass of the body, which allows for fairly rapid dragging.
默認情況下,這個屬性設置為 1000倍,大量的身體,使之有相當快速拖動。


Frequency頻率

The mass-spring damping frequency of the elastic joint (in Hz):
質量的彈簧的彈性阻尼頻率聯合(單位 Hz):
------------------------
myJoint.frequency = 50
frequency = myJoint.frequency
----------------------

Damping ratio阻尼比

The damping ratio of the elastic joint, ranging from 0, for no damping, to 1, for critical damping:
阻尼比的彈性關節,從0,沒有阻尼,為 1,臨界阻尼:
---------------------
myJoint.dampingRatio = 0.2
damping = myJoint.dampingRatio
---------------------
The above attributes behave similarly to their counterparts in the Distance joint (see above). As in that case, the default values should work fairly well, but you may want to experiment with other values.
上述屬性的行為同樣的同行在遠程聯合(見上文)。正如在這種情況下,默認值應該還算不錯,但你可能要進行實驗的其他值。


Dragging objects with touch joints拖動對象觸摸關節


Here is a general function for making a physics object draggable, as seen in the "DebugDraw" sample code:
這裡是一個通用函數用於製造一個物理對象拖動,就像在“DebugDraw“示例代碼:
-------------------
local physics = require("physics")
physics.start()
system.activate( "multitouch" )
 ----------------------
-- A general function for dragging physics bodies
一個通用函數物理機構拖拉
-------------------------
local function dragBody( event )
        local body = event.target
        local phase = event.phase
        local stage = display.getCurrentStage()
 
        if "began" == phase then
                stage:setFocus( body, event.id )
                body.isFocus = true
 
                -- Create a temporary touch joint and store it in the object for later reference
                body.tempJoint = physics.newJoint( "touch", body, event.x, event.y )
 
        elseif body.isFocus then
                if "moved" == phase then
                
                        -- Update the joint to track the touch
                        body.tempJoint:setTarget( event.x, event.y )
 
                elseif "ended" == phase or "cancelled" == phase then
                        stage:setFocus( body, nil )
                        body.isFocus = false
                        
                        -- Remove the joint when the touch ends                 
                        body.tempJoint:removeSelf()
                        
                end
        end
 
        -- Stop further propagation of touch event
        return true
end
-------------------------------------
-- Add a physics object 添加一個物理對象
--------------------
crate = display.newImage( "crate.png" )
physics.addBody( crate, { density=0.8 } )
-------------------
-- Make object draggable 使對象可拖動
---------------------------
crate:addEventListener( "touch", dragBody )
------------------------


Common features of all joints
所有接頭的共同特點
In addition to the above, all joint types share several common attributes and functions:
除上述情況外,所有類型共享聯合幾個共同的屬性和功能:
------------------
myJoint:getAnchorA
myJoint:getAnchorB
-------------------
A function that returns the (x,y) coordinates of the joint’s anchor points within objects A and B, which are the two joined objects. The values are given in the local coordinates of each object, so an anchor point at the center of the object would be at position (0, 0).
函數返回的(x,y)坐標的聯合的錨點在對象 A和B,這是兩個參與對象。給出的值在每個對象的局部坐標,使錨點在該中心的對象將在位置(0,0)。
----------------------------
x, y = myJoint:getAnchorA()
x, y = myJoint:getAnchorB()
----------------------------


myJoint:getReactionForce
A function that returns the reaction force (in Newtons) at the joint anchor in the second body.
一個函數,返回反作用力(在牛頓)在接頭錨點第二身體。
-------------------
reactionForceX, reactionForceY = myJoint:getReactionForce()
------------------------


myJoint.reactionTorque
A read-only property that returns the reaction torque (in N*m) at the joint anchor in the second body.
只讀屬性,返回反作用力矩(牛頓米)在接頭錨點第二身體。
------------------
reactionTorque = myJoint.reactionTorque
---------------------


Destroying joints關節破壞
To destroy an existing joint, and detach the two bodies (which may then collide), use removeSelf():
要銷毀現有的聯合和分離的兩個機構(可能當時發生碰撞),使用removeSelf():
-----------------
myJoint:removeSelf()
------------------

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 17 週二 201115:03
  • Corona Configuration Options 配置選項

Configuration Options配置選項


Corona projects may be configured with two optional files: config.lua and build.settings, each of which use Lua table syntax and should be located in the project directory. The build.settings file contains instructions for the build process, and config.lua is compiled into your project and accessed at runtime.
Corona項目可能配置了兩個可選文件:config.lua和build.settings,每個表使用Lua語法和應位於項目目錄。該文件包含指令build.settings生成過程,並 config.lua編譯到你的項目和訪問在運行時。


Runtime Configuration: config.lua
運行時配置:config.lua


Several runtime properties can be specified in a config.lua file, which can be included in the project directory. This section discusses the currently available options.
幾個運行時屬性可以指定在一個 config.lua文件,它可以包含在項目目錄。本節討論了目前可用的選項。


Dynamic Content Scaling
動態內容縮放


(For a detailed introduction to this feature, see this blog post.)
(有關詳細介紹了這個功能,看到這個博客帖子。)


Content scaling features are useful for multi-screen development. For example, iPhone projects designed for a 320 pixel wide screen can be upscaled to the 480 pixel wide screen on Android devices, making porting much easier, since code and assets do not need to be revised.
內容縮放功能是有用的多屏的發展。例如,iPhone的項目設計為320像素寬屏幕可放大的480像素的寬屏幕Android設備,使移植容易得多,因為代碼和資產並不需要加以修訂。


Also, Corona now targets iOS 4.0 in iPhone builds (while remaining iOS 3.0-compatible). This means that pre-iPhone 4 content will no longer upscale automatically to the larger iPhone4 screen resolution. As a result, content scaling will generally be required in new iPhone apps.
此外,現在的目標的iOSCorona在iPhone4.0版本(而其餘的iOS3.0兼容)。這意味著,前iPhone4內容將不再自動高檔大iPhone4屏幕分辨率。因此,內容比例一般都需要在新的iPhone應用程序。


The basic idea behind dynamic content scaling is that you can tell Corona that your content was originally authored for a particular screen size. Then you can choose how your app should be scaled if it runs on a device whose physical screen size is different from the original.
背後的基本思想動態內容縮放是你可以告訴您的內容Corona最初創作的一個特定的屏幕尺寸。然後你可以選擇你的程序應該如何縮放,如果它運行在一個物理設備,其屏幕尺寸從原來的有所不同。


To activate dynamic content scaling, create a config.lua file (see below) and use a scale other than "none", as shown below.
要激活動態內容縮放,創建一個 config.lua文件(見下文),並使用其他的規模比“無“,如下圖所示。


Example:


-------------------------------
application =
{
        content =
        {
                width = 320,
                height = 480,
                scale = "letterbox"
        },
} 
-----------------------
Note 注意:
If you are building an application to run on a single device then it is not necessary to specify any content height, width, or scaling options.
如果您正在構建一個應用程序運行在一台設備則沒有必要指定任何內容的高度,寬度或縮放選項。


If your application does support running on devices with different screen dimensions, the width and height MUST be the value of the target device in portrait orientation. 
如果您的應用程序不支持的設備上運行的不同屏幕尺寸,寬度和高度必須是價值目標設備在縱向方向。


These values are not dependent on the orientation mode of your application. If your app runs in landscape mode, you still set these values to the portrait width and height. 
這些值不依賴於你的應用方向模式。如果你的程序運行在橫向模式下,你仍然設置這些值的肖像寬度和高度。


Use the "orientation" setting in the build.settings file to define the orientation modes supported by the application.
使用“方向“設置在build.settings文件來定義的方向所支持的應用模式。


Note 
about trailing commas
In the examples on this page you'll notice that the tables have commas after the last entries. These are referred to as trailing commas. In Lua, trailing commas are optional, but always valid. Source: Programming in Lua, 2nd Edition by Roberto Ierusalimschy
注意:
關於尾隨逗號
在此頁上的例子,你會發現,現在情況發生了逗號後,最後條目。這些被稱為尾隨逗號。在Lua中,尾隨逗號是可選的,但始終有效。來源:編程 Lua中,第二版由Roberto Ierusalimschy


The value of "content" should be a table containing the following key-value pairs:
該值“內容“應該是一個包含以下關鍵值對:


width (number) - the width, in pixels, of the original target device (in portrait orientation)
寬度(數字) -的寬度,以像素為單位,原來的目標設備(縱向)


height (number) - the height, in pixels, of the original target device (in portrait orientation)
高(數字) -的高度,以像素為單位,原來的目標設備(縱向)



scale (string) - the type of auto-scaling, from one of:
量表(字符串)- 類型的自動縮放,從一個:


"none" - turns off dynamic content scaling
“無“- 關閉動態內容縮放


"letterbox" - uniformly scales up content as much as possible, while still showing all content on the screen. 
“信箱“ -統一尺度註冊內容盡可能,而仍然顯示在屏幕上的所有內容。
This is similar to watching a widescreen DVD on a non-widescreen TV set, except that you can use offstage content to fill the "bleed" areas rather than displaying black bars.
這類似於觀看寬屏 DVD在非寬屏電視,但你可以用台下內容來填充“流血“的地區,而不是顯示黑條。


"zoomEven" - uniformly scales up content to fill the screen, while preserving aspect ratio. Some content may appear offscreen, if the new screen has a different aspect ratio
“zoomEven“ -均勻可擴展至內容來填充屏幕上,同時保持高寬比。有些內容可能會出現屏幕外,如果新的屏幕上有一個不同的寬高比


"zoomStretch" - non-uniformly scales up content to fill the screen. All content will remain onscreen, but it may be stretched vertically or horizontally.
“zoomStretch“ -非均勻可擴展至內容來填充屏幕。所有內容將保持在屏幕上,但它可能是水平或垂直拉伸。


The content width and height allow you to choose a virtual screen size that is independent of the physical device screen size. This will generally be the size of your original target device -- which often means the original iPhone dimensions of 320 x 480, as in the SDK code samples.
寬度和高度的內容讓您選擇一個虛擬屏幕大小是獨立於物理設備的屏幕大小。這通常會在你原來的大小目標設備- 這往往意味著原有的iPhone尺寸為 320× 480,作為 SDK中的代碼示例。


You are then free to code as if you are positioning objects to the virtual screen. Touch events (and other hit events) will be remapped to the correct location on all screens when dynamic content scaling is active.
然後,您可以自由地代碼,如果你是定位對象的虛擬屏幕。觸摸事件(和其他襲擊事件)將被重新映射到正確的位置時,屏幕上的所有動態內容縮放活躍。


These virtual (i.e., content) dimensions are accessible via display.contentWidth and display.contentHeight. Because of this, the concept of stage width and height, e.g., display.stageWidth and display.stageHeight, has been deprecated in favor of content width and height.
這些虛擬(即內容)的尺寸都可以通過 display.contentWidth和display.contentHeight。正因為如此,這一概念的舞台寬度和高度,如display.stageWidth和display.stageHeight,已被否決贊成內容的寬度和高度。


By default, if no content size is specified, the content width and height returned will be the same as the physical screen width and height of the device. If you are specify a different content width and height in config.lua, the content width and height will take on those values.
默認情況下,如果沒有指定內容的大小,寬度和高度的內容將返回相同的物理屏幕的寬度和高度的裝置。如果您指定一個不同內容的寬度和高度config.lua,寬度和高度的內容將在這些價值觀。


When a scale is set in config.lua, the content will be rescaled to fit the screen. As far as your code is concerned, however, positions should still be specified in terms of the virtual screen coordinates.
當一個規模是集config.lua,內容將被重新調整以適應屏幕。至於你的代碼來說,然而,職位仍然應該在條款中指定的虛擬屏幕坐標。


For example, in the "Fishies" sample code (SampleCode/Graphics/Fishies), there is a config.lua file in which the content width is 320, the height is 480, and the scale is "zoomEven". If you were to view this in iPad, all the content (including the background image and the images of the fish) would be scaled to fit the iPad's screen size (1024x768) even though the images were intended for the smaller iPhone screen (320x480).
例如,在“Fishies“示例代碼(SampleCode/圖形 / Fishies),有一個 config.lua文件,其中內容的寬度為 320,高度為480個,規模是“zoomEven“。如果你要查看此在iPad,所有的內容(包括背景圖片和圖像的魚)將調整為適合 iPad的屏幕尺寸(1024 × 768),即使這些照片被用於較小的iPhone屏幕(320x480) 。


Depending on which dynamic scaling mode is used, and the aspect ratio of the device used to view the content, some of the original content may be scaled in such a way that portions are offscreen. Therefore, display.viewableContentWidth and display.viewableContentHeight have also been provided. These properties give you the currently viewable area of the screen, within the coordinate system of the original content. The Fishies sample leverages this so that the fish continue to swim only on the visible portions of the virtual screen.
根據哪個動態縮放模式時,和長寬比的設備用於查看的內容,一些原來的內容可能被縮小在這樣一種方式,部分是離屏。因此,display.viewableContentWidth和display.viewableContentHeight也已提供。這些屬性使您目前的屏幕可視區域內的坐標系統中的原始內容。樣品的Fishies利用這一點以便繼續游泳的魚只在可見部分的虛擬屏幕。


Dynamic Content Alignment動態內容的對齊方式

By default, dynamically scaled content is centered when shown on different screens. For example, in "letterbox" scaling mode, any additional screen area will be evenly divided between both sides, and in "zoomEven" mode, the area cropped will be the same on both sides.
默認情況下,中心內容是動態縮放時,顯示在不同的屏幕。例如,在“信箱“縮放模式下,任何額外的屏幕面積將是雙方平分,並在“zoomEven“模式,該地區將出現同樣的兩側。


However, there are cases where you might not want the content to be centered. For example, when scaling from the iPhone to the taller and skinnier screen of the Droid, you may not want the additional screen area at both the top and the bottom. Instead, you may want all of the added area shown the bottom, if your design features a navigation bar that should be aligned with the top of the screen.
然而,在一些情況下,您可能不希望內容居中。例如,在縮放時從 iPhone的屏幕高和瘦對 Droid,你可能不希望在更多的屏幕區域的頂部和底部。相反,你可能需要添加的所有區域中顯示的底部,如果您的設計採用了導航欄,應與頂部的屏幕。


For such cases, you may optionally specify the content alignment in both the x- and y-directions:
對於這種情況,你可以選擇指定內容的對齊方式在x和y方向:

application =
{
        content =
        {
                width = 320,
                height = 480,
                scale = "letterbox",
                xAlign = "left",
                yAlign = "top"
        },
} 


xAlign

A string that specifies the alignment in the x-direction for the position of the reference screen (which may be scaled) relative to the physical screen. It can be one of the following values:
xAlign


一個字符串,指定路線在x方向的位置的​​參考屏幕(可縮放)相對於物理屏幕。它可以是以下值:


*"left"
*"center" (Default)
*"right"


yAlign

A string that specifies the alignment in the y-direction for the position of the reference screen (which may be scaled) relative to the physical screen. It can be one of the following values:
一個字符串,指定路線在y方向的位置的​​參考屏幕(可縮放)相對於物理屏幕。它可以是以下值:
*"top"
*"center" (Default)
*"bottom"


Note
previous versions of Corona defaulted to left/top alignment rather than centered alignment, so you can restore the older behavior by setting xAlign to "left" and yAlign to "top" in your config.lua file.
以前版本的Corona默認為左/頂端對齊,而不是居中對齊,這樣你就可以恢復舊的行為設定 xAlign“左“和yAlign到“頂“在你的config.lua文件。


Dynamic Content Properties動態內容屬性

A number of methods are exposed within Lua to help you work with scaled content:
一個數字的方法暴露在Lua中,以幫助您的工作內容與規模:


display.contentWidth
By default, this is the same as the physical screen width in pixels. If config.lua specifies a reference width, it takes on that value. For example, this would return 320 in the above examples. This is referred to as the "reference screen width" below.
默認情況下,這是一樣的物理屏幕的寬度,以像素。如果config.lua指定一個寬度,它需要這個值。例如,這將返回320以上的例子。這被稱為“參考屏幕寬度“下面。


display.contentHeight
By default, this is the same as the physical screen height in pixels. If config.lua specifies a height it takes on that value. For example, this would return 480 in the above examples. This is referred to as the "reference screen height" below.
默認情況下,這是一樣的物理屏幕的高度,以像素。如果config.lua指定高度需時該值。例如,這將返回480以上的例子。這被稱為“參考屏幕高度“下面。


display.viewableContentWidth


display.viewableContentHeight


Returns the width and height of the viewable content, which may be different than the reference content dimensions if the target screen has a taller or wider aspect ratio.
返回的寬度和高度的可視內容,這可能是不同的尺寸比參考的內容,如果屏幕上有一個更高的目標或更大的寬高比。


Note that these values are expressed in reference screen units: for example, content with a reference size of 320 x 480 upscaled to iPad using "zoomEven" will be cropped at the top and the bottom, and therefore the viewableContentHeight will return a value like 426 rather than the original value of 480. This lets you detect the "safe zone" for your content when deploying across multiple screens.
請注意,這些值是在參考屏幕單位表示:例如,內容與參考尺寸為 320× 480上變換到ipad使用“zoomEven“將出現在頂部和底部,因此viewableContentHeight將返回值,如426而不是原來的值480。這可以讓你發現的“安全區“為您的內容時,部署在多個屏幕上。


Note注意:


There is currently a known bug where these methods may return misleading values in "letterbox" scaling mode; this will be fixed in a future release.
目前有一個已知的錯誤而這些方法可能誤導返回值“letterbox“的縮放模式,這將是固定在以後的版本。


display.screenOriginX
display.screenOriginY
Returns the x-distance and y-distance from the top-left of the reference screen to the top-left of the current screen, in reference screen units. For example, in "letterbox" or "zoomEven" scaling modes, there may be added area (or cropped area) on the current device screen. These methods let you find out how much visible area has been added or removed on the current device.
返回的x和y的距離,距離左上角參考屏幕左上角的當前屏幕,屏幕的單位參考。例如,在“letterbox“或”zoomEven“縮放模式,有可能會增加面積(或裁剪區)對當前設備的屏幕。這些方法讓你了解多少可見區域已被添加或刪除當前設備。


Dynamic Image Resolution動態圖像分辨率

Dynamic image resolution lets you automatically swap in higher-resolution versions of your images on higher-resolution devices, without having to change your layout code.
動態圖像分辨率可以自動交換在更高分辨率的版本上的圖像分辨率更高的設備,而無需改變你的佈局代碼。


The simplest example is the iPhone 4, which has a resolution of 640 x 960, or exactly twice the resolution of the iPhone 3GS, which is 320 x 480. You can use content scaling in your config.lua file to scale up your original 320 x 480 application to fill the iPhone 4's screen. This works well, but does not make full use of the higher resolution — your images will not be as crisp and detailed as they could be, given all the added pixel density available.
最簡單的例子是iPhone 4,它的分辨率為 640 × 960,或究竟兩倍的iPhone 3GS的決議,這是320 × 480。您可以使用內容縮放在config.lua文件,以擴大原來的320 × 480的應用,填補了iPhone 4的畫面。這個效果很好,但不充分利用具有更高的分辨率 - 您的圖片不會像清晰和詳細,因為他們可能是,由於所有增加像素密度。


To address this issue, Apple defined a naming convention for images. Under Apple's method, developers create double-sized versions of their base images and add an "@2" suffix to their filenames, and the double-resolution versions of the images are automatically substituted on the double-resolution iPhone 4.
為了解決這個問題,蘋果定義的命名約定的圖像。根據蘋果公司的方法,開發人員創建雙大小版本的形象和他們的基地添加一個“@ 2”後綴的文件名,和雙決議版本的圖像會自動取代對雙決議 iPhone 4。


However, while Apple's system works for the iPhone 4, which is exactly 2x the resolution of previous iPhones, a more robust system is needed to support full multi-platform development, where different device resolutions do not fall neatly into a 2:1 ratio.
不過,雖然蘋果的系統的工程,iPhone 4,而這正是以前的2倍iPhone的決議,一個更強大的系統需要支持完整的多平台開發,不同的設備分辨率不屬於成一個整齊的比例為 2:1。


Instead, Corona uses a more general method for defining alternate images, which has two advantages:
相反,Corona使用更通用的方法替代圖像定義,它有兩個優點:


Corona lets you select your own image naming patterns. The "@2" convention can be used, but so can any other naming suffixes defined by you.
Corona讓你選擇自己的形象的命名方式。在“@ 2”公約可以使用,但至今不能有任何其他的命名後綴由您定義。


Corona does not require you to know the exact resolution of the target device — which may be unknown, especially for the growing range of Android devices. Instead, you can predefine several image resolution choices, and Corona will automatically find the closest match on each device.
Corona不需要你知道確切的目標設備的決議 - 這可能是未知的,尤其是對範圍日益擴大的Andr​​oid設備。相反,你可以預先定義幾個圖像分辨率選擇,Corona會自動找到最接近的每一個設備。


To define your image naming convention, and the corresponding image resolutions, a table named imageSuffix is added to config.lua, inside the content subtable. Here is an example of a config.lua file that defines four alternative image resolutions:
要定義你的形象的命名規則,以及相應的圖像分辨率,表名為 imageSuffix添加到config.lua,裡面的內容子表。下面是一個例子一config.lua文件定義了四個替代圖像分辨率:


------------------------
application =
{
    content =
    {
        width = 320,
        height = 480,
        scale = "letterbox",
 
        imageSuffix =
        {
            ["@2"] = 2,
            ["@3"] = 3,
            ["-bar"] = 3.3,
            ["-foo"] = 4.5,
        },
    },
}
----------------------------
This is probably more complex than a real-world example would be, but it demonstrates several possibilities for image naming conventions. In this case, the file defines the "@2" suffix as referring to images with 2x the base resolution, and similarly the "@3" suffix as meaning 3x the base resolution. But any names and resolution ratios are allowed, including non-integer values, so the "-bar" suffix is defined as being 3.3x the base resolution, and the "-foo" suffix means 4.5x the base resolution.
這可能是更複雜的比真實世界的例子是,但它演示了幾種可能的圖像命名約定。在這種情況下,該文件定義了“@2“的後綴,它是指圖像分辨率和2倍的基礎,以及類似的“@3“後綴的含義3倍基決議。但是,任何名稱和分辨率比是允許的,包括非整數值,因此,“-bar“後綴被定義為3.3x決議的基礎,而“-foo“後綴是指4.5倍的基礎決議。


With the above defined, the corresponding set of images would be created as follows. Assuming a base image named myImage.png, with a size of 100 x 100 pixels, the alternate images would be:
有了上述定義,設置相應的圖像將被創建如下。假設一個名為 myImage.png基地形象,有大小100 ×100像素,圖像的替代將是:


myImage@2.png (200 x 200 pixels)
myImage@3.png (300 x 300 pixels)
myImage-bar.png (330 x 330 pixels)
myImage-foo.png (450 x 450 pixels)


With the alternative assets in place, simply use display.newImageRect() rather than display.newImage(), setting the target height and width to the dimensions of your base image:
隨著另類資產到位,只需使用display.newImageRect()而不是display.newImage(),設置目標的高度和寬度的尺寸你的基地的形象:


display.newImageRect( "myImage.png", 100, 100 )
Corona will then choose the closest matching suffix, defined as the one whose scale is equal to or smaller than the current content scale factor, and then map that image file into the given 100 x 100 area (defined in base coordinates).
Corona將選擇最匹配的後綴,定義為一個其規模等於或小於當前內容的比例因子,然後映射到給定的圖像文件100× 100區(定義在基坐標)。


Currently, the largest possible range of scaling factors between different devices is about 2.4 to 1, so the above example is somewhat exaggerated. Today's most common case will likely be double-resolution alternate images for use with iPhone 4 and iPad, rather than this set of higher values. In the future, the range of possible cases is likely to be greater, as iOS and Android devices multiply.
目前,最大的可能範圍內不同的設備之間換算係數大約為 2.4比1,因此上面的例子是有些誇大。當今最常見的情況可能會是雙圖像分辨率交替使用與 iPhone4和iPad,而比這一套更高的價值。在未來,可能案件的範圍可能會更大,因為 IOS和Android設備繁殖。


Note that you do not need to provide all (or any) of the alternate images for every case. When you use display.newImageRect(), Corona will automatically look for the best match available for the target screen, and when that image is unavailable, it will work its way down the list of lower-resolution choices, finally falling back to the base image filename if no other choice is available.
請注意,您並不需要提供全部(或任何)的替代圖像的每一個案件。當您使用display.newImageRect(),Corona會自動尋找可用的最佳匹配為目標的屏幕,而當這種形象是不可用,其工作方式將在列表中向下較低分辨率的選擇,終於回落到基圖像文件名,如果沒有其他選擇可用。


It is likely that some images in your application are more prominent or important than others, so you can selectively add higher-resolution versions in the cases where it matters most. The caveat is that the base image called in display.newImageRect() must always exist, even if none of the alternate choices do.
很可能有些圖片在你的應用較為突出或重要的不是別人,這樣你可以有選擇地添加更高分辨率的版本,它的情況下,最重要的。需要說明的是,該基地的形象稱為 display.newImageRect()必須始終存在,即使沒有做的替代選擇。


Frame rate control
By default, the frame rate is 30 fps. We now allow you to optionally set the frame rate to 60 fps by adding the fps key to config.lua:
幀速率控制
默認情況下,幀頻為 30幀。我們現在讓你選擇設置幀頻為 60 fps的幀中加入關鍵 config.lua:
------------------------
application =
{
    content =
        {
            fps = 60,
        },
}
-----------------------


Note
To avoid image tearing, the screen refresh rate in Corona is now locked to the hardware refresh rate on the iPhone, which is 60 fps. Therefore, the Corona framerate must be a number that divides evenly into 60. We are currently assuming that setting a rate below 30 fps is not a priority, which leaves two possible choices: 30 fps and 60 fps. Values other than 60 in this setting will be ignored.
注意:
為了避免圖像撕裂,屏幕刷新率鎖定在Corona是現在的硬件更新速度的iPhone,這是60幀。因此,Corona幀率必須是一個數字的鴻溝平均分為 60。目前,我們正在制定一個假設率低於30 FPS是不是一個優先事項,這讓兩種可能的選擇:30 fps和60 fps的。 60以外的值在此設置將被忽略。


Anti-aliasing
反鋸齒
Corona uses software anti-aliasing for its vector objects. Previously, this anti-aliasing was on by default. It is now off by default, which will greatly improve performance of vector objects, and should make little visual difference on the latest high-dpi devices.
Corona使用軟件的抗混疊的矢量對象。在此之前,這種反鋸齒,是在以默認。現在是默認關閉的,這將大大提高性能的矢量對象,並應使視覺差異不大的最新高DPI設備。


To turn it on again, you must create a config.lua file and add an antialias key:
要再次打開它,你必須創建一個 config.lua文件,並添加了抗混疊的關鍵:
---------------------------------
application =
{
        content =
        {
                antialias = true,
        },
}
---------------------------------
Build Configuration: build.settings


Build-time properties can be provided in an optional build.settings file, which uses Lua syntax. An example of a build.settings file:
構建時特性可以提供一個可選 build.settings文件,它使用Lua的語法。一個例子一build.settings文件:
-----------------------------
settings =
{
        orientation =
        {
                default = "portrait",
        },
 
        iphone =
        {
                plist =
                {
                        UIRequiredDeviceCapabilities = "magnetometer",
                        UIPrerenderedIcon = true,
                },
        },
 
        build =
        {
                custom = "a1234",
        }
}
---------------------------------
You can also use dot syntax instead of a Lua table constructor to define your build settings. This alternate syntax is required for some device-specific plist keys that contain special characters, like the tilde (~). The following build.settings file demonstrates how to include both dot and table constructor syntax:
您也可以使用點語法,而不是一個 Lua表的構造來定義生成設置。這種替代語法一些設備需要特定plist中包含特殊字符鍵,如波形符(〜)。下面build.settings文件演示如何包括點和表構造語法:
------------------------------
settings =
{
    orientation =
    {
        default = "portrait",
        supported =
        {
            "portrait", "portraitUpsideDown", "landscapeRight", "landscapeLeft"
        }
    },
    
    
    iphone =
    {
        plist =
        {
            UIInterfaceOrientation = "UIInterfaceOrientationLandscapeRight",
 
            UISupportedInterfaceOrientations =
            {
                "UIInterfaceOrientationLandscapeLeft",
                "UIInterfaceOrientationLandscapeRight"
            },
            
            UIApplicationExitsOnSuspend = true,
            UIStatusBarHidden = true,
            UIPrerenderedIcon = true
            
        }
    }
}
 
 
settings.iphone.plist["UIInterfaceOrientation~ipad"] = "UIInterfaceOrientationPortrait"
settings.iphone.plist["UISupportedInterfaceOrientations~ipad"] = 
{
    "UIInterfaceOrientationPortrait",
    "UIInterfaceOrientationPortraitUpsideDown"
}
------------------------------------------
The build.settings file is used to set application orientation and auto-rotation behavior, along with a variety of platform-specific build parameters.
該 build.settings文件用於設置應用程序定位和自動旋轉行為,以及各種特定於平台的構建參數。


In addition, there is a custom build parameter for creating device builds with specific test versions of Corona. Currently, the only publicly available option is the temporary Beta 3 compatibility setting (which will be deprecated in the future), but others may be announced in the future.
此外,還有一個自定義生成參數創建設備建立與特定的測試版本的Corona。目前,唯一的公開的選擇是暫時的Beta 3的兼容性設置(這將在未來被廢棄),但其他人可能在將來公佈。


Info.plist Values (iOS)


Within build.settings, the optional “plist” table, within the “iphone” table (as shown above), can be used to set values in the compiled application’s Info.plist file. This has a number of uses, such as specifying device requirements or capabilities for the App Store. In the above example, the UIRequiredDeviceCapabilities key is set to “magnetometer”, which is required for apps using the Compass API to indicate to the App Store that they require devices with a compass. Also, the UIPrenderedIcon key is set to true, which prevents the iPhoneOS from adding the “shiny” highlight to the application icon.
在build.settings,可選“plist中“表,在“iPhone“表(如上所示),可以用來設定值在編譯的應用程序的Info.plist文件。這一個數字的用途,如指定設備的需求或功能的應用程序商店。在上面的例子中,UIRequiredDeviceCapabilities項設置為“磁力“,這是應用程序所需的API來使用羅盤指示的App Store,他們需要的設備和一個指南針。此外,UIPrenderedIcon項設置為 true,這可防止iPhone操作系統從加入“閃亮“突出顯示應用程序圖標。


For boolean values in Info.plist keys, use Lua-style booleans (true and false, without quotes) rather than Objective-C style booleans (“YES” and “NO”).
對於布爾值Info.plist中鍵,使用Lua風格的布爾值(true和false,不帶引號),而不是目的,C風格的布爾值(“是”和“NO“)。


The table name “iphone” refers to the iOS platform, which also includes the iPad.
該表命名為“iPhone“是指內部監督辦公室的平台,其中也包括在IPAD。


See the Apple developer documentation for more information on supported Info.plist values and what you can do with them.
看看蘋果開發者文檔的更多信息,價值觀和支持Info.plist中你可以與他們無關。
更多資訊請看 Apple developer documentation的supported Info部分,你可以對有關plist的value如何操作


Orientation Support (iOS) 定向支援辦公室(IOS)


The build.settings file can be used to set application orientation, including auto-orientation with the accelerometer.
該 build.settings文件可以被用來設置應用方向,包括自動方向與加速度計。


On iPhone and iPad, it is important to understand that there are actually three different things that are subject to orientation:
在iPhone和iPad,重要的是要明白,其實有三個不同的東西,受的方向:


The splash screen image初始屏幕圖像


The native UI elements, such as the keyboard and alert popups
本機用戶界面元素,如鍵盤和警報彈出窗口


The Corona canvas itself畫布本身Corona


In many cases, you may want (2) and (3) to have the same orientation, but note that there are also cases in which you want to orient them separately.
在許多情況下,您可能希望(2)及(3)有相同的方向,但是請注意,也有個案要分開的方向。


For example, you might create an iPad game with no “correct” orientation, but still want the iPhoneOS notification dialogs to appear right side up from the current player’s point of view. Alternatively, you might want to lock the orientation of the Corona canvas, because you are performing your own orientation changes using Corona animation (as shown in the Fishies sample code), but you still want the native UI elements to appear in the current orientation.
例如,您可以創建一個 iPad的遊戲,沒有“正確“的方向,但仍然希望iPhone操作系統通知對話框出現右側從目前球員的觀點。或者,您可能要鎖定方向的Corona帆布,因為你是你自己的方向的變化進行使用Corona動畫(Fishies所示的示例代碼),但你仍然希望本地UI元素出現在目前的方向。


To control these various possible scenarios, there are now three optional key/value pairs within the orientation table in build.settings: default, supported, and content. The following scenarios demonstrate usage by example.
要控制這些 various可能發生的情況,現在有三個可選的鍵 /值雙,方向表build.settings:默認,支持和內容。以下方案說明用法範例。


Auto-rotation自動旋轉
To auto-rotate to all four orientations, you could use the following build.settings file:
要自動旋轉到所有四個方向,你可以使用下面的build.settings文件
--------------------------------------------------
settings =
{
        orientation =
        {
                default = "landscapeRight",
                supported =
                {
                        "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown",
                },
        },
}
--------------------------------------------------
The default orientation setting determines the initial launch orientation on the iPhone, and also the initial orientation of the Corona simulator.
默認的方向設置確定首次推出的iPhone的方向,也是初始取向的Corona模擬器。


Note注意:
On Android, the default orientation setting has no effect. The orientation is initialized to the actual orientation of the device (unless only one orientation is specified). Also, the only supported orientations are landscapeRight and portrait. On a device, you can flip to either landscapeRight or landscapeLeft, but the OS only reports one flavor of landscape, and Corona's orientation event chooses landscapeRight.
在Android,默認的方向設置不起作用。初始化的方向與實際方向的設備(除非只有一個方向是指定)。此外,僅支持方向是landscapeRight和肖像。在設備上,您可以翻轉要么landscapeRight或landscapeLeft,但操作系統只報告一種味道的風景,和Corona的方向選擇 landscapeRight事件。


When you change the device or simulator orientation, the Corona view will auto-rotate, within the orientations supported. In addition, native UI (on the device) will auto-rotate. The auto-rotation is such that to the user, the content appears "upright". Also, the position (0,0) within Corona will correspond to the upper left-hand corner of the current screen orientation.
當您更改設備或模擬器方向,Corona視圖將自動旋轉,在方向的支持。此外,本機用戶界面(在設備)會自動旋轉。自動旋轉,這樣給用戶,內容顯示為“正氣“。此外,位置(0,0)在Corona將對應到上左角當前屏幕的方向。


Note that the iPad ignores the default setting, and attempts to launch in the current physical orientation of the device, assuming that orientation is found on the supported list. To avoid unexpected orientation display issues, it's recommended that your project's build.settings specify allowed orientations for all iPad projects.
請注意,在IPAD忽略了默認設置,並嘗試推出在當前的物理定位裝置,假設方向上找到支持列表。為了避免意外的方向顯示問題,建議該項目的build.settings指定允許的方向iPad的所有項目。


If you are writing an iPad app that supports multiple orientations, you should also provide a splash screen for each of the orientations, or the App Store reviewers may reject your app. The iPad supports the following naming conventions for orientation-specific splash screen files:
如果你正在編寫一個應用程序,支持多種 iPad的方向,你也應該提供一個啟動畫面的每個方向,或App Store的評論可能會拒絕你的應用程序。在IPAD支持以下命名約定為取向的特定啟動畫面文件:


Default-Portrait.png
Default-PortraitUpsideDown.png
Default-Landscape.png
Default-LandscapeLeft.png
Default-LandscapeRight.png


Note that the "Portrait" and "Landscape" splash screens in the list above will automatically handle two types of orientation each, unless you decide to provide more specialized files, such as "LandscapeLeft". Also, all splash screen graphics provided should be internally upright -- one common misunderstanding is that the "PortraitUpsideDown" graphic should actually be created upside down, which is incorrect.
請注意,“肖像“和“山水“撲通屏幕上述的名單將自動處理兩種類型的每個方向,除非你決定提供更專業化的文件,如“LandscapeLeft“。此外,所有閃屏圖形應提供內部直立- 一個常見的誤解是,“PortraitUpsideDown“圖形實際上應該是建立上下顛倒,這是不正確的。


Landscape orientation橫向

To support a single orientation (for example, landscape-only), build.settings should look like this:
為了支持一個方向(例如,只有景觀),build.settings應該是這樣的:
---------------------------------
settings =
{
        orientation =
        {
                default = "landscapeRight",
                supported =
                {
                        "landscapeLeft", "landscapeRight"
                },
        },
}
------------------------------------
In this sample, both of the equivalent landscape orientations are supported (landscapeRight and landscapeLeft). It has become fairly common for iPhone apps to only support one orientation, but Apple now encourages iPad developers to support all equivalent orientations: for example, a landscape app should support both landscapeLeft and landscapeRight, and a portrait app should support both portrait and portraitUpsideDown.
在此示例,這兩個方向的等效景觀支持(landscapeRight和landscapeLeft)。它已成為相當普遍的iPhone應用程序只支持一個方向,但蘋果現在鼓勵 iPad的開發者支持所有等效方向:例如,一個景觀的應用程序應該支持landscapeLeft和landscapeRight,以及應用程序應該支持肖像肖像和portraitUpsideDown。


Again, the position (0,0) within Corona will correspond to the upper left-hand corner of each screen orientation.
同樣,位置(0,0)在Corona將對應於左上方角落,每個屏幕的方向。


Orientation of native UI only只有定位本地UI


There are scenarios in which you want the native UI elements to auto-rotate, or to be oriented in a specific way, but you also want to maintain a fixed coordinate system within Corona (which matches the previous behavior in Corona SDK 1.x).
有些情況要在其中本地用戶界面元素的自動旋轉,或將要面向一個特定的方式,但你也希望保持一個固定的坐標系統內Corona(這在以前的行為相匹配的SDK1.x的Corona) 。


For example, you may have a multiplayer game where any orientation is equally valid, or you may want to manually define the animation that occurs on orientation change (e.g., animate a dissolve and/or rotation between the sideways and upright interface layouts). The only way to do this is through a fixed Corona coordinate system where you manage your own rotation behavior in Lua. Because Corona renders its graphics to an OpenGL canvas that is separate from the other native elements, it is possible to control the rotation behavior of this canvas independently.
例如,你可能有一個多人遊戲,任何方向上同樣有效,或者您可能需要手動定義動畫方向上發生變化(例如,動畫一溶解和/或旋轉之間的橫向和垂直界面佈局)。只有這樣,才能做到這一點是通過一個固定的坐標系統,其中Corona您管理自己的旋轉行為在Lua。由於Corona呈現其圖形的OpenGL畫布獨立於其他本土元素,它是可以控制這個畫布旋轉行為獨立。


To lock Corona’s orientation while allowing native iPhone UI elements to rotate, add a content parameter in build.settings:
要鎖定Corona的方向,同時允許本地iPhone UI元素進行旋轉,添加內容參數 build.settings:
-----------------------------
settings =
{
        orientation =
        {
                default = "portrait",
                content = "portrait",
                supported =
                {
                        "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown",
                },
        },
}
------------------------------
Similarly, to lock Corona’s internal coordinate system to portrait orientation (e.g., for compatibility with your older Corona code) while locking iPhone UI elements to landscape orientation, you could do the following in build.settings:
同樣,要鎖定Corona的內部協調制度,以縱向(例如,為了兼容性與您的舊Corona代碼),而鎖定 iPhone的UI元素,橫向,你可以做以下的build.settings:
------------------------------
settings =
{
        orientation =
        {
                default ="landscapeRight",
                content = "portrait",
                supported =
                {
                        "landscapeRight",
                },
        },
}
---------------------------------
Orientation naming conventions定位命名約定


Orientations follow the UIInterfaceOrientation conventions on the iPhone (not to be confused with UIDeviceOrientation). These are defined as follows:
按照UIInterfaceOrientation公約取向上的iPhone(不要混淆UIDeviceOrientation)。這些定義如下:


*portrait - device in the upright position with the Home button on the bottom
*landscapeRight - device in the sideways position with the Home button on the right
*landscapeLeft - device in the sideways position with the Home button on the left
*portraitUpsideDown - device in the upside down position with the Home button on the top
portrait- 設備處於直立狀態的主頁按鈕在底部
landscapeRight-裝置在橫向位置的主頁按鈕在右邊
landscapeLeft-裝置在橫向位置上的主頁按鈕在左側
portraitUpsideDown-設備處於倒掛位置與Home按鈕頂部

About combining dynamic scaling and auto-rotation
關於結合的動態縮放和自動旋轉

As discussed in Dynamic Content Scaling, Corona lets you develop content for a single "virtual" screen size which is automatically scaled up (or down) on devices with different screen sizes. However, not all dynamic scaling options will work perfectly with auto-rotation of the Corona canvas. In particular, you should avoid using the zoomStretch scaling option unless you also disable auto-rotation for the Corona canvas. For more information about disabling auto-rotation of the Corona canvas, see Orientation of native UI only.
正如在動態內容縮放,讓您開發Corona內容單一的“虛擬“屏幕大小自動調整是向上(或向下)的設備上使用不同的屏幕尺寸。然而,並非所有動態縮放選項將完全與自動旋轉畫布的Corona。特別是,你應該避免使用zoomStretch縮放選項,除非您還禁用自動輪換Corona畫布。有關更多信息有關禁用自動旋轉的Corona帆布,看到取向本地UI而已。

Detecting current device orientation目前的檢測設備方向

The current device orientation can be read from system.orientation. This property will return one of six possible string values, from a set consisting of the four orientations above plus faceUp and faceDown.
目前設備的方向可以讀出system.orientation。此屬性將返回六分之一的可能的字符串值,從一組由四個方向上面加faceUp和面朝下。


To get more detailed information about the device’s specific x, y, and z angle in space, see the section on accelerometer events in the API Reference.
要獲得更詳細的信息有關該設備的特定的X,Y和Z角的空間,看到一節加速度事件的API參考。


Orientation Support (Android)定向支持(Android)


The Android platform supports two orientations: portrait and landscapeRight (defined as above). The orientations “landscapeLeft” and “portraitUpsideDown” have no effect on Android. Also, auto-rotation is not currently supported on Android.
Android平台的支持兩個方向:縱向和landscapeRight(定義如上)。在面向“landscapeLeft“和”portraitUpsideDown“沒有對 Android操作系統。此外,自動旋轉目前不支持Android上。


Here is an example of an Android-specific build.settings file (you may also combine Android and iPhone settings in the same file):
下面是一個例子,一個 Android特定build.settings文件(您可能還結合 Android和iPhone的設置在同一個文件):
--------------------------------------
settings =
{
        android =
        {
                versionCode = "3"
        },
    
        androidPermissions =
        {
                "android.permission.ACCESS_FINE_LOCATION",
                "android.permission.INTERNET"
        },
    
        orientation =
        {
                default = "landscape"
        },
}
-------------------------------------


Version Code (Android)版本代碼(Android)


The version code can be set within an optional “android” table in build.settings. See the code above for an example.
該版本的代碼可以設定在一個可選的“Android“表build.settings。見上面的代碼中的例子。


For more information, see android:versionCode on this page. Note that this version code is an internal number used to distinguish application releases for the Android Marketplace, and is different than the version given in the Corona build dialog. The latter determines the version number displayed to the end user, also known as android:versionName.
有關詳細信息,請參閱Android:versionCode在此頁。請注意這個版本的代碼是一個內部編號來區分應用程序釋放為 Android市場,並給予不同的版本相比,在電暈建立對話。後者決定了版本號顯示給最終用戶,也被稱為Android:versionName。


Application Permissions (Android)
應用程序的權限(Android)


Finally, an optional “androidPermissions” table can be used to specify permissions, using string values as given in the Android Manifest Reference. For example, ACCESS_FINE_LOCATION and INTERNET permissions are specified in the code above.
最後,一個可選的“androidPermissions“表可用於指定的權限,使用字符串值中給出了Android清單參考。例如,ACCESS_FINE_LOCATION權限和INTERNET上面的代碼中指定。


Developers should choose the permissions that match what their application requires. In particular, set the INTERNET permission for any Android application that requries network access.
開發者應該選擇什麼權限,其應用要求相匹配。特別設置 Internet權限 Android的應用程序的任何requries網絡訪問。

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 13 週五 201115:44
  • Corona Physics Bodies

Physics Bodies 物理機構

Bodies機構

The physics world is based on the interactions of rigid bodies. These physical bodies can be bound to Corona display objects in a one-to-one relationship, and Corona will automatically handle all position updates and other synchronization tasks.
物理世界是基於剛體的相互作用。這些物理機構可以綁定Corona 顯示對象在一比一的關係,和Corona 會自動處理所有位置更新和其他同步任務。


In fact, our goal is that you should be able to consider the physical bodies as literally part of the visible display objects. Therefore, the body constructor physics.addBody does not return a new object, but instead “extends” an existing display object with physical properties.
事實上,我們的目標是,你應該可以考慮物理機構,因為從字面上的一部分,可見顯示對象。因此,身體構造 physics.addBody不會返回一個新的對象,而是“延伸“一現有的顯示對象的物理特性。


Therefore, standard object read/write attributes like x, y and rotation should continue to work normally on a physical body, although if the bodyType is “dynamic”, the physics engine may “fight back” against your attempts to move the object manually, since the target object will be under the constant effect of gravity and other forces.
因此,標準對象的讀 /寫屬性,如X,Y和旋轉應該繼續正常工作在物理機構上,但如果在bodyType是“動態“的,物理引擎可能“抵抗“針對您嘗試手動移動對象,由於目標對象將是重力和其他力量的常數影響下。


The “DragPlatforms” sample code shows one method for changing body types to “kinematic” during dragging, which temporarily removes them from the influence of external forces. 
在“DragPlatforms“示例代碼演示了一種方法改變身體類型為“運動“在拖動時,這暫時移除它們從外部勢力的影響。


In contrast, the "DebugDraw" sample shows a method for dragging objects using "touch joints" that does not remove them from external forces. 
與此相反,“DebugDraw“示例顯示了一個方法拖動對象使用“觸摸關節“,這並不能從外部力量消除他們。


The second method is probably more useful in physics-based games, but you can compare the two examples to see the difference between "kinematic" and "dynamic" object behavior.
第二種方法可能更有益的物理為基礎的比賽,但是你可以比較兩個例子,看到的區別““運動“和”動態“對象的行為。


A display object that has physical properties can be deleted in the normal way, using object:removeSelf(). It will be automatically removed from both the visible screen and the physical simulation. 
一個顯示對象,具有物理屬性可以以正常方式刪除,使用 object:removeSelf()。它會被自動刪除無論從可視屏幕和物理模擬。


Note: You cannot remove the Physics properties of an object -- you can only remove the entire object.
注意:您不能刪除一個對象的物理特性- 您只能刪除整個對象。


Simple body construction簡單的機身結構


physics.addBody

This allows you to turn any Corona display object into a simulated physical object with one line of code, including the assignment of physical properties.
這使您可以將任何Corona 顯示對象 成模擬的物理對象一行代碼,包括分配的物理特性。


Physical bodies have three main physical properties:
物理機構有三個主要的物理性能:


*density is multiplied by the area of the body’s shape to determine its mass. 
This parameter is based on a standard value of 1.0 for water, so materials that are lighter than water (such as wood) have a density below 1.0, and heavier materials (such as stone) have a density greater than 1.0. 
密度乘以面積身體的形狀來確定它的質量。
此參數是基於一個標準值1.0的水,所以材料都輕於水(如木材)的密度小於 1.0,和重的材料(如石頭)有密度大於1.0。


However, feel free to set density values to whatever feels right for your game, since overall object behavior will also depend on your gravity and pixels-to-meter scale settings (see previous section). The default value is 1.0.
但是,隨意設置密度值的任何感覺對你的遊戲,因為總體目標的行為也將取決於您的重力和像素到米比例設置(見上一節)。默認值是1.0。


*friction may be any non-negative value; a value of 0 means no friction and 1.0 means fairly strong friction. The default value is 0.3.
摩擦可以是任何非負值,一個值為 0意味著沒有摩擦,1.0表示比較強烈的摩擦。默認值是0.3。


*bounce is the Box2d property known internally as “restitution”, and determines how much of an object’s velocity is returned after a collision. Values greater than 0.3 are fairly “bouncy”, and an object with a bounce value of 1.0 will rebound forever (i.e., if dropped to the ground, it will bounce back up to roughly the height from which it was dropped). Bounce values higher than 1.0 are valid, but will cause strange behavior: objects will literally gain velocity with each collision until they fly off into space. The default value is 0.2, which is slightly bouncy.
彈性是Box2D的屬性著名國內的“恢復原狀“,並確定有多少對象的速度發生碰撞後返回。值大於 0.3是相當“有彈性“,以及一個對象,具有反彈值1.0將反彈到永遠(即,如果掉在了地上,它還會彈回來了約有的高度,從它被丟棄)。彈跳值高於 1.0是有效的,但會導致奇怪的行為:對象將獲得字面上與每個碰撞速度飛了過去,直到他們進入太空。默認值是0.2,這是稍微有彈性。


Note:
You may find that an object with a bounce set to exactly 1.0 will rebound somewhat higher than its original height, due to numerical approximations in Box2D. Bounce values slightly below 1.0, possibly combined with some linear damping, may be used for a closer simulation of "same height" behavior over short periods of time. Over long periods of time, it may be difficult to avoid runaway or decaying bounce.
注意:
您可能會發現一個對象,具有反彈設置為1.0將反彈正好略高於原來的高度,由於在Box2D數值逼近。彈跳值稍低於 1.0,可能結合一些線性阻尼,可用於模擬一個接近“同一高度“行為在短時間內的時間。在很長一段時間,可能難以避免失控或腐爛的反彈。


Default (rectangular) bodies默認(矩形)機構


By default, this constructor assumes that the physical object is rectangular, with collision boundaries that automatically snap to the edges of the associated image or vector object. This works well for crates, platforms, large ground bodies, and other simple rectangular sprites. All parameters in the table are optional, and all default to reasonable values if not provided.
默認情況下,這個假設的物理構造對象是矩形,碰撞的界限,自動捕捉到的相關圖像邊緣或矢量對象。這很適合箱子,平台,大型地面機構以及其他簡單的矩形精靈。表中的所有參數都是可選的,默認為所有合理的值,如果沒有提供。
--------------------------
local crate = display.newImage( "crate.png", 100, 200 )
physics.addBody( crate, { density = 1.0, friction = 0.3, bounce = 0.2 } )
--------------------------
Note that the table of physical attributes can be declared externally and then used multiple times:
注意該表的物理屬性可以被聲明為外部,然後多次使用:
---------------------------
local crate1 = display.newImage( "crate.png", 100, 200 )
local crate2 = display.newImage( "crate.png", 180, 280 )
 
local crateMaterial = { density = 1.0, friction = 0.3, bounce = 0.2 }
 
physics.addBody( crate1, crateMaterial )
physics.addBody( crate2, crateMaterial )
-------------------------------------
Also note that this default constructor assumes that your physics object has the same rectangular boundaries as your display object. This is very convenient in many cases, but in other cases may not be what you want. For example, a vector line drawn diagonally using display.newLine() is actually rendered as a rectangular object, since it creates a rectangular area of OpenGL texture (which would be mostly transparent, in this case).
另外請注意,此默認構造假設你的物理對象具有相同的矩形邊界為您顯示對象。這是非常方便,在許多情況下,但在其他情況下可能不是你想要的。例如,使用矢量線繪製對角display.newLine()實際上是呈現為一個矩形對象,因為它創建一個矩形區域的OpenGL紋理(這將是通透,在這種情況下)。


If you do not want your physics body to match this bounding rectangle, you should define more specific shape data using either the circular radius property or the array of polygon coordinates discussed below.
如果你不想你的物理身體,以配合這個邊界矩形,你應該更具體的定義形狀數據要使用什麼樣的圓形半徑屬性或多邊形坐標陣列下面討論。


When in doubt, you can use physics.setDrawMode() to get a "behind the scenes" view of what the physics engine is actually doing, including the collision boundaries for your physics bodies.
如有疑問,您可以使用physics.setDrawMode()來得到一個“幕後“的觀點是什麼物理引擎實際上是在做,包括你的物理碰撞分界機構。


Circular bodies圓體

Circular bodies require an additional radius parameter. This works well for balls, rocks, and other objects that can be treated as perfectly round when calculating collisions. If the visible sprite is round but irregular (say, a boulder or an egg), you may wish to set this radius slightly smaller than the physical image size.
圓形的身體需要額外的半徑參數。這很適合球,岩石和其他對象,可以被視為是完美的圓形,當計算碰撞。如果可見精靈是圓的,而是不規則的(例如,一巨石或雞蛋),您可能希望設置這個半徑略小於物理圖像的大小。


Note that there is no such thing as a non-circular oval in Box2D collision geometry, since circular bodies exist as a special case. To make an oval body, you would instead lay out a series of specific boundary points to outline the shape as a polygon (see below).
請注意有沒有這樣的東西非圓形橢圓形幾何在Box2D碰撞,因為圓形機構存在,作為一個特例。為了使一個橢圓形的身體,你反而會制定出一系列具體的邊界點的輪廓形狀為多邊形(見下文)。
-----------------------
local ball = display.newImage( "ball.png", 100, 200 )
physics.addBody( ball, { density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 } )
------------------------


Polygon bodies多邊形機構

General polygonal bodies that don’t fall into the above two special cases are generated with a “shape” parameter, which is used to pass a Lua table of (x,y) coordinate points that outline the collision boundaries. These coordinates are specified relative to the display object: by default, Corona sets the origin of a display object at the center of the corresponding image file (or vector object).
一般多邊形機構不屬於上述兩種特殊情況下產生了“形“參數,它是用來傳遞一個 Lua表(的x,y)坐標點,勾勒出碰撞邊界。這些坐標指定相對於顯示對象:默認情況下,Corona 設置顯示對象的起源中心在相應的圖像文件(或矢量對象)。


For example, to define a rectangular shape 20 pixels high and 40 pixels wide, with its origin at its center, the following shape definition would be used:
例如,要定義一個長方形高20像素和40像素寬,其原產地為中心,下面的形狀定義將用於:
----------------------
squareShape = { -20,-10, 20,-10, 20,10, -20,10 }
-----------------------
The maximum number of points (and therefore edges) allowed per collision shape is eight. Once defined, a shape definition can be re-used multiple times.
最高點數(因此邊緣)允許每個碰撞型狀是八。一旦定義,形狀定義可以重複使用多次。


Note that these polygon coordinates must be defined in clockwise order, and the resulting shape must be convex-only. Coordinate sets that violate these two rules may appear to work, but their objects will behave oddly in collisions: for example, they may become stuck to other objects. (Concave physical objects must be assembled from multiple elements attached to the same body; see "Complex body construction" below.)
請注意,這些多邊形的坐標必須定義在順時針順序,以及由此產生的形狀必須是凸形。坐標集違反規則可能會出現這兩個工作,但他們的行為很古怪的物體碰撞:例如,他們可能成為堅持到其他物體。 (凹物理對象必須從多個元素進行組裝連接到相同的身體,見“複合體結構“一節。)


Here are two valid examples:
這裡有兩個有效的例子:
--------------------
local triangle = display.newImage("triangle.png")
triangle.x = 200
triangle.y = 150
triangleShape = { 0,-35, 37,30, -37,30 }
 
physics.addBody( triangle, { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )


local pentagon = display.newImage("pentagon.png")
pentagon.x = 200
pentagon.y = 50
pentagonShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
 
physics.addBody( pentagon, { density=3.0, friction=0.8, bounce=0.3, shape=pentagonShape } )
----------------------------
For examples of polygonal body specifications, see “ShapeTumbler” and the bumper objects in “SimplePool”.
舉例來說多邊形體規格,請參閱“ShapeTumbler“和緩衝器槓對象“SimplePool“。


bodyType ConstructorbodyType構造

Here are two ways to specify the bodyType when adding a Physics body.
這裡有兩種方法可以指定bodyType當添加一個物理的身體。
-------------------------------
physics.addBody( triangle, "static", { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )
--------------------------------
Alternatively, you can construct the body and then set its type attribute:
或者,您可以構造體,然後將其類型屬性:
-------------------------
physics.addBody( triangle, { density=1.6, friction=0.5, bounce=0.2, shape=triangleShape } )
triangle.bodyType = "static"
---------------------------
Possible bodyTypes are “static”, “dynamic” and “kinematic”, and the default type is “dynamic” if no value is specified.
可能bodyTypes是“靜態“,“動態”和“運動“,而默認類型是“動態“如果沒有指定值。


In general, you can allow moving objects to default to “dynamic”, and specify “static” for objects (like walls or the ground) that shouldn’t move or fall under gravity.
一般情況下,可以允許移動物體默認為“動態”,並指定“靜態“的對象(如牆壁或地面),不應移動或在重力作用下。


Complex body construction複雜的身體結構


The above examples assume a body with only one element. However, it is also possible to construct a body from multiple elements. In this context, each body element is specified as a separate polygon shape with its own physical properties.
上述例子假設一個機構,只有一個元素。不過,也有可能建立一個身體從多個元素。在這種情況下,每一個 body元素被指定為一個單獨的多邊形的形狀,其自身的物理特性。


For example, to model a pencil, you would probably want to define the eraser end as a separate body element with a much higher “bounce” value than the rest of the pencil.
例如,一支鉛筆的模型,您可能要定義橡皮擦結束作為一個單獨的主體元素以更高的“反彈“的價值比其他的鉛筆。


Also, since collision polygons in Box2D must be convex, any game object with a concave shape must be constructed by appending multiple body elements. For example, to model a car, you would use a body with two or more body elements, since the shape of a car includes concave angles, such as the angle where the windshield meets the hood of the car.
此外,由於碰撞,必須在Box2D多邊形凸的,任何遊戲對象凹形狀的施工必須由多個機構追加元素。例如,模擬一個車,你會用身體與兩個或更多的體元素,因為汽車的形狀,包括凹角,角的地方,如符合罩在擋風玻璃上的汽車。


The constructor for a complex body is the same as the simple polygon body constructor, except with more than one body element listed:
該構造一個複雜的身體是一樣的身體構造簡單的多邊形,除非列出的一個以上身體元素:

physics.addBody( displayObject, [bodyType,] bodyElement1, [bodyElement2, ...] )

Each body element may have its own physical properties, along with a shape definition for its collision boundaries. For example:
每一個機構元素可能有自己的物理性能,以及一個形狀定義的碰撞邊界。例如:
---------------------------------------------------
local car = display.newImage("big_red_car.png")
roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
hoodShape = { 0,-35, 37,30, -37,30 }
trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }
  
physics.addBody( car, "dynamic",
  { density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
  { density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
  { density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)
------------------------------------------------------
(These shape definitions are for example only, and probably would not make a very good car shape.)
(這些形狀的定義只是舉例,可能不會使一個很好的汽車形狀。)


As in the simpler cases, the bodyType attribute is optional and will default to “dynamic” if not specified.
正如在簡單的情況下,bodyType屬性是可選的,默認為“動態“如果沒有指定。


Sensors感應器


Any body (or element of a multi-element body) can be turned into a “sensor”. Sensors do not physically interact with other bodies, but produce collision events when other bodies pass through them. For example, the pockets on a pool table might be implemented as sensors.
任何機構(或元素的多元素體)可變成了“感應器“。不物理感應器與其他機構的互動,但產生的碰撞事件時,其他機構通過它們。例如,口袋台球桌可能將實施的感應器。


Because the simplest Corona body constructors are based on visible display objects, the easiest way to implement an invisible sensor region is to create a display object and then make it invisible:
由於身體構造最簡單的Corona 基於可見的顯示對象,最簡單的方法來實現一種無形的感應器區域要創建一個顯示對象,然後使之不可見:
------------------------
local rect = display.newRect( 50, 50, 100, 100 )
rect:setFillColor( 255, 255, 255, 100 )
rect.isVisible = false  -- optional
physics.addBody( rect, { isSensor = true } )
--------------------------
The visible object can be used for game debugging, and then the isVisible property can be set to false once debugging is complete. In the above example, the initial display object is a translucent vector rectangle using the Corona drawing API.
可見的對象可用於遊戲調試,然後 IsVisible屬性可以設置為 false,一旦調試完成。在上面的例子中,初始顯示對象是一個半透明的矩形使用Corona 矢量繪圖 API。


Destroying bodies銷毀機構

Physics bodies can be destroyed like any other display objects:
物理機構,可以像任何其他顯示銷毀對象:
-------------------------
myBody:removeSelf()
-- or --
myBody.parent:remove( myBody )
------------------------------
The first method above is recommended for simplicity, and is the same syntax used to destroy physics joints (which do not have parents, since they are invisible and not part of the display hierarchy).
第一種方法為簡單起見,上述建議,是相同的語法用來摧毀物理關節(其中沒有父母,因為他們是無形的,而不是一部分的顯示層次結構)。


When you destroy bodies or joints, Corona will automatically handle the process of holding onto the corresponding Box2D objects until the end of the current physics world step, and then safely dispose of them.
當你摧毀機構或接縫,Corona 處理過程中會自動持有到相應 Box2D的對象,直到結束當前的物理世界的一步,然後安全地處置它們。


Note:
While Box2D objects will be safely retained until the end of the current world step, their Lua references will be deleted immediately. Therefore, be careful not to accidentally delete the same Lua object more than once. This situation could occur when deleting objects involved in collisions, which can potentially have many event phases before the collision is fully resolved. The solution is simple:
注意:
雖然 Box2D的對象將被安全地保留到最後是當今世界的一步,他們的Lua的言論將被立即刪除。因此,要小心不要意外刪除相同的Lua對象不止一次。這種情況可能發生在刪除對象涉及碰撞,最終也可能有許多事件相碰撞前完全解決。解決的辦法很簡單:
-----------------------
local function onCollision( self, event )
        if ( event.phase == "began" ) then
                 -- Check if body still exists before removing!
                if ( crate1 ) then
                        crate1:removeSelf()
                        crate1 = nil
                end
 
        end
end
---------------------

Body properties
Body屬性
Many of the native Box2D setter/getter methods have been reduced to simpler dot properties on the display object. The following examples assume that a body myBody has been created using one of the above constructor methods.
許多本地Box2D的setter / getter方法​​已減少到​​簡單點的屬性上顯示對象。下面的例子假設,一個物體 myBody已創建使用一個以上的構造方法。
-----------------
body.isAwake
-------------------
A boolean for the current awake state. 
當前清醒狀態是一個布爾值。


By default, all bodies automatically “go to sleep” when nothing interacts with them for a couple of seconds, and then they stop being simulated until something (e.g., a collision) wakes them up. This property can either fetch their current state or forcibly wake them up.
默認情況下,所有機構自動“去睡覺“沒事的時候與他們相互作用的幾個秒,然後,他們不再是模擬碰撞,直到它們喚醒。這個屬性可以獲取其當前狀態或強行叫醒他們。
----------------
myBody.isAwake = true
local state = myBody.isAwake
--------------------

body.isBodyActive
A boolean for the current active state. Inactive bodies are not destroyed, but they are removed from the simulation and cease to interact with other bodies.
前活動狀態是一個布爾值。不活躍的身體不被破壞,但他們將被刪除從模擬和終止和其它的機構互動
-------------------------
myBody.isBodyActive = true
local state = myBody.isBodyActive
---------------------------

body.isBullet

A boolean for whether the body should be treated as a “bullet”. 
該機構是否應被視為一個“砲彈”。是一個布爾值


Bullets are subject to continuous collision detection, rather than periodic collision detection at world timesteps. 
砲彈都受到連續碰撞檢測,而不是在世界時間步驟週期性 碰撞檢測 。


This is more computationally expensive, but it prevents fast-moving objects from passing through solid barriers. The default is false.
這是更昂貴的計算,但它可以防止快速移動的物體 穿過 堅實屏障。默認為 false。


body.isSensor

A (write-only) boolean property that sets an internal "isSensor" property across all elements in the body. 
一個(只寫)布爾屬性,設置了一個內部“isSensor“屬性跨越在體內的所有元素。


A sensor passes through other objects rather than bouncing off them, but still fires some collision events (for example, the table pockets in the "SimplePool" sample code are sensors). 
經過一個感應器等對象,而不是他們的反彈,但仍有些碰撞火災事件(例如,表口袋中的“SimplePool“示例代碼的感應器)。


Because this body property acts across all body elements, it unconditionally overrides any "isSensor" settings on the elements themselves.


由於這個機構屬性的動作跨越所有身體的元素,它無條件地覆蓋任何“isSensor“設置的元素本身。
------------------
myBody.isSensor = true
-------------------

body.isSleepingAllowed

A boolean for whether the body is ever allowed to go to sleep. 
該機構是否任何時候都可以去睡覺是一個布爾值。
true 表示沒有碰撞時body is sleep.


Keeping bodies awake has a larger overhead, and is often not required, because collisions with other bodies will automatically wake them up. 
保持清醒的機構有較大的開銷,通常不是必需的,因為與其他機構的碰撞會自動叫醒他們。


However, forcing awakeness is useful in cases such as the tilt-gravity case (since sleeping bodies do not respond to changes in global gravity). The default is true.
然而,迫使覺醒是有用的情況下,如傾斜重力情況下(因為睡機構不響應全球變化的重力)。默認為 true。


-------------------------
myBody.isSleepingAllowed = true
local state = myBody.isSleepingAllowed
-------------------------

body.isFixedRotation

A boolean for whether the rotation of the body should be locked, even if the body is under load or subjected to off-center forces. The default is false.
是否旋轉的機構應被鎖定這是一個布爾,即使身體負荷或正在遭受偏離中心的力量。默認為 false。
---------------------
myBody.isFixedRotation = true
local state = myBody.isFixedRotation
-------------------------

body.angularVelocity

The numerical value of the current angular (rotational) velocity, in degrees per second.
當前角度(旋轉)的速度數值,以度每秒。
---------------------------
myBody.angularVelocity = 50
local v = myBody.angularVelocity
----------------------------

body.linearDamping

The numerical value for how much the body's linear motion is damped. The default is zero.
有多少身體的直線運動數值被抑制。默認是零。
------------------------
myBody.linearDamping = 5
local d = myBody.linearDamping
------------------------

body.angularDamping

The numerical value for how much the body's rotation should be damped. The default is zero.
有多少身體的轉動數值為應阻尼。默認是零。
------------------------
myBody.angularDamping = 5
local d = myBody.angularDamping
------------------------

body.bodyType

A string value for the type of physical body being simulated. Possible values are "static", "dynamic" and "kinematic".
一個字符串值類型的身體被模擬。可能的值是“靜態“,“動態”和“運動“。


*static bodies don't move, and don't interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
*靜態機構不動,並且不互相影響;例子靜態對象將包括地面,牆壁或一個彈球機。


*dynamic bodies are affected by gravity and collisions with the other body types.
*動態物體受重力和碰撞與其他機構的類型。


*kinematic objects are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.
The default body type is "dynamic".
*運動物體受力,但不是由重力,所以你應該設置可拖動對象一般為“運動“,至少在此期間的拖動事件。
默認的身體類型是“動態“。
------------------------
myBody.bodyType = "kinematic"
local currentType = myBody.bodyType
-------------------------

Body methods

The following examples assume that a body myBody has been created using one of the above constructor methods.
下面的例子假設,一個物體 myBody已創建使用一個以上的構造方法。

body:setLinearVelocity

A function that accepts x,y components for the body's linear velocity, in pixels per second.
一個函數接受的x,y分量對身體的線性速度,以像素每秒。
---------------------
myBody:setLinearVelocity( 2, 4 )
-----------------------------

body:getLinearVelocity

A function that returns x,y components for the body's linear velocity, in pixels per second.
一個函數,返回x,y分量對身體的線性速度,以像素每秒。
vx, vy = myBody:getLinearVelocity()
-------------------------------------

body:applyForce


A function that accepts x,y components of a linear force, applied at a given point with x,y world coordinates. 
一個函數接受的x,y分量的線性力,適用於在某一時間點上的x,y世界坐標。


If the target point is the body's center of mass, it will tend to push the body in a straight line; if the target is offset from the body's center of mass, the body will spin about its center of mass.
如果目標點是人體的質心的時候,會推動身體在一條直線上,如果目標是從身體失調的質心,身體會旋轉約其質心。


For symmetrical objects, the center of mass and the center of the object will have the same position: (object.x, object.y). Also note that the amount of force may need to be fairly high to move heavy objects.
對於對稱物體,該中心的質量和中心的對象將具有相同的 position : (object.x,object.y)。還要注意的是力的數值可能需要相當高的移動重物。
-------------------------------------
myBody:applyForce( 500, 2000, myBody.x, myBody.y )
------------------------------------

body:applyTorque

A function that accepts a numerical value for applied rotational force. The body will rotate about its center of mass.
一個函數接受一個數值為應用旋轉力。該機構將繞其質心。
-------------------------
myBody:applyTorque( 100 )
--------------------------

body:applyLinearImpulse

Like applyForce, except that an impulse is a single, momentary jolt.
applyForce一樣,除了一衝力是一個單一的,瞬間的震動。
-------------------------------
myBody:applyLinearImpulse( 600, 200, myBody.x, myBody.y )
----------------------------

body:applyAngularImpulse

Like applyTorque, except that an angular impulse is a single, momentary jolt.
applyTorque一樣,除了一個角衝力是一個單一的,瞬間震動。
------------------
myBody:applyAngularImpulse( 100 )
---------------------


Force vs. Impulse?
力 vs 衝力?

A common question is the difference between applying "force" and "impulse" to a body. 
一個常見的問題是區別應用“力”和“衝力“於一體。

The difference is that an impulse is meant to simulate an immediate "kick" to the body, but force (and torque) is something exerted over time. 
所不同的是,一個衝力是為了模擬一個即時的“踢“的身體,但力(和扭力)施加的東西隨著時間的推移。

Therefore, to get a realistic force simulation, you should reapply the force on every frame, perhaps for several seconds, or as long as you want the force to continue. You can use an "enterFrame" event for this purpose.
因此,要獲得一個模擬現實的力量,你應該重新申請每幀上的力,也許是幾秒鐘,或者只要你想要的力量繼續下去。你可以使用“enterFrame“事件作此用途。


body:resetMassData

If the default mass data for the body has been overridden (TBD), this function resets it to the mass calculated from the shapes.
如果默認身體的質量數據已被重寫(TBD),這個函數並將依其出形狀的重算質量。
--------------
myBody:resetMassData()
--------------




(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 12 週四 201118:16
  • Corona Collision Filters "Helper Chart"

Collision Filters "Helper Chart"
碰撞過濾器“幫手圖“


Hello all,大家好


I'm posting the following explanation about Collision Filters as a help to the community in general, as a result of my own experiments. Some users, especially recent converts, have not yet used collision filters but it's an essential aspect to almost any game design. I created the attached "Collision Helper Chart" which I use for my own game designs... hopefully it can assist others too! The blank document can be downloaded from my website (link at the end of this post).
我下面的解釋張貼關於碰撞過濾器的幫助,對社會一般,因此我自己的實驗。有些用戶,特別是最近的轉換,還沒有使用過濾器的碰撞,但它是一個重要的方面幾乎所有的遊戲設計。我創建了附加“碰撞助手圖“,我用我自己的遊戲設計...希望它能夠幫助別人呢!空白文件可從我的網站(鏈接在結束這篇文章)。


-----


So, what are Collision Filters? Simply put, they're a method to determine what objects combine with other objects, or perhaps more importantly, what objects do not collide with others in a game. The official documentation explains Corona's method of accomplishing this, which varies from other SDKs, but I created a chart to assist in the issue.
那麼,什麼是碰撞過濾器?簡而言之,他們是一個方法來確定哪些對象與其他對象相結合,或者更重要的是,哪些對象不與他人發生碰撞在遊戲中。官方文檔解釋Corona的方法實現這一點,從其他SDK而異,但我創建了一個圖表,以協助問題。


Here's a chart and list of steps following the classic "Asteroids" game example...
這裡有一個圖表,列出以下步驟經典的“小行星“的遊戲例子...






STEPS:

1.Observe the "bits" (numbers) in the very top row. 1 to 512, in binary numbers. You can go as high as "32768" (16 places) but I stopped the chart at 512 which should be enough for most people. These "bits" are how Corona determines collision filters.
遵守“位元“(數字)排在最高層。 1到512,在二進制數字。你可以去高達“32768“(16處),但我停在512的圖表應足以讓大多數人。這些“位元“是如何確定Corona碰撞過濾器。

2.Observe the first row. It has two sub-rows: "catg." and "cl.w/". These mean "category" and "collides with" respectively.
遵守第一行。它有兩個子行:“catg。“和“cl.w/“。這意味著"category"和"collides with"分別。

3.For each object type in your game (i.e. "asteroid", pick one bit number. Place a circled X in that column. This bit number should be unique and not repeated for other objects under most circumstances! (There are probably advanced situations where you might duplicate category bits or even assign more than one to an object, but don't worry about it now)
對於每個對象類型在你的遊戲(即“小行星“,選擇一個位元的數字。放置一個圈X的在該列。該位元號碼應該是唯一的,而不是重複其他對象在大多數情況下!(有可能是先進的情況下,您可能會重複類別位元,甚至超過一個指定的對象,但不用擔心了)

4.Next, ask yourself: "can this object collide with others of its type?" If yes, then place an X directly below in the "collides with" row. In the example, notice that asteroids can collide with other asteroids.
4.接下來,問自己:“這個對象可以與他人發生衝突的類型?“如果是的話,然後直接在 "collides with"那行 放一個X 。在這個例子中,可以發現小行星碰撞與其他小行星。

5.Move down the rows of other objects in your game. For every object that "asteroids" can collide with, place an X in the "collides with" row for that object. Asteroids can collide with player_ship and alien_ship, so both of those get an X in their respective row/column. If it's not obvious already, keep the columns ordered: Asteroids have bit "2" as their category, so stay within that column for anything asteroids should collide with (I colored the chart entries to make it clearer).
5.向下行的其他對象在你的遊戲。對於每一個對象,“小行星“可以碰撞,放置一個 X在“collides with“行該對象。小行星可能撞到player_ship和alien_ship,所以這些都得到了X在各自的行/列。如果它已經不很明顯,繼續列下令:小行星有位元“2“,其類別,所以留在該列中任何小行星會撞上(我彩色圖表,使之更清晰的條目)。

6.Move to the next game object and repeat. IMPORTANT! You must work back UP the chart, not just down! If two objects are intended to collide, both must be marked properly or the collision will not function! 
6.移動到下一個遊戲對象和重複。重要!您必須備份圖表,而不僅僅是下來!如果兩個對象是為了碰撞,都必須標明正確或碰撞將無法正常工作!

So, take the item pair of asteroid and player_ship, which should always collide: "asteroid: category" is marked in "player_ship: collide with" AND "player_ship: category" is marked in "asteroid: collide with". If you fail to mark both corresponding factors, the collision will not happen!
因此,採取項目對小行星和player_ship,這應該永遠碰撞:“小行星:category“標記在“player_ship:collide with“及”player_ship:category“標記在“小行星:collide with“。如果你沒有標出對應的因素,不會發生碰撞!

7.When you've done all of your objects, simply add the bits across every row to determine sums.
7.當你已經做了所有你的對象,只需添加位元在每行,以確定的數額。

8.For each collision filter, you need these sums as follows, near the top of your main.lua file.
8.對於每一個碰撞過濾器,你需要這些款項如下,頂部附近你main.lua文件。
---------------
local asteroidCollisionFilter = { categoryBits = 2, maskBits = 7 }
local playerCollisionFilter = { categoryBits = 1, maskBits = 6 }
local alienCollisionFilter = { categoryBits = 4, maskBits = 7 }
------------------------
categoryBits is the sum from the "category" row for that object. 
categoryBits是總結從“類別“行該對象。

maskBits is the sum from the "cl.w/" row for that object.
maskBits是總結從“cl.w/“行該對象。


9.Later, in your physics body declarations, specify the collision filter. Obviously, define the proper filter for every object in your game, as declared near the top of your game code.
9.後來,在你的物理身體聲明,指定過濾器的碰撞。顯然,確定適當的過濾器,每一個對象在你的遊戲,這一點已接近頂部的你的遊戲的代碼。
--------------
local asteroid = display.newImageRect( [displayGroup], "asteroid.png", 32, 32 )
physics.addBody( asteroid, { density=2.9, friction=0.5, bounce=0.3, radius=16, filter=asteroidCollisionFilter } )
-------------
That's it! Remember the basic rules of collisions and body types. "Dynamic" bodies react physically with other "dynamic" or "static" bodies, but not with "kinematic" bodies. While confusing at first, it will soon make complete sense.
就是這樣!記住的基本規則和身體碰撞類型。 “動態“身體反應,身體上的其他“動態“或“靜態“的機構,但不符合“運動“組織。雖然一開始混亂,它很快就會作出完整意義上的。


Anyway, hopefully this helps some new Corona users, or even gives veterans a more visual way to calculate collision filters. If anybody at Ansca or in the community sees any errors in my description, please let me know! I'm not an Ansca staff member or Corona expert; all of this is just a result of my own personal testing and experimentation. :)
無論如何,希望這有助於一些新的Corona用戶,甚至給退伍軍人更直觀的方式來計算碰撞過濾器。如果有人在Ansca還是在社區中看到任何錯誤,我的描述,請讓我知道!我不是一個 Ansca工作人員或Corona的專家,所有這一切,僅僅是一個結果我個人的測試和試驗。 :)


And here's a link to the blank "chart" document in PDF format. You can download it from my website and print it for your own use: Collision Filter Helper Chart (PDF)
下面是一個鏈接到空白的“圖表“文件的PDF格式。你可以從我的網站下載並打印供自己使用:碰撞過濾助手圖(PDF)

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 12 週四 201118:11
  • Corona Collision Detection

Collision Detection 碰撞檢測


Collision events 碰撞事件


Physics engine collision events are exposed through the standard Corona event-listener model, with three new event types. For general collision detection, you should listen for an event named "collision". The "collision" event includes phases for "began" and "ended", which signify the moments of initial contact and broken contact. These phases exist for both normal two-body collisions and body-sensor collisions. If you do not implement a "collision" listener, this event will not fire.
物理引擎,碰撞事件暴露通過標準Corona事件偵聽器模型,有三個新的事件類型。對於一般的碰撞檢測,你應該聽的事件名為“碰撞”。在“碰撞“事件,包括階段為“開始“和“結束“,這意味著對初次接觸的瞬間和破碎接觸。這些階段存在正常兩體碰撞和身體碰撞傳感器。如果你沒有實施“碰撞“監聽,這一事件不會觸發。


In addition to "collision" events, two other event types are optionally available whenever two bodies (not sensors) collide. Previously, these were also phases of the "collision" event type, but they have now been separated into unique event types, since they have more specialized uses.
除了“碰撞”事件,另外兩個事件類型可供用戶選擇每當兩個機構(不傳感器)發生碰撞。以前,這些也是階段的“碰撞”事件的類型,但是他們現在已經分成獨特的事件類型,因為他們有更多的專門用途。


"preCollision": an event type that fires right before the objects start to interact. Depending on your game logic, you may wish to detect this event and conditionally override the collision.
“preCollision”:一個正確的觸發事件類型的對象開始之前進行交互。根據你的遊戲邏輯,你不妨檢測此事件,並有條件地覆蓋碰撞。


For example, in a platform game, you may wish to construct “one-sided” platforms that the character can jump vertically through, but only in one direction. You might do this by comparing the character and platform position to see if the character is below the platform, and then using a short timer to make "isSensor" body property temporarily true for the character object so that it passes through the platform. If you do not implement a "preCollision" listener, this event will not fire.
例如,在一個平台上的遊戲,你不妨構建“一邊倒”的平台,垂直跳躍的字符可以通過,但只能在一個方向。你可以這樣做比較的性質和平台的位置,看看下面的字符是平台,然後用很短的計時器,以使“isSensor”身體暫時真實屬性的Character對象,使其穿過平台。如果你不實行“preCollision”聽眾,這一事件不會觸發。


"postCollision": an event type that fires right after the objects have interacted. This is the only event in which the collision force is reported. See the “Collision forces” section below for more on this topic. If you do not implement a "postCollision" listener, this event will not fire.
“postCollision”:一個事件之後觸發類型的對象有互動。這是唯一的事件,其中碰撞力的報導。參見“碰撞力”一節獲得更多關於這個主題。如果你不實行“postCollision”聽眾,這一事件不會觸發。


Note that the “preCollision” events are quite noisy, and may report many times per contact. Therefore, you should only listen for these events if you need pre-collision warnings, and we also recommend that you use local listeners within the objects of interest, rather than listening globally to all "preCollision" events in the world.
請注意,“preCollision”事件是相當嘈雜,可能會報告很多次,每次接觸。因此,你應該只偵聽這些事件,如果您需要預碰撞警告,我們還建議您使用本地聽眾的興趣範圍內的對象,而不是聽全球所有“preCollision”事件在世界上。


Collisions are reported between pairs of objects, and they can be detected either globally, using a Runtime listener, or locally within an object, using a table listener. See the "CollisionDetection" sample code for working examples of global and local collision listeners.
之間的碰撞是對報告的對象,他們可以在全球任何檢測,使用運行時監聽器,或在本地內的對象,使用一個表的傾聽者。參見“CollisionDetection”示例代碼示例工作全局和局部衝突的聽眾。


Global collision listeners全域碰撞監聽

When detected as a Runtime event, each collision event includes event.object1 and event.object2, which contain the table IDs of the two Corona display objects involved.
當作為運行時檢測到的事件,每次碰撞事件包括event.object1和event.object2,其中包含了兩個表IDCorona顯示對象參與。


Because Corona display objects behave like Lua tables, you may freely add any arbitrary data to these tables, such as names, category designators, point values, or even stored functions, and then retrieve this data at collision time. This is similar to the userData attribute in Box2D, but it is essentially unlimited, since you can assign as many custom attributes as you like.
由於Corona顯示對象的Lua的表像,你可以自由添加任意的數據到這些表,如名稱,類別代號,點值,甚至存儲功能,然後檢索這些數據在碰撞時間。這是類似於在Box2D用戶數據屬性,但它本質上是無限的,因為你可以指定多個自定義屬性,你喜歡。


For example, you may wish to store object names in an easily-accessible string format:
例如,您可能希望在一個存儲對象的名稱易於獲取字符串的格式:
-----------------------
local crate1 = display.newImage( "crate.png", 100, 200 )
physics.addBody( crate1, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate1.myName = "first crate"
 
local crate2 = display.newImage( "crate.png", 100, 120 )
physics.addBody( crate2, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate2.myName = "second crate"
 
local function onCollision( event )
        if ( event.phase == "began" ) then
 
                print( "began: " .. event.object1.myName .. " & " .. event.object2.myName )
 
        elseif ( event.phase == "ended" ) then
 
                print( "ended: " .. event.object1.myName .. " & " .. event.object2.myName )
 
        end
end
 
Runtime:addEventListener( "collision", onCollision )
--------------------------
Local collision listeners 本地碰撞監聽

When detected with a table listener within an object, each collision event includes event.other, which contains the table ID of the other Corona display object involved in the collision. Again, you may wish to store each object’s name in string format and retrieve it during the collision event:
當檢測到一個表在一個監聽對象,每次碰撞事件包括event.other,其中包含了表中的ID其他Corona顯示對象參與了碰撞。同樣,你可能想存儲每個對象的名稱,字符串格式和檢索它在碰撞事件:
-------------------
local crate1 = display.newImage( "crate.png" )
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
crate1.myName = "first crate"
 
local crate2 = display.newImage( "crate.png" )
physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } )
crate2.myName = "second crate"
 
local function onLocalCollision( self, event )
        if ( event.phase == "began" ) then
 
                print( self.myName .. ": collision began with " .. event.other.myName )
 
        elseif ( event.phase == "ended" ) then
 
                print( self.myName .. ": collision ended with " .. event.other.myName )
 
        end
end
 
crate1.collision = onLocalCollision
crate1:addEventListener( "collision", crate1 )
        
crate2.collision = onLocalCollision
crate2:addEventListener( "collision", crate2 )
-------------------
See the "CollisionDetection" sample code for examples of both of these methods. (Run the project using Corona Terminal to see the output of the collisions.)
參見“CollisionDetection“示例代碼例子,這兩種方法。 (運行該項目利用 Corona 終端看到輸出的衝突。)


Collisions with multi-element bodies碰撞的多元素機構

Collision events involving a multi-element body (see "Complex Body Construction") also return the specific body part involved in the collision. This allows for more finely-tuned game logic: for example, you may decide that colliding with the nose of a rocket does more damage than colliding with its tailfins.
碰撞事件涉及多元素機構(見“複合體的建構“)也返回特定的身體部分參與了碰撞。這樣就可以更精細調校的遊戲邏輯:例如,你可以決定撞到火箭的前端比碰撞尾翼 造成的損害還多。


Body elements are identified by a numerical index, where the first element added to the body is given the number 1, the second one is number 2, the third is number 3, and so on.
Body元素是確定一個數字索引,其中第一個元素添加到身體給出數字 1,第二個是數字 2,第三個是3號,依此類推。


For global collision events, two additional integer values are now returned:
對於全球碰撞事件,另外兩個現已返回整數值:
---------------
event.element1
event.element2
---------------


These numerical properties are equal to the index of the elements in object1 and object2 that were involved in the collision. For example, object1 might a rocket with three body elements: nose, body and tail. If the collision is with its tail, the value of event.element1 would be 3; if the collision is with its body, the value of event.element1 would be 2. Again, this number is simply determined by the order in which you declared the elements of the body during its construction.
這些數值性質等同於指數中元素的object1和object2的參與了碰撞。例如,object1可能一火箭三體要素:鼻子,身體和尾巴。如果碰撞是它的尾巴,其價值 event.element1將是3,如果碰撞是與它的身體,其價值 event.element1是2。同樣,這個數字僅僅是確定的順序在其中聲明的元素在其體內的建設。


When collisions involve single-element bodies, both of the above values will always be 1.
當衝突涉及的單元素機構,無論上述值將始終為 1。


Similarly, local collision events (table listeners) now have additional fields:
同樣,本地的碰撞事件(表監聽)現在有額外的字段:

----------------
event.selfElement
event.otherElement
------------------
As above, these values will be 1 in the case of single-element bodies, and in multi-element bodies will range from 1 to the total number of elements in the body, numbered by the order in which the elements were added to the body.
如上所述,這些值將有1例在單元素的體,多元素機構將範圍從 1到總數的元素在體內,編號的順序被添加元素對身體。


Collision forces碰撞力

Once a collision has occurred, you can obtain the direct force of the collision, along with the sideways force between the two objects, which is effectively a frictional force. For example, you may have game objects that should be destroyed only if a collision is sufficiently forceful.
一旦發生碰撞,你可以直接獲得的碰撞力,側向力隨兩個物體之間,這實際上是一個摩擦力。例如,您可能有遊戲對象應該只被銷毀,如果有足夠的有力碰撞。


The direct force of the collision is reported within the "postCollision" event as event.force, and the frictional force is available as event.friction.
直接碰撞力報導在“postCollision“事件為 event.force和摩擦力可作為 event.friction。


-----------------
local function onPostCollision( event )
        if ( event.force > 1.0 ) then
                print( "Collision force: " .. event.force .. " Friction: " .. event.friction )
        end
end
 
Runtime:addEventListener( "postCollision", onPostCollision )
------------------


In the example above, very small forces are screened out. Also, a global listener is used here to simplify the example.
在上面的例子,非常小的力量篩選出。另外,一個全球性的監聽器是用在這裡是簡化的例子。


Since the postCollision event stream from the physics engine can be quite noisy (it registers a series of increasingly tiny forces as objects "settle"), you will probably want to choose your own threshold for ignoring some of it. See the "CollisionDetection" sample project for an example of how to do this (run the project using Corona Terminal to see the output of the collisions.)
由於 postCollision事件流的物理引擎可以很吵鬧(它註冊了一系列微小的力量越來越為對象,“定居“),你可能想選擇自己的門檻,無視它的一些。參見“CollisionDetection“示例項目為例,如何做到這一點(運行該項目利用Corona碼頭看到輸出的衝突。)


(Technical note: Box2D is actually reporting collision impulses, which are forces multiplied by the elapsed time of each world step, but since this time interval is always the same, this distinction can be ignored for the purposes of game logic.)
(技術說明:Box2D的報告實際上是碰撞的衝動,這是部隊所用的時間乘以每個世界同步,但由於這個時間間隔是一樣的,這種區別可以忽略而言的遊戲邏輯。)


Collision categories, masking, and groups碰撞類別,掩蔽和組

By default, all bodies collide with all other bodies, but you may want to fine-tune this behavior. For example, in the classic arcade game Asteroids, none of the asteroids collide with other asteroids, but all of them should collide with the player and with the enemy spaceships. There are two ways to accomplish this.
默認情況下,所有機構和所有其他機構的碰撞,但您可能要微調此行為。例如,在經典的街機遊戲小行星外,並無其他小行星與小行星碰撞,但他們都應該與球員發生碰撞,並與敵人的太空船。有兩種方法可以做到這一點。


First, you can assign categoryBits and maskBits to your objects via a "collision filter" definition, which is an optional table assigned during body construction. An object will only collide with other objects if their categoryBits are among its assigned maskBits. Normally, an object will only have one category bit assigned, but may have one or more mask bits depending on what other things it should collide with.
首先,你可以指定categoryBits和maskBits到你的對象通過“碰撞過濾器“的定義,這是一個可選的期間分配表體建設。對象將只與其他物體相撞,如果他們是在其指定的categoryBits maskBits。通常,一個對象只能有一個類別位分配,但可以有一個或多個掩碼位取決於什麼其他的事情就應該碰撞。


(Update: see the helpful collision filter worksheet and discussion posted here.)
(更新:請參閱表濾波器的有益碰撞與討論張貼在這裡。)


In the example below, the red balloon has a maskBits value of 3, so it would collide with any objects in category bits 2 and 1, which in this case would include other red balloons (category bit 2) or the wall objects (category bit 1). Meanwhile, it will pass through any blue balloons (category bit 4), since bit 4 is not included in its maskBits value.
在下面的例子中,紅色的氣球有maskBits值為 3,所以它與任何物體相撞類別2和1位,在這種情況下,將包括其他的紅氣球(類第2位),或在牆上的對象(類別位1)。同時,將通過任何藍色氣球(類別第4位),因為位4,不包含在其maskBits值。
--------------------------
borderCollisionFilter = { categoryBits = 1, maskBits = 6 } 
-- border collides with (4 & 2) only
 
borderBody = { friction=0.4, bounce=0.8, bodyType="static", filter=borderCollisionFilter }
 
local borderTop = display.newRect( 0, 0, 320, 1 )
physics.addBody( borderTop, borderBody )
 
local borderBottom = display.newRect( 0, 479, 320, 1 )
physics.addBody( borderBottom, borderBody )
 
local borderLeft = display.newRect( 0, 1, 1, 480 )
physics.addBody( borderLeft, borderBody )
 
local borderRight = display.newRect( 319, 1, 1, 480 )
physics.addBody( borderRight, borderBody )
 
local redCollisionFilter = { categoryBits = 2, maskBits = 3 } 
-- red collides with (2 & 1) only
 
local blueCollisionFilter = { categoryBits = 4, maskBits = 5 } 
-- blue collides with (4 & 1) only
 
local redBody = { density=0.2, friction=0, bounce=0.95, radius=43.0, filter=redCollisionFilter }
local blueBody = { density=0.2, friction=0, bounce=0.95, radius=43.0, filter=blueCollisionFilter }
 
redBalloon = display.newImage( "red_balloon.png" )
physics.addBody( redBalloon, redBody )
 
blueBalloon = display.newImage( "blue_balloon.png" )
physics.addBody( blueBalloon, blueBody )
--------------------------------------------------------


Note that categoryBits and maskBits are binary values that are currently assigned using decimal numbers. This is convenient for lower bits like 1, 2, 4 and 8, but not so convenient for higher bits -- since there are 16 possible categoryBits, the highest bit value is 32768. Therefore, future versions of this API may use a different bit assignment syntax, such as binary or hexadecimal values.
請注意,categoryBits和maskBits是二進制值是當前分配使用十進制數字。這是非常方便的低位元,如1,2,4和8,但不是很方便更高位 -因為有16種可能categoryBits,最高位的值是32768。因此,未來版本的該 API可能會使用不同的位分配語法,如二進制或十六進制值。


The second method is to assign a groupIndex to each object, via the same filter definition shown above. This value can be a positive or negative integer, and is a simpler way of specifying collision rules: objects with the same positive groupIndex value will always collide with each other, and objects with the same negative groupIndex value will never collide with each other.
第二種方法是分配一個 groupIndex每個對象,通過相同的過濾器定義上面。這個值可以是正或負的整數,是一個簡單的方式指定碰撞規則:對象與同樣積極的groupIndex值將始終相互碰撞,和對象具有相同的負 groupIndex值不會互相碰撞。
--------------------------
local greenCollisionFilter = { groupIndex = -2 }
--------------------------
If both groupIndex and collisionBits/maskBits are assigned to an object, the groupIndex has higher precedence.
如果同時 groupIndex和collisionBits/ maskBits被分配到一個對象,groupIndex 具有較高的優先 。


See the "CollisionFilter" sample code for an example of collision filtering.
參見“CollisionFilter“示例代碼示例碰撞過濾。


Collision event propagation rules碰撞事件傳播規律


Collision events in Corona now have a propagation model similar to touch events. You can use this to further optimize your game performance by limiting the number of events that are created.
碰撞事件的Corona現在有一個傳播模式類似觸摸事件。你可以用它來進一步優化你的遊戲的性能限制數量的事件所創建的。


By default, a collision between two objects will fire a local event for the first object, then a local event for the second object, then a global event in the Runtime object (assuming all have active listeners enabled). However, you may only be interested in some of this information. For example, in a game with one player character and lots of enemies, you may only be interested in what the player has collided with.
默認情況下,兩個物體之間的碰撞將觸發本地事件的第一個對象,然後是本地事件的第二個對象,然後是全球性事件中的運行時對象(假設所有監聽有積極的啟用)。但是,您可能只在一些有興趣的這些信息。例如,在一場比賽中與一名球員性格和大量的敵人,你可能只關心什麼球員相撞。


As of Alpha 3, any collision event handler that returns true will stop further propagation of that collision event, even if there are further listeners that would otherwise have received it. This allows you to further limit the number of events that are created and passed to the Lua side. While individual events are not very expensive, large numbers of them can affect overall performance, so limiting event propagation is a good practice.
作為 Alpha 3,任何碰撞事件處理程序返回true會停止進一步的傳播,碰撞事件,即使有進一步的監聽,否則已收到。這使您可以進一步限制數量的事件是創建並傳遞到 Lua 的一面。雖然個別事件不是很昂貴,大量可以影響他們的整體表現,因此限制了事件的傳播是一個很好的做法。

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 12 週四 201111:30
  • Corona Physics Engine The Corona Physics API

Overview 概述


Corona makes it very easy to add physics to your games, even if you've never worked with a physics engine before. While the underlying engine is built around the well-known Box2D, we've taken a radically different design approach that eliminates most of the coding that is traditionally required.
Corona使得它很容易添加到您的物理遊戲,即使你從來沒有同一個物理引擎之前。雖然基礎引擎是建立在著名的Box2D的,我們已經採取了完全不同的設計方法,消除了最傳統的編碼是必需的。


More Information
For more information see the Corona Physics guide.
更多信息
欲了解更多信息,請參閱Corona物理指南。


Physics Engine The Corona Physics API


Corona makes it very easy to add physics to your games, even if you've never worked with a physics engine before. While the underlying engine is built around the well-known Box2D, we've taken a radically different design approach that eliminates most of the coding that is traditionally required.
Corona使得它很容易添加到您的物理遊戲,即使你從來沒有同一個物理引擎之前。雖然基礎引擎是建立在著名的Box2D的,我們已經採取了完全不同的設計方法,消除了最傳統的編碼是必需的。


In addition, we've tied physics seamlessly into mobile development: for example, using our new "gameUI" library, any physics object can now be made multitouch-draggable with one additional line of code.
此外,我們已經綁物理無縫移動開發:例如,用我們的新的“gameUI“庫,任何物理對象現在可以多點,拖動一個額外的一行代碼。


To work with the Corona physics engine, you begin with familiar Corona objects. Corona treats physical body properties as an extension of its graphics objects: any standard display object, including images, vector drawings, or animated sprites, can be “made physical”, and will automatically begin to interact with other objects in the simulation.
若要使用Corona物理引擎,你就開始熟悉的Corona對象。Corona處理的身體屬性,擴展其圖形對象:任何標準的顯示對象,包括圖片,向量圖,或動畫精靈,可以“做物理“,將自動開始與其他對象進行交互的模擬。


Our design goal is to allow users to think primarily in terms of visible game elements wherever possible, as opposed to constructing an invisible physical world and then attaching visible sprites afterwards.
我們的設計目標是讓用戶認為主要是在可見的遊戲元素方面盡可能,而不是構建一個無形的物質世界,然後附加可見精靈之後。


Also, Corona automatically translates between its familiar onscreen units and the internal metric units of the physical simulation. All position values are exposed in pixels, which are converted internally to meters at a default ratio of 30 pixels per meter (this ratio is user-settable with physics.setScale).
此外,Corona之間的自動轉換屏幕上熟悉的單位和公制單位的內部的物理模擬。所有位置值都暴露在像素,這是轉換內部米默認比例每米30像素(這個比例是用戶可設置與 physics.setScale)。


For consistency with the rest of the Corona SDK, all angular values are exposed in degrees, rather than radians, and position (0,0) remains at the upper left-hand corner of the screen, with the y-axis pointing downwards. Shape definitions should declare their points in clockwise order.
為了保持一致性,其餘的Corona SDK中,所有的角值都暴露度,而不是弧度而且位置(0,0)仍然在左上角在屏幕右下角,與 Y軸指向下方。形狀定義應申報點順時針順序。


Physics world setup物理世界格局

This line makes the physics engine features available under the “physics” namespace:
這條線使物理引擎可用功能下的“物理學“命名空間:
-------------
local physics = require "physics"
-------------



physics.start( [noSleep] )

The following functions start, pause, and stop the physics simulation. start either instantiates or resumes the world, and should be called before any of the other functions in this section.
下面的函數開始,暫停和停止的物理模擬。無論是實例啟動或恢復世界,應該叫之前的其他功能在這一節。


Note that stop is treated as a request to destroy the world, so if you merely want to pause the physics engine, you should use physics.pause().
請注意,停止被視為一個請求來毀滅世界,所以如果你僅僅是要暫停的物理引擎,你應該使用physics.pause()。
-------------
physics.start()
 
physics.pause()
physics.stop()
------------
By default, Box2D bodies not involved in a collision will "sleep" after a couple of seconds. This reduces overhead, but in some cases you may not want this behavior. 
默認情況下,Box2D的機構沒有參與碰撞將“睡眠“幾秒鐘後,幾個。這減少了開銷,但在某些情況下,您可能不希望這樣的行為。


For example, the "ShapeTumbler" sample code will not work well if bodies are allowed to sleep, since sleeping bodies do not respond to changes in the direction of gravity.
例如,“ShapeTumbler“示例代碼將無法正常工作,如果身體允許睡覺,因為睡覺機構不回應重力的方向的變化。


You can override this behavior on a given body with body.isSleepingAllowed = false, but you can also override this globally for all bodies in the world by using an optional boolean parameter in start:
您可以覆蓋此行為在給定的機構,body.isSleepingAllowed=false,但你也可以覆蓋這個全域的所有機構在世界上用一個可選的布爾參數開始:
----------------
physics.start( true ) -- prevent all bodies from sleeping  防止所有機構睡覺
 
physics.start( false ) -- default behavior; bodies may sleep  默認行為;機構可以睡覺
-----------------------


physics.setGravity
設置 x,y分量的全球重力載體,單位 m/s2。默認為(0,9.8)的標準來模擬地球引力,向下在Y軸。
-------------
physics.setGravity( 0, 10 )
--------------
physics.getGravity


Returns the x,y components of the global gravity vector, in units of m/s2. This takes advantage of the fact that Lua functions can return multiple values.
返回的x,y分量的全球重力載體,單位 m/s2。這充分利用了這一事實 Lua函數可以返回多個值。
--------------
gx, gy = physics.getGravity()
---------------


Tilt-based gravity傾斜的重力


Using the above setter, and the existing Corona accelerometer API, it is very easy to implement tilt-based dynamic gravity (note that the y-component returned by the accelerometer hardware must be inverted to conform to Corona coordinates):
使用上面的設置器,而現有的Corona加速API,它是很容易實現傾斜的動態重力(請注意,y分量加速度計傳回的硬件必須符合Corona反向坐標):
-----------------
local function onTilt( event )
        physics.setGravity( 10 * event.xGravity, -10 * event.yGravity )
end
 
Runtime:addEventListener( "accelerometer", onTilt )
----------------
See the “ShapeTumbler” sample project for an example of this feature (the accelerometer is not present in the Corona Simulator, so create a device build to see the effect).
參見“ShapeTumbler“示例項目為例,此功能(加速度計不存在Corona中的模擬器,因此創建一個設備構建看到效果)。


physics.setScale

Sets the internal pixels-per-meter ratio that is used in converting between onscreen Corona coordinates and simulated physics coordinates. This should be done only once, before any physical objects are instantiated.
設置內部像素的每米的比例,用於在屏幕上的Corona坐標之間的轉換和模擬物理坐標。這項工作應該只有一次,在任何物理對象被實例化。


Changing this value has no visual consequences, and simply affects the accuracy of the physical model. The Box2D engine is tuned for simulating medium-sized objects between 0.1m and 10m in size, so it works best when the objects in your game are mapped to physical properties that fall roughly within this range.
改變這個值沒有視覺的後果,影響了準確性和簡單的物理模型。該 Box2D的發動機調整為模擬中等大小的物體之間的0.1米和10米的大小,因此它最適合當你的遊戲中的對象映射到物理特性大致屬於這個範圍之內。


The default scaling value is 30, which means that the optimal 0.1m to 10m range corresponds to visible sprites between 3 and 300 pixels in size, which should cover most typical iPhone content. For higher-resolution devices like iPad, Android, or iPhone 4, you may wish to increase this value to 60 or more.
physics.setScale
默認縮放值是30,這意味著最佳0.1米至10米範圍對應於可見精靈3至300像素的大小,它應該包括最典型的iPhone內容。對於高解析度設備如iPad的,Android,或iPhone4,您可能希望增加該值到60以上。
---------------
physics.setScale( 60 )
---------------


You may also want to increase this value if the objects you are simulating are relatively small. As a rough guide, take the width of a sprite in pixels and divide it by its real-world width, if any. For example, a basketball is about 0.25 meters across, so a 20-pixel basketball sprite suggests a physics scaling factor of roughly (20 / 0.25) = 80. However, the resulting effect also depends on how much your chosen density (mass) values approximate the "real world". Therefore, you should ultimately set this scaling factor to whatever feels right within the context of your game: if objects seem too sluggish, and fall too slowly, then they are too big and heavy for your purposes -- try raising the scaling value and/or reducing their densities.
您可能還需要增加這個值,如果你是模擬的對象都比較小。作為一個粗略的指南,採取寬度 Sprite的像素和劃分它在其現實世界的寬度,如果有的話。例如,籃球是約 0.25公尺,所以20像素的籃球精靈表明了物理學的比例因子約為(20/ 0.25)=80。然而,由此產生的效果也取決於您選擇的多少密度(質量)值近似的“現實世界“。因此,你應該最終設置此換算係數的權利在任何情況下感覺你的遊戲:如果對象似乎過於緩慢,和下降速度太慢,那麼他們太又大又重您的目的-嘗試提高定標值和/或降低其密度。


Note that this pixels-per-meter factor is relative to your original content dimensions, if you use the Corona content scaling features to deploy the same code across different screen resolutions (such as iPhone and Android). See the Corona API Reference for more information on autoscaling content for multiple screens.
請注意,此像素每平方米的因素是相對於原始內容的尺寸,如果您使用Corona內容縮放功能相同的代碼部署在不同的屏幕分辨率(如iPhone和Android)。見Corona API參考有關詳細信息,自動縮放多個屏幕內容。


Also, since onscreen objects are not resized when this value is changed, the visible simulation may behave strangely if it is changed while physical objects are already onscreen. In other words, this setting is not the correct way to visibly scale the world. To do that, you should add all the game objects to a common Corona display group, which will cause the simulation to operate according to the group’s internal coordinates rather than the global stage coordinates, and then scale or pan that group. See the “EggBreaker” sample code for a demonstration of this technique.
此外,由於屏幕上的對象不調整大小時,這個值改變時,可能會出現奇怪的可視化仿真,如果它被改變,而物質對象已經在屏幕上。換句話說,此設置是不是正確的方法,能明顯地規模的世界。為了做到這一點,你應該添加所有的遊戲對象到一個共同的Corona顯示組,這將導致模擬操作根據本群組的內部協調,而不是在全球舞台的坐標,然後縮放或平移該組。參見“EggBreaker“示例代碼演示了這種技術。


physics.setDrawMode
Selects one of three possible rendering modes for the physics engine. This mode may be changed at any time -- see the "DebugDraw" sample project for an example of how to toggle it on the fly.
三種可能的選擇之一渲染模式的物理引擎。這種模式可能會隨時改變- 見“DebugDraw“示例項目為例,如何切換它在飛。
----------
physics.setDrawMode( "debug" ) -- shows collision engine outlines only 只顯示碰撞發動機概述
physics.setDrawMode( "hybrid" ) -- overlays collision outlines on normal Corona objects 覆蓋碰撞物體輪廓正常Corona
physics.setDrawMode( "normal" ) -- the default Corona renderer, with no collision outlines 默認Corona渲染,沒有碰撞概述
------------
While this feature will also run on devices, it will probably be most useful in the Corona Simulator, when debugging unexpected physics engine behavior.
這個功能也將在設備上運行,它可能是最有用的Corona中的模擬器,調試時意外的物理引擎的行為。


When working with Corona display groups and Box2D, it is important to keep in mind that Box2D expects all physics objects to share a global coordinate system. This means that a set of ungrouped Corona objects will work well, and a set of objects that are all added to the same display group should also work, since they will share the internal coordinates of that group -- this is demonstrated in the "EggBreaker" sample code, which uses a single moving display group to create a "moving camera" effect.
當使用Corona顯示組和Box2D的,重要的是要記住,Box2D的預期所有對象共享一個物理全局坐標系統。這意味著,一組不分組Corona對象將工作做好,還有一組對象都添加到同一個顯示組也應努力,因為他們將分享該組的內部協調- 這是表現在“EggBreaker “示例代碼,它使用一個單一的移動顯示組創建一個“移動鏡頭“的效果。


However, unexpected results may occur if physical objects are added to different display groups, especially if the groups are then moved in different directions. The "hybrid" draw mode makes these issues much easier to diagnose, since it lets you overlay the physics engine's collision boxes and shapes on top of the Corona renderer.
但是,如果可能會出現意外的結果物理對象被添加到不同的顯示群體,特別是如果組,然後在不同的方向移動。 “混合“畫模式使這些問題更容易診斷,因為它可以讓你覆蓋了物理引擎的碰撞和形狀的盒子上面的Corona渲染。


The physics data is displayed using color-coded vector graphics, which reflect different object types and attributes:
物理數據顯示彩色編碼的矢量圖形,這反映了不同的對象類型和屬性:


Orange: dynamic physics bodies (the default body type)橙色:動態物理機構(默認主體類型)
Dark blue: kinematic physics bodies深藍色:物理機構運動學
Green: static physics bodies, such as the ground or walls綠色:靜態物理機構,如地面或牆壁
Gray: a body that is "sleeping" due to lack of activity 灰色:一個機構,是“睡覺“,由於缺乏活動
Light blue: joints 淺藍色:接頭
NOTE: While the physics debug draw renderer should correctly account for physics objects in nested display groups, it will display misleading results if display groups are rotated or scaled. This will be addressed in a future release.
注意:當物理調試畫渲染應該正確帳戶對物理對象的嵌套顯示組,它會顯示錯誤的結果,如果顯示組的旋轉或縮放。這將是在未來的版本處理。


physics.setPositionIterations
Sets the accuracy of the engine's position calculations.
設置精度發動機的位置計算。
----------------
physics.setPositionIterations( 16 )
-----------------


The default value is 8, which means that the engine will iterate through eight position approximations per frame for each object. Increasing this number will cause fewer momentary innacuracies (overlapping objects. etc.) but will increase computational overhead. The default value should be good for most general cases.
默認值是8,這意味著該引擎將遍歷八個方位逼近每幀為每個對象。增加這個數字將產生更少的瞬間 innacuracies(重疊的對象。等),但會增加計算開銷。默認值應該是很好的最一般的情況。



physics.setVelocityIterations

Sets the accuracy of the engine's velocity calculations.
設置精度發動機的速度計算。
-------------
physics.setVelocityIterations( 6 )
-------------
The default value is 3, which means that the engine will iterate through three velocity approximations per frame for each object. Increasing this number will cause fewer momentary innacuracies (overlapping objects. etc.) but will increase computational overhead. The default value should be good for most general cases.
默認值是3,這意味著該引擎將通過三個迭代逼近每幀的速度為每個對象。增加這個數字將產生更少的瞬間 innacuracies(重疊的對象。等),但會增加計算開銷。默認值應該是很好的最一般的情況。


A note for current Box2D users 當前 Box2D的用戶請注意


Corona incorporates the latest version of the Box2D physics engine (currently v2.1.2) , written by Erin Catto of Blizzard Entertainment.
Corona採用了最新版本的Box2D的物理引擎(目前v2.1.2),書面由Erin卡托暴雪娛樂。


Porting Box2D applications from other platforms should be fairly easy. The Corona API includes most of the core features of Box2D, including:
移植Box2D的應用程序從其他平台應該是相當容易的。電暈 API包括最核心的特徵 Box2D的,其中包括:


Automatic world setup, scaling, and synchronization with visible Corona objects
Basic collision geometry (boxes, circles and arbitrary polygons)
Complex collision geometry (multi-element bodies)
Attributes for primary body and fixture properties
Collision events via Corona event listeners, including collision forces
Primary collision event phases: began and ended
Additional collision event types: preCollision and postCollision, which correspond to Box2D "preSolve" and "postSolve" collision features
Draggable object handling within the simulation
Eight types of joints: distance, pivot, piston, friction, weld, wheel, pulley and touch (some of these are renamed from their Box2D counterparts; see “Joints” section below)
Touch joints (based on Box2D "mouse joints") can be used with multitouch, for simultaneous dragging of 5-10 physics objects; see "DebugDraw" sample project
Joint motors and limits
Applied forces and impulses, both linear and angular
Dynamic gravity, including accelerometer-driven gravity
Sensors and bullets
Collision categories, masking and groups
“DebugDraw” mode, including an exclusive "hybrid" mode showing the debug view as an overlay
Joint and body destructors


全自動世界格局,縮放和同步對象可見電暈
基本碰撞幾何(盒,圓和任意多邊形)
幾何形狀複雜的碰撞(多元素機構)
主要機構的屬性和夾具性能
通過電暈碰撞事件的事件偵聽器,包括碰撞力
碰撞事件的初步階段:開始和結束
額外的碰撞事件類型:preCollision和postCollision,它們對應於 Box2D的“preSolve“和”postSolve“碰撞特性
可拖動對象在模擬處理
八種類型的關節:距離,樞紐,活塞,摩擦,焊接,輪,滑輪和觸摸(其中一些是從他們的Box2D的同行改名,見“關節“一節)
觸摸關節(基於 Box2D的“鼠標接頭“)可用於多點,可同時拖動5-10物理對象;見“DebugDraw“示例項目
聯合電機和限制
作用力和衝動,線性和角
動態重力,包括加速推動的重力
傳感器和子彈
碰撞類別,掩蔽和組
“DebugDraw“模式,包括獨有的“混合“模式顯示了作為一個覆蓋調試視圖
聯合和身體析構


Features not yet supported include:
功能尚不支持包括:
Gear joints
Ray casting, region queries, etc.
Automatic resizing of physics objects when Corona display objects are resized with xScale/yScale attributes (avoid using xScale/yScale on an already-existing physical object in the meantime).
齒輪接頭
光線投射,區域查詢等
自動調整大小的物理對象時顯示對象大小電暈帶 XScale/ yScale屬性(避免使用的Xscale/ yScale在一個已經存在的物理對象在此期間)。
























(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
  • 5月 11 週三 201116:07
  • Corona Animation and Motion Basic Motion and Transitions Part2

Advanced Animation Using Sprites先進的動畫使用精靈


What are Sprite Sheets?精靈是什麼表?

Sprite sheets are 2D animations packed as multiple frames into a single texture image. This allows a much more efficient use of texture memory, which is highly limited on mobile devices, and also minimizes loading time.
精靈表是二維動畫包裝成多個幀到一個單一的紋理圖像。這使得更有效地利用紋理內存,這是非常有限的移動設備,並最大限度地減少加載時間。


Corona supports two types of sprite sheets: those whose animation frames are all sized and positioned uniformly, and those whose frames have non-uniform sizes and positions. In the former case, you simply provide Corona with the width and height of each frame in the sprite sheet image file to create a new internal representation of the sprite sheet. The image below (from the JungleScene sample project that ships with Corona SDK) is an example of a sprite sheet with uniformly-sized frames.
Corona支持兩種類型的精靈表:那些動畫幀大小和位置都均勻,那些畫面有非均勻的的大小和位置。在前一種情況下,您只需提供Corona的寬度和高度每幀圖像中的精靈表文件來創建一個新的內部表示的Sprite表。下面的圖片(從 JungleScene示例項目,船舶與Corona SDK)是一個例子,一個精靈片均勻大小的幀。

 


In the other case, the positions and sizes of individual frames within the sprite sheet are described by an external data file that can be exported from several sprite sheet generator tools (such as Zwoptex or TexturePacker). 
在其他情況下,個別位置和大小框架內的精靈表,描述了一個外部數據文件,可以從幾個精靈出口表發生器工具(如Zwoptex或TexturePacker)。




Corona lets you easily create an internal sprite sheet object from a sprite sheet image and its accompanying data file. See below for examples of how to work with both types of sprite sheets. The sprite sheet below (from the HorseAnimation sample project) contains frames with non-uniform sizes and positions.
Corona讓您輕鬆創建一個內部精靈表對象從一個精靈張圖像和與之配套的數據文件。見下面的例子,如何使用這兩種類型的精靈表。 精靈的表如下(從 HorseAnimation樣本項目)包含框架與非均勻大小和位置。


Corona also includes constructors for complex animated characters with multiple sequences, and sequence playback methods that are time-based rather than frame-based, so animation duration will remain consistent on slower devices. These time-based sequences also allow you to individually choose and tweak the frame rate for each sequence, rather than having the animation speed locked to the application’s global frame rate.
Corona還包括構造複雜的動畫人物與多個序列,序列回放方法是基於時間,而不是基於幀的,因此動畫的持續時間將保持一致在速度較慢的設備。這些基於時間序列,也可以讓您單獨選擇和調整幀速率為每一個序列,而不是動畫的速度鎖定在應用程序的全球幀速率。


There may be more than one instance of each sprite on the stage at the same time, playing at different locations and with different durations. A sprite animation behaves like any other Corona display object -- it may be added to a group or transformed, or even used as a Box2D physics object.
可能有多個實例的每個精靈在舞台上在同一時間,打在不同地點和不同時間。一個 Sprite動畫Corona行為像任何其他顯示對象- 這可能是添加到組或轉換,或甚至作為 Box2D的物理對象。


The JungleScene sample project demonstrates using two different sprite sheets (both with uniformly-sized frames), to create animations running at different frame rates. To see an example of sprite sheet source images, view the files “greenman.png” and “runningcat.png” in that project folder.
該 JungleScene示例項目演示如何使用兩種不同的精靈片(包括均勻大小的幀),以創建動畫運行在不同的幀速率。要查看示例精靈表源圖像,查看文件“greenman.png“和”runningcat.png“在該項目文件夾。


The HorseAnimation sample project demonstrates how to use create a sprite sheet from a Lua data descriptor file and source image whose frames are non-uniformly sized and positioned in the sheet.
該 HorseAnimation示例項目演示如何使用創建一個精靈從一個 Lua表數據描述符和源文件的幀圖像非均勻大小調整和定位工作表中。


Limitations限制

If you attempt to use a sprite sheet whose width or height exceeds your device's maximum texture size, no image will be displayed.
如果您嘗試使用一個精靈表的寬度或高度超過您設備的最大紋理尺寸,無圖像將顯示。


To check the maximum texture size, use system.getinfo("maxTextureSize").
要檢查最大紋理大小,使用system.getinfo(“maxTextureSize“)。


Summary綜述
For each animation sequence, the developer specifies the following things:
對於每個動畫序列,開發商指定了以下幾點:


*Source image (the sprite sheet)
*One of the following:
*The height and width of each frame within the sprite sheet (for sprite sheets with uniformly sized frames)
*A Lua data descriptor file that describes the size, position, and other attributes of each frame (for sprite sheets with non-uniformly sized frames). Typically this would be generated by a sprite sheet packing utility.
*Location of sprite frames -- these may not be contiguous!
When drawing an instance of the sprite animation, the developer specifies:
*源圖像(精靈表)
*下列其中一項:
*高度和寬度在每幀精靈表(精靈片大小均勻的幀)
*一個 Lua數據描述符文件,它描述的大小,位置和其他屬性每幀(片精靈與非均勻大小的幀)。通常這會產生一個精靈表包裝工具。
*位置精靈框架- 這可能不是連續的!
當畫一個實例的Sprite動畫,發展商指定:


*Destination in the scene
*Optional transforms such as rotate/scale
*Length of animation (time-based)
*Looping behavior
*目的地在現場
*可選的變換,如旋轉/縮放
*長度的動畫(基於時間)
*循環行為


Sprite API精靈的API
This line makes the sprite features available under the “sprite” namespace:
這條線使精靈可用功能下的“精靈“命名空間:

(繼續閱讀...)
文章標籤

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

  • 個人分類:Corona
▲top
«1...56720»

最新文章

    文章精選

    個人資訊

    createps
    暱稱:
    createps
    分類:
    攝影寫真
    好友:
    累積中
    地區:

    熱門文章

    • ()C# 取亂數 record
    • ()C# lock record
    • ()C# Dictionary用法 record
    • ()C# ToString 格式 record
    • ()C# 十進制轉各進制,再轉回來 record
    • ()C# GUID產生亂數字串 record
    • ()C# 除法顯示小數點 record
    • ()C# List排序 record
    • ()C 函式參數指標寫法
    • ()中華電信、無線IP分享器和網路交換器如何連接

    文章分類

    • 國外旅遊 (2)
    • C# (87)
    • 喜歡的歌 (1)
    • GRD3 (1)
    • XNA (12)
    • C++ (4)
    • Game (1)
    • Game (1)
    • Apple (3)
    • 物理 (1)
    • 歌曲 (4)
    • SQL (1)
    • FTP (2)
    • 創業 (4)
    • 笑話 (1)
    • 技巧 (2)
    • Shader (1)
    • VB.NET (2)
    • 大易 (1)
    • 輸入法 (1)
    • OS (2)
    • Unity3D (3)
    • Lua (2)
    • Corona (29)
    • DirectX (15)
    • XNA 4.0 (2)
    • 程式使用 (1)
    • 懷孕 (1)
    • Facebook (1)
    • 網路硬體 (1)
    • 未分類文章 (1)

    文章搜尋

    誰來我家

    參觀人氣

    • 本日人氣:
    • 累積人氣: