Total Pageviews

Wednesday, April 23, 2014

event.text()

event.text
វាជា text របស់ textField or TextBox (រួមបញ្ចូលទាំង new text)
ចំណាំះ event.text ត្រឡប់ជា current text string នៅក្នុង “editing” phase ប៉ុន្តែមិនបញ្ចូលនៅក្នុង “submitted” or “ended” phases។ ការប្រើ event.target.text ក្នុងការ retrieve the text អំឡុងពេល phases
សូមមើលកូដះ
local defaultField
local function textListener( event )
    if ( event.phase == "editing" ) then
        print( event.text )
    elseif ( event.phase == "submitted" or event.phase == "ended" ) then
        print( event.target.text )
    end
end
defaultField = native.newTextField( 15015018030 )
defaultField:addEventListener( "userInput", textListener )


event.startPosition()

event.startPosition
វាជា position ដែល cursor ស្ថិតនៅ ពេលដែល event ចាប់ផ្តើម។ Property នេះគឺមានតែនៅក្នុង “editing” event.phase របស់ userInput events
សូមមើលកូដះ
local function textListener( event )
    if ( event.phase == "editing" ) then
        print( event.startPosition )
    end
end
defaultField = native.newTextField( 15015018030 )
defaultField:addEventListener( "userInput", textListener )


event.oldText()

event.oldText
នេះជា characters ដែលតំណាងនៅក្នុង TextField or TextBox មុនពេលដែល new characters ថ្មីដែលត្រូវបញ្ចូលទៅក្នុង event។ property របស់វា គឺមានតែក្នុង “editing” event.phase នៃ userInput events
សូមមើលកូដះ
local defaultField
local function textListener( event )
    if ( event.phase == "editing" ) then
    print( event.oldText )
    end
end
defaultField = native.newTextField( 1205018030 )
defaultField:addEventListener( "userInput", textListener )


Looking deeper to the event of Corona SDK

Event UserInput របស់ Corona SDK
នេះជា user input របស់ event នៅក្នុង Corona SDK គេប្រើសំរាប់ userInput events ដែលមានជាមួយនឹង ​TextFields & TextBoxes។ វាត្រូវប្រើជាមួយនឹង listen to text input events ដែលបានមកពី user interaction
ចំណែក Properties របស់វាមានះ

event.newCharacters(string)
ប្រើ new characters ដែលត្រូវបញ្ចូលសំរាប់ eventproperty របស់វាអាចមានតែអំឡុងពេល editing event.phase នៃ userInput events
សូមមើលកូដះ
local defaultField
local function textListener( event )
    if ( event.phase == "editing" ) then
        print( event.newCharacters )
    end
end
defaultField = native.newTextField( 150, 150, 180, 30 )
defaultField:addEventListener( "userInput", textListener )


Monday, April 21, 2014

physics.toMKS()

physics.toMKS()
ពីមុនយើងបានមើលអំពី physics.fromMKS()។ ចូរក្រឡេកមើល physics.toMKS() ម្តងមើល
ការប្រើ Physics នេះសំរាប់ Convenience ហ្វាំងសិន សំរាប់បំលែងពី MKS units ទៅជា Corona units។​ Syntax: physics.fromMKS (unitName, value)
unitName(តំរូវការ) វាជា String ដែលអាចជ្រើសចេញមួយពីខាងក្រោមះ
“length”, “velocity”, “angularVelocity”
Value(តំរូវការ) វាជាចំនួនលេខ ដែលជាតំលៃក្នុងការបំលែង MKS ទៅកាន់ Corona Units

សូមមើលកូដះ
Local corona_unit = physics.toMKS (“velocity”, 30)




physics.stop()

physics.stop()
ជាធម្មតាមាន start ត្រូវតែមាន Stop។ ចូរមើលពីវាម្តង ការប្រើប្រាស់ stops the physics engine។ ដែលហ្វាំងសិននេះនឹងត្រឡប់ជា false ហើយនឹងបង្ហាញនូវ ​warning message នៅក្នុង​Corona simulator បើសិនជា API មិនអាចដំណើរការបាន
Syntax: physics.stop()

សូមមើលកូដះ
Local physics = require “physics”
Physiscs.start()
Timer.performWithDelay (2000, function()
            Physics.stop()
End,
1
)

physics.start()

physics.start()
អ្នកដឹងពីរបៀបហៅ physics.start() នៅពេលហៅវាចេញមកធ្វើការ។ កាហៅនេះសំរាប់ ដាក់នៅខាងលើនៃហ្វាល់ main.lua
Local physics = require “physics”
Physics start()
ដែលវាមាន syntax: physics.start(noSleep)
noSleep(ជំរើស) គេប្រើសំរាប់ដាក់វា true or false (boolean) ដែល ​true នឹងធ្វើឪ្យគ្រប់ទាំង body not sleeping នៅពេលដាក់ជា​ false វានឹងធ្វើឪ្យគ្រប់ទាំង body to sleep (default mood)


physics.setVelocityIterations()

physics.setVelocityIterations()
គេប្រើសំរាប់បញ្ចូលនៅតំលៃដ៏ត្រឹមត្រូវរបស់ engine’s velocity calculation។ តំលៃដើមវាគឺ៣
Syntax: physics.setVelocityIterations (value)
Value(តំរូវការ)វាជាចំនួនលេខដែលជា Iterations។ តំលៃដើមរបស់វាគឺ៣ មានន័យថា engine will iterate through three velocity ដែលមាន៣ហ្វ្រេមសំរាប់ Object នីមួយៗ
សូមមើលកូដះ
Physics.setVelocityIterations (6)

physics.setTimeStep()

physics.setTimeStep()
ការប្រើនេះសំរាប់ frame-based physics simulation Or time-based simulation
Syntax: physics.setTimeStep (dt)
Dt(តំរូវការ) វាជាចំនួនលេខដែលជាតំលៃរបស់ Physics “time step ” in seconds, តាមរយះ សូន្យ ក្នុងការទទួល approximate time-based physics simulation ។ ដែល​-1 ជាតំលៃដើម (frame-based)
សូមមើលកូដះ
Physics.setTimeStep(0)


physics.setScale()

physics.setScale()
នេះការបញ្ចូលនូវ internal pixel-per-meter ratio ដែលប្រើសំរាប់បំលែង on screen corona coordinated ទៅនឹង​ simulated physics coordinates។ វាត្រូវប្រើតែម្តងមុនពេលដែល any physics objects are instantiated។ បើប្តូរតំលៃវានឹងមិនមាន visual consequenses។ វានឹងប៉ះពាល់ដល់ physic model។ ពីព្រោះ Box2D engine is tuned for simulating medium-sized objects between 0.1m and 10m in size។ ដូចនេះការប្រើ Objects in game ត្រូវតែ mapped ជាមួយនឹង​ physical properties that fall roughly within this range។ ចំណែកតំលៃ scale ដើមគឺ 30 មានន័យថា ០.១​ទៅកាន់ ១០ម range corresponds to visible objects btween 3 & 300 pixels in size។ សំរាប់រូបភាពធំ សូមបង្កើនតំលៃជា ៦០ ឬច្រើនជាង
សូមបង្កើនតំលៃបើសិនជា Objects simulating seem to sluggish or reach too slowly។ វាប្រហែលជាធំហើយនឹងធ្ងន់ សូមព្យាយាមក្នុងការ raising the scale calue and or reduce their desities
Syntax: physics.setScale (value)
Value (តំរូវការ)វាជាចំនួនលេខដែលត្រូវបញ្ចូលនៅតំលៃ Scale។ តំលៃដើមគឺ ៣០ range corresponds to visible objects btween 3 & 300 pixels in size
សូមមើលកូដះ​
Physics.setScale (60)



physics.setReportCollisionsInContentCoordinates()


ប្រើសំរាប់បញ្ចូលនៅ content origin ជា collision point នៅក្នុង collision, preCollision, and PostCollision physics events
Syntax: physics.setReportCollisionInContentCoordinates (enabled)
Enabled (តំរូវការ)វាជាការប្រើ Boolean ក្នុងការបញ្ចូលទៅ physics engine ក្នុងការត្រឡប់មកនូវ collision point រវាង two bodies​ នៅក្នុង content coordinates។ វាមានន័យថានៅពេល two bodies collide, the event.x & event.y reported to the collision listener will equate to the exact point where collision occurred
សូមមើលកូដះ
-- Toggle the collision point.
if ( physics.getReportCollisionsInContentCoordinates() ) then
    physics.setReportCollisionsInContentCoordinates( false )
else
    physics.setReportCollisionsInContentCoordinates( true )
end


physics.setPositionIterations()

physics.setPositionIterations()
សំរាប់ដាក់បញ្ចូលនូវតំលៃត្រឹមត្រូវរបស់ engine’s position calculation, តំលៃដើមគឺ៨
Syntax: physics.setPositionIterations (value)
Value(តំរូវការ) វាជាចំនួនលេខដែល iteration value, the default is 8 which means that the engine will iterate through 8 positions approximations per frame for each object. Increasing this number will cause fewer momentary inaccuracies line overlapping objects, but it will increase computational overhead. The default value should work for most general cases
សូមមើលកូដះ
Physics.setPositionIterations (16)


physics.setParticleRadius()

physics.setParticleRadius()
បញ្ចូល radius របស់ particles នៅក្នុង content units
Syntax: physics.setParticleRadius (radius_in_content_units)
radius_in_content_units(តំរូវការ)វាជាចំនួនលេខដែលជា radius of particles in content units
សូមមើលកូដះ
Physics.setParticleRadius (16)


physics.setMKS()

physics.setMKS()
ប្រើក្នុងការបញ្ចូលទៅកាន់ MKS (meters, kilograms and seconds) ជាតំលៃរបស់ physics simulation for specific keys។ វាត្រូវប្រើសំរាប់ថ្នាក់ Advanced – the average developer and project will not require this functions
Syntax: physics.setMKS (key, value)
Key(តំរូវការ) វាជា String ជា Key ត្រូវបញ្ចូលទៅក្នុង MKS units:
velocityThreehold corresponds to b2_velocityThreehold
timeToSleep corresponds to b2_timeToSleep
linearSleepTolerance corresponds to b2_linearSleepTolerance
angularSleepTolerance coorespnds to b2_anglularSleepTolerance
value(តំរូវការ) វាជាចំនួនលេខជាតំលៃសំរាប់រើស the choosen MKS key
សូមមើលកូដះ
Physics.setMKS (“timeToSleep”,10)


physics.setGravity()

physics.setGravity()
ប្រើសំរាប់បញ្ចូលនៅ X & Y components របស់ global gravity vector នៅក្នុង units របស់ m/s2
ដែលតំលៃដើម (០,៩.៨) to simulate standard Earth gravity, point downward on the y axis
Syntax: physics.setGravity (gx, gy)
Gx, Gy(តំរូវការ)វាជាចំនួនលេខដែលប្រើក្នុងការបញ្ចូលនៅ gravity vector នៅក្នុង x/y ក្នុង units របស់ m/s2។ មានន័យថាវានឹង​ pull of gravity នៅក្នុង x horizontal and y vertical directions
សូមមើលកូដះ
Physics.setGravity (0,6)


physics.setDrawMode()

physics.setDrawMode()
ប្រើសំរាប់បញ្ចូល១ក្នុងចំណោមបី “rendering modes” សំរាប់ Physics engine។​ នៅពេលដែល Features រត់លើ devices។ it’s most useful in the corona Simulator when debugging enexpected physics engine behavior:
physics.setDrawMode( "hybrid" )  --overlays collision outlines on normal display objects
physics.setDrawMode( "normal" )  --the default Corona renderer, with no collision outlines
physics.setDrawMode( "debug" )   --shows collision engine outlines only
ពេលនោះ Physics data ត្រូវបង្ហាញដោយការប្រើប្រាស់ Color vector graphics which reflect object types and attributes:
Orange: dynamic physics bodies
Dark blue: kinematic physics bodies
Green: stat, non movable physics bodies
Gray: a body that is sleeping due to lack of activity
Light blue: physical joints
Syntax: physics.setDrawMode (mode)
Mode(តំរូវការ) វាជា String ដែល Draw mode, អាចជា “normal”,”hybrid”,”debug”
សូមមើលកូដះ
physics.setDrawMode( "normal" )  --the default Corona renderer, with no collision outlines
physics.setDrawMode( "hybrid" )  --overlays collision outlines on normal display objects
physics.setDrawMode( "debug" )   --shows collision engine outlines only



physics.setDebugErrorsEnabled()

physics.setDebugErrorsEnabled()
ហ្វាំងសិននេះអនុញ្ញាតឪ្យ extra physics errors to be caught by Box2D
ចំណាំះ សំរាប់​ feature នេះមានតែលើ Mac simulator
Syntax: physics.setDebugErrorsEnabled(enabled)
Enabled(តំរូវការ) វាជា Boolean ដែលអនុញ្ញាតឪ្យ extra physics errors to be caught by Box2D
សូមមើលកូដះ
-- Toggle extra physics errors for debugging.
if ( physics.getDebugErrorsEnabled() ) then

    physics.setDebugErrorsEnabled( false )
else
    physics.setDebugErrorsEnabled( true )
end

physics.setContinuous()

physics.setContinuous()
ដោយ default, Box2D បង្ហាញនៅ collision detection continuous ដែលការពារនៅ Objects from “tunneling” បើសិនជាវា turn off an object នឹងធ្វើចលនាយ៉ាងលឿនដែលអាចឆ្លងកាតជញ្ជាំង អិតស្តើងបាន។ ក្នុងដំណាក់កាលដែល complex situations ដែល bodies ត្រូវបានភ្ជាប់ជាមួយនឹង Pivot joints (ragdolls) instability អាចកើតមាន។ ដើម្បីដោះស្រាយវាត្រូវតែ turn up ចំនួនលេខរបស់ velocity iterations ដោយការប្រើ physics.setVelocityIterations()។ វាអាចគិតបានតាមរយះ reduce frame rates។ សំរាប់ដំណោះស្រាយមួយទៀតគឺ disable continuous physics។ វាអាចការពារនៅ instability ដោយគ្មាន increasing iterations។ សូមដាក់ bodies ជា static extra thick to prevent tunneling effects
Syntax: physics.setContinous (enabled)
Enabled (តំរូវការ) វាជា Boolean ក្នុងការគ្រប់គ្រង់ whether continuous physics is enabled or not
សូមមើលកូដះ
Physics.setContinous(false)


physics.setAverageCollisionPositions()

physics.setAverageCollisionPositions()
ពីព្រោះវាមានលក្ខណះធម្មតាសំរាប់ Box2D ក្នុងការ report multiple collision points អំឡុងពេលដែល a single frame iteration, ការបញ្ចូលនេះគឺមានប្រយោជន៏ណាស់ក្នុងការ report those points as one averaged point។ សំរាប់ហ្វាំងសិននេះ Applies ទៅកាន់គ្រប់ទាំង contact points នៅក្នុង collision, preCollision and postCollision physics events
Syntax:
physics.setAverageCollisionPositions( enabled )
enabled (required)
Boolean. Enables the averaging of all contact points in a collision between physics bodies.

សូមមើលកូដះ

-- Toggle the averaging.
if ( physics.getAverageCollisionPositions() ) then
    physics.setAverageCollisionPositions( false )

else
    physics.setAverageCollisionPositions( true )
end


physics.removeBody()

physics.removeBody()
ប្រើសំរាប់ removed a physics body ចេញពី Display object ដោយគ្មានការ destroying the entire object។ សំរាប់ការ remove the body វានឹងបង្កើតនៅ physics.addBody()។ សំរាប់ API នេះមិនអាចប្រើនៅក្នុង Collision event listener។ physics.removeBody() គ្រាន់តែ remove physics body ចេញពី DisplayObject – it does not remove the display object itself។ សំរាប់ហ្វាំងសិននេះត្រឡប់ជា true បើសិនជា body វាត្រូវបាន removed and false បើសិនជាមិនបាន removed។ API will fail បើសិនជាហៅនៅ any collision event listener
Syntax:
physics.removeBody( object )
object (required)
DisplayObject. The object whose physics body will be removed.

សូមមើលកូដះ
if not ( physics.removeBody( object ) ) then
    print( "Could not remove physics body" )
end