Total Pageviews

Monday, April 21, 2014

physics.newJoint()

physics.newJoint()
ប្រហែលជាលំបាកបន្តិចនៅពេលប្រើ physics.newJoint() នៅក្នុង Corona sdk។ អ្នកនឹងយល់ ស្រូលនៅពេលដែលមើលវាដោយលំអិត។ វាជាប្រភេទហ្វាំងសិនដែល Joints ត្រូវបានប្រើ សំរាប់ផ្គុំនៅ more complex game objects ពី multiple rigid bodies។ ដើម្បីសាងសង Joint មុនដំបូង ត្រូវសាងសង់ Bodies ដែលត្រូវ Joined, ហើយត្រូវបានហៅវិធីនេះជាមួយនឹង Desired joint constructor type។ ដើម្បីលុប Joint ចេញត្រូវប្រើ joint:removeSelf() or display.remove(joint)
ចំណាំះ
សូមមើល physics Joints guide សំរាប់ការប្រើប្រាស់ជាច្រើនទៀត។ API នេះមិនត្រូវប្រើនៅក្នុង Collision Event Handler។ មានប្រភេទ Joints ខ្លះវាមិន stable ដោយសារតែ Box2D ប្រើ continuous physics។ អ្នកអាចបិទវាចេញដោយប្រើ Command physics.setContinous()
Syntax: physics.newJoint ( jointType, …)
jointType(តំរូវការ) វាជាប្រភេទ String  ដែលអាចជាមួយក្នុងចំណោមខាងក្រោមះ
Pivot, Distance, Piston, Friction, Weld, Wheel, Pulley, Touch
Object1 (តំរូវការ) វាជា Display Object, ដែល Object ទីមួយប្រើនៅក្នុង joint
Object2: វាជា display Object, ដែល Object ទី2ប្រើនៅក្នុង joint
AnchorX & AnchorY: វាជាចំនួនលេខដែលកំនត់ X & Y locations របស់ joint anchor points
Distance Joints: វាជា distance joints joins នៅ bodies ចំនួន២ នៅចំនុច fixed ណាមួយ។ ពេលដែលចំនុច initial arguments  ដែលមាន two bodies joined, ដែលតាមដោយ​(x,y) anchor point  សំរាប់ body នីមួយៗ។ វាត្រូវបានប្រកាស់នៅក្នុង world coordinates:
Physics.newJoint (“distance”, object1,object2,anchorX1,anchory1,anchorX2,anchorY2)

Friction Joints:
សំរាប់ Joints មួយនេះមានចំនុចពិសេសដែលជា special kind of pivot joint ដែលវា resist motion, ដែលជា sticky:
Physics.newJoint(“friction”, object1, object2, anchorX, anchorY)

Piston Joints:
សំរាប់ ​Joint មួយនេះដែលអាចហៅថា “prismatic joint” នៅក្នុង Box2D វាត្រូវ joins two bodies ជាមួយនឹង single, restricted axis of motion។ វាដូចនឹង pistons or a shock absorber នៅក្នុងឡានមួយ។ the initial arguments ជាប្រភេទ two bodies joined, តាមដោយ anchor point នៅក្នុង first body & a vector ដែលកំនត់ axis ជាមួយនឹង motion ដែលបានអនុញ្ញាត។
Physics.newJoint (“piston”,object1,object2,anchorX1, anchorY1, axisDistanceX, axisDistanceY)

Pivot Joints:
សំរាប់ Joints មួយនេះ ត្រូវបានហៅថា “revolute joint” នៅក្នុង Box2D ដែលវាជាការ joins នៅ two bodies នៅចំនុច overlapping point។ the initial arguments ជាប្រភេទ two bodies joined វាតាមនៅ anchor point នៅក្នុង global coordinates of world:
Physics.newJoint (“pivot”, object1, object2, anchorX, anchorY)

Pulley Joints:
សំរាប់ pulley joint វាភ្ជាប់ជាមួយនឹង two bodies ជាមួយនឹង imaginary rope ដែល length នៅជា constant: បើសិនជា one body is pulled down, the other will pulled up។ ចំណែកការសាងសង់វិញមានការលំបាកបន្តិចដោយសារវាត្រូវតែជា Joint Anchor point នៅចន្លោះ body  រួមទាំងនឹង stationary anchor point នៅក្នុង world coordinates សំរាប់ “rope” នីមួយៗ to hang out។ ចុងក្រោយវាមាន “ratio” property simulate a block and tackle arrangement ដែលចំនុចមួយរបស់ rope នឹង moves faster than the other។ តំលៃដើមវា ratio គឺ ១.០
Physics.newJoint (“pulley”, object1,object2,anchorX1,anchorY1,anchorX2,anchorY2,x1,y1,x2,y2,ratio)

Touch Joints:
ការប្រើសំរាប់ a touch joint (អាស្រ័យលើ Box2D “mouse joint”) វាភ្ជាប់ជាមួយនឹង single object ទៅកាន់ Current position ដែលនៅលើ touch screen។ សំរាប់ connection នេះជាប្រភេទ elastic joint ជាមួយ specifiable strength & behavior ប៉ុន្តែវានៅមិនអាច possible to apply infinite forces to the simulation, សំរាប់ dragged object may “lag behind” a rapidly moving touch
Physics.newJoint (“touch”, object1, targetX,targetY)

Weld Joints:
សំរាបមួយនេះគឺ a weld joint “welds” ដែលមាន two bodies together at a specified point នៅក្នុង World Coordinates
Physics.newJoiunt (“weld”,object1,object2,anchorX,anchorY)

Wheel Joints:
សំរាប់ wheel joint មួយនេះ​(ត្រូវបានហៅថា “line joint” នៅក្នុង Box2D terms) ដែលផ្គុំគ្នាជា Piston & a pivot joint, ដូចជា wheel mounted នៅលើ shock absorber of a car។ ដែល Properties របស់វាភាគច្រើនគឺ inherited ចេញពី standard piston joint; ចំនុចខុសគ្នាគឺថា body at the end of the axis is allowed to rotate freely:
Physics.newJoint (“wheel”,object1,object2,anchor,anchor,axisDistanceX,axisDistanceY)
សូមមើលកូដះ
Local myJoint = physics.newJoint (“pivot”, crateA, CrateB, 200, 300)


No comments:

Post a Comment