Corona SDKã䜿çšããŠã²ãŒã ã®éçºããã¹ã¿ãŒããããšã«æ±ºããå Žåããã®èšäºã§ã¯ããšã³ãžã³èªäœãšéçºããå¿ èŠã®ããLuaèšèªã®å¿ èŠãªåºæ¬ã説æããŸãã ç¬èªã®æ¹æ³ã§ããã®èšèªã¯çŸãããå€ãã®ç¹ã§çããã§ãã æãå¿ èŠãªãã¹ãŠã®æ å ±ã1ã€ã®èšäºã«éããããšããŸãããã1ã€ã®åºçç©ã«æ²èŒã§ãã以äžã®ãã®ã§ããããšãå€æããèšäºã3ã€ã®éšåã«åå²ããå¿ èŠããããŸããã
- ãœãŒã¹ã®ã³ã¡ã³ãæé
- å€æ°ãå®æ°ãã¹ã³ãŒã
- ã¢ãžã¥ãŒã«ãšãããžã§ã¯ãçµç¹
- æ¡ä»¶ä»ãã¹ããŒãã¡ã³ã
ãœãŒã¹ã®ã³ã¡ã³ãæé
ã»ãšãã©ãã¹ãŠã®ããã°ã©ãã³ã°èšèªã«ã¯ã³ã¡ã³ãã®æŠå¿µããããŸãããLuaãäŸå€ã§ã¯ãããŸããã äžè¬çã«ã³ã¡ã³ããšã¯ãããã°ã©ã ã®ãœãŒã¹ã³ãŒãã®èª¬æã§ãããã³ã¡ã³ããããã³ãŒãå ã«çŽæ¥é 眮ãããŸãã ã³ã¡ã³ãã®æ§æã¯ãããã°ã©ãã³ã°èšèªã«ãã£ãŠæ±ºå®ãããŸãã ã³ã³ãã€ã©ãŸãã¯ã€ã³ã¿ãŒããªã¿ãŒã®èŠ³ç¹ããèŠããšãã³ã¡ã³ãã¯ããã°ã©ã ããã¹ãã®äžéšã§ããããã®ã»ãã³ãã£ã¯ã¹ã«ã¯åœ±é¿ããŸããã T.O. ã³ã¡ã³ãã¯ã³ãŒãã®å®è¡é åºã«åœ±é¿ãäžããŸãããã³ã¡ã³ãã¯èªåèªèº«ãšããã°ããããŠãœãŒã¹ã®èª¿æ»ãéå§ã§ãã人ã®ããã«äœæããŸãã ã³ã¡ã³ãã¯ããããã°ããŒã«ãšããŠäœ¿çšã§ããŸãã ã³ãŒããäžæçã«å®è¡ããé€å€ããããšã«ãããã³ãŒãã«ã³ã¡ã³ããæ¿å ¥ããããšãã§ããŸããããã«ãããå¥ã®ã»ã¯ã·ã§ã³ã§ãšã©ãŒãæ€çŽ¢ããç¬éãç°¡åã«ãªããŸãã Luaã«ã¯2çš®é¡ã®ã³ã¡ã³ãããããŸãã
åäžè¡ã³ã¡ã³ã
æåã·ãŒã±ã³ã¹ã-ãããè¡æ«ãŸã§ã«æžããããã®ã¯ãã¹ãŠã³ã¡ã³ããšèŠãªãããŸãã
è€æ°è¡ã³ã¡ã³ã
è€æ°è¡ã®ã³ã¡ã³ãã¯ãã·ãŒã±ã³ã¹ã-[[ãã§å§ãŸããã·ãŒã±ã³ã¹ã]]ãã§ä»»æã®è¡æ°ã§çµäºããŸããã³ã¡ã³ãã®äœ¿çšäŸïŒ
--[[ 2 a b ]] function summ(a,b) return a + b end print(summ(5,7))-- 12
ã³ãŒãã«å¯Ÿããã³ã¡ã³ãã®è³ªã®åé¡ã«ã¯ããŸã泚æãæãããèªåã§æ±ºããã®ã¯å šå¡ã®è²¬ä»»ã§ãã
- ããèªäœã«å¯Ÿããè¯ãã³ãŒãã®ã³ã¡ã³ã-ããªãã¡ æ確ã«æžããŠãå€æ°ã«æå³çã«ååãä»ããå Žåãã»ãšãã©ã®å Žåãã³ã¡ã³ãã¯äžèŠã§ã
- ã³ã¡ã³ããæžããªãã§ãã ãã-ã³ã¡ã³ãã®ããã«ã ããªãã¡ ãã¹ãŠãæ確ãªå Žæã«ã³ã¡ã³ããæžããªãã§ãã ããã
- ç°¡æœãã¯æèœã®å§åŠ¹ã§ãã ã³ã¡ã³ããã·ã³ãã«ã§ãããããããã®ã«ããŸãã
- ãã¡ã€ã«ãšé¢æ°ã®ç®çã«ã€ããŠã³ã¡ã³ãããŸãã
å€æ°ãå®æ°ãã¹ã³ãŒã
ã»ãšãã©ã®ããã°ã©ãã³ã°èšèªã«ã¯å€æ°ããããŸãã ã»ãšãã©ã®å Žåããã®æŠå¿µã¯ååä»ããŸãã¯å¥ã®æ¹æ³ã§ã¢ãã¬ã¹æå®ãããã¡ã¢ãªé åãšããŠç解ããããã®ã¢ãã¬ã¹ãŸãã¯ååã䜿çšããŠããŒã¿ã«ã¢ã¯ã»ã¹ããããã°ã©ã å®è¡äžã«å€ãå€æŽã§ããŸãã Luaã§ã¯ãå€æ°ãé©çšããå¿ èŠãããå Žæã§å€æ°ãäœæã§ããŸãã å€æ°ã䜿çšããåã«äºåã«å€æ°ã宣èšããå¿ èŠã®ããç¹å®ã®ãããã¯ïŒ Pascalãªã©ã®èšèªã®ãã㪠ïŒã¯ãããŸããã å€æ°å®£èšã®äŸã次ã«ç€ºããŸãã
a = 1 b = 3 local c = 'example' d,pi = 2, 3.14 a = 'stroka'
ä»ã®èšèªã®æ奜家ã¯ãããã€ãã®æ©èœã«æ°ã¥ãããšæããŸãã
- å€æ°ã®ã¿ã€ããæå®ããå¿ èŠã¯ãããŸãããå€ã¯ãã®ã¿ã€ãã決å®ããŸã
- å€æ°ã®ã¿ã€ãã¯å€æŽã§ããŸãã å€æ°ãæ°å€ã§ïŒäŸã§ã¯ãaãïŒãæååå€ãå²ãåœãŠãããå Žåãå°æåã«ãªããŸãã
- 1ã€ã®ã=ãèšå·ã«ãã䞊åå²ãåœãŠãå©çšå¯èœã§ãïŒ dãpiå€æ° ïŒã ãã®ããããã£ã¯ãåæåã®éå§æéãå€§å¹ ã«ççž®ã§ããŸãããŸããaãb = bãaãªã©ã®äžéå€æ°ãªãã§å€æ°å€ã亀æããããšãã§ããŸãã
- ããŒã«ã«ããŒã¯ãŒãã ãã®åèªã¯ãå€æ°ã®ã¹ã³ãŒããå¶éããããã«äœ¿çšãããŸããå€æ°ãæäœãããã¯ïŒ é¢æ°ãã«ãŒããæ¡ä»¶ã¹ããŒãã¡ã³ã ïŒå ã§ããŒã«ã«ã«å®£èšãããŠããå Žåãå€æ°ã¯å€æ°å ã§ã®ã¿è¡šç€ºãããŸãã ããŒã«ã«å€æ°ããã¡ã€ã«ã®ã°ããŒãã«ã³ã³ããã¹ãã§å®£èšãããŠããå Žåããã®è¡ãããã¡ã€ã«ã®æåŸãŸã§è¡šç€ºãããŸãïŒ ã¹ã³ãŒãã«ã€ããŠã¯ã以äžã§å°ã説æããŸã ïŒã
å®æ°ã«ã€ããŠèŠãŠã¿ãŸãããã å®æ°ãšã¯ã䜿çšäžã«å€ãå€åããªãå€æ°ãæå³ããŸãã å€ãã®å Žåããããžã§ã¯ãïŒ ã¢ããªã±ãŒã·ã§ã³ããŒãžã§ã³ãªã© ïŒã§ç¹°ãè¿ã䜿çšãããããã€ãã®å€ãå®æ°ã«æ ŒçŽãããšäŸ¿å©ã§ããäžéšã®èšèªã§ã¯ãæåéãã®æå³ã§å®æ°ãäœæããããã®ããŒã«ããããŸãã äžåºŠå®£èšãããå€æ°ãšãã®åŸã®å€ã¯å€æŽã§ããŸãããLuaã«ã¯ãã®ãããªããŒã«ã¯ãããŸããã ãã¹ãŠïŒ é¢æ°ã®å®è£ ãïŒã®ããã«ããããšãã§ããŸãããã®ããã絶ãéãªãå€æŽããä¿è·ããããã®äŸ¿å©ãªãªãã·ã§ã³ïŒååã®é åºïŒãèæ ®ããããšãã§ããŸãã BIG_LETTERS_S_WORD_WORD_INTERCARRATINGã®ããã«ãã³ãŒãå ã§ç®ç«ã€ããã«å®æ°ã«ç¹å¥ãªæ¹æ³ã§ååãä»ããããšããå§ãããŸãããããã¯ã«ãŒã«ã§ã¯ãªãã¢ããã€ã¹ã§ãã
æå¹ãªå€æ°åãå®æ°ãé¢æ°ã®åœ¢åŒãç°¡åã«èª¬æããŸãã宣èšçãªãã®ã§éåã§ããªããã®ããã³ãã«ãããªããã®ããããŸãã
- å€æ°ã«ã¯ãã©ãã³å€§æåãšå°æåãæ°åãã¢ã³ããŒã¹ã³ã¢ã_ããå«ããããšãã§ããŸã
- å€æ°ã¯æ°åã§å§ããããšã¯ã§ããŸãã
- å€æ°ã«ã¯äºçŽèªã®ååãä»ããããšã¯ã§ããŸããïŒandãbreakãdoãelseãelseifãendãfalseãforãfunctionãifãinãlocalãnilãnotãorãrepeatãreturnãthenãtrueãuntilãwhile
- 倧æåãšå°æåãåºå¥ãããŸãã Luaã®ã»ãšãã©ã®èšèªãšåæ§ã«ã倧æåãšå°æåã¯å€æ°ã®äžææ§ã®æ±ºå®èŠå ã§ãã luaãLUAãlUaãããã³LuAã¯ãã¹ãŠç°ãªãå€æ°ã§ãã
- ã¢ã³ããŒã¹ã³ã¢ã§å§ãŸãå€æ°ã®ååãä¹±çšããªãã§ãã ããããã¡ããããããã®ååãèšèªã«ãã£ãŠå éšã¡ã«ããºã ã®åœåã«äœ¿çšãããŠããªãããšã確å®ã§ãªãéãã
- åºãç¯å²ãæã€æå³çãªå€æ°åã䜿çšããŸãã ããã¯æ¬¡ã®ããã«ç解ããå¿ èŠããããŸã-å€ââæ°ããããžã§ã¯ãã®å€§éšåã§äœ¿çšãããå Žåãå€æ°ã¯äœãæå³ãããçãååãæã€ã¹ãã§ã¯ãããŸãã
- å€æ°ãå®æ°ãé¢æ°ã®åœå圢åŒãåããŸãã ããšãã°ãå®æ°ã«ã¯SUCH_FORMATãå€æ°about_thisãããã³é¢æ°ã«this_Formatã䜿çšã§ããŸããããã«ãããã³ãŒãããã䟿å©ã«ãªããŸãã
ã¹ã³ãŒããšã¯ãããŒã¿ã«çŽæ¥ã¢ã¯ã»ã¹ã§ããã³ãŒã空éã®ããšã§ãã ã¹ã³ãŒãã®æ§æã®ååã誀ã£ãŠç解ãããšãå€ãã®äžå¿«ãªãšã©ãŒãçºçããå¯èœæ§ããããŸããããããã¯éåžžãæé€ããã®ãå°é£ã§ãã
- å€æ°ã¯è¡šç€ºãããŸãã-ãã¹ãŠãæ£åžžã§ãå€æ°ãnilïŒ æªå®çŸ© ïŒã§ããããã«æãããŸãã éåžžããã®ãšã©ãŒã¯ç°¡åã«ç¹å®ã§ããŸãããå¿ ãããç°¡åã«æé€ã§ãããšã¯éããŸããã
- å€æ°ã¯äœ¿çšãããŠããªãå Žæã§è¡šç€ºãããŸã-ãã®äžèŠå°ããªåé¡ã¯ãéåžžã«è€éãªãã°ã«ã€ãªããå¯èœæ§ããããŸããããšãã°ãã³ãŒãã®å¥ã®ã»ã¯ã·ã§ã³ã®å€æ°ããã®é åã«è¡šç€ºãããªãããšãæåŸ ãããã®ååšããªãããšã確èªããŠïŒ åæåãããã ïŒæåã§çµäºãããåæåã³ãŒããå®è¡ãããªããããå¥ã®å Žæã§å®çŸ©ãããå€ã䜿çšãããŸãã ãã®åé¡ãåé¿ããã«ã¯ãåžžã«localãšããåèªã䜿çšããŠããã¹ãŠã®å€æ°ãæå°éã«èŠããããã«ããŠãã ããã ã°ããŒãã«å€æ°ã®äœ¿çšã¯åžžã«æå°éã«æããå¿ èŠããããŸãã
ããã«ãã¹ã³ãŒãã®äžé©åãªæ§æã®äŸã«åºãããããšãäœåºŠããããŸããããããã®å Žæã§ãã®ã»ã¯ã·ã§ã³ãå®æã§ããçç±ã匷調ããŸãã
ã¢ãžã¥ãŒã«ãšãããžã§ã¯ãçµç¹
ããã°ã©ã ã¢ãžã¥ãŒã«ã¯ãããã°ã©ã ã®æ©èœçã«å®å šãªãã©ã°ã¡ã³ãã§ããããœãŒã¹ã³ãŒããå«ãåå¥ã®ãã¡ã€ã«ãšããŠèšèšãããŠããŸãã ãåãã®ãšããã Corona SDKã®ãããžã§ã¯ãã®å®è¡ã¯main.luaãã¡ã€ã«ããå§ãŸããŸãã ã¢ããªã±ãŒã·ã§ã³å šäœã1ã€ã®ãã¡ã€ã«ã«èšè¿°ããå Žåãå€ãã®åé¡ãçºçããå¯èœæ§ããããŸããäŸãæããŸãã
- 倧éã®ã³ãŒãã ã»ãŒãã¹ãŠã®æ¬æ Œçãªã²ãŒã ã®ãœãŒã¹ã³ãŒãã«ã¯ãæ°çŸãæ°åãæ°äžãå Žåã«ãã£ãŠã¯10äžè¡ä»¥äžã®ã³ãŒããå«ãŸããããšããããŸãããã段éã§ãã¹ãŠã®ã³ãŒãã1ã€ã®ãã¡ã€ã«ã«é 眮ãããšããã®ãããžã§ã¯ããç¶æããã®ãéåžžã«é£ãããªããŸã
- ããããã®ã·ãŒã³ã ã»ãšãã©ã®å Žåãå®éã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯è€æ°ã®ã·ãŒã³ïŒ æ©èœç»é¢ ïŒãå«ãŸããŸããããšãã°ãããŸããŸãªã¡ãã¥ãŒãããŒãç»é¢ãè€æ°ã®æŠéã·ãŒã³ããªãŒãã³ã¯ãŒã«ãã·ãŒã³ãªã©ã§ãã ç¹°ãè¿ããŸããããã¹ãŠã1ã€ã®ãã¡ã€ã«ã«é 眮ããå Žåãã·ãŒã³ãåãæ¿ãããšãã«ã·ãŒã³ãäœæããã³åé€ããããã®å€æ°ã®æé ã§ã³ãŒããç©ã¿éããå¿ èŠããããŸãã ã³ãŒãã¯åã³éåžžã«è€éã«ãªããŸã
- ãŠãããŒãµã«ããŒã¿ãã«ã³ãŒãã ã¢ããªã±ãŒã·ã§ã³ã®äœæããã»ã¹ã§ã¯ãå€ãã®å Žåãã©ã€ãã©ãªã«è»¢éããã¿ã¹ã¯ãšåãã¿ã¹ã¯ãçºçãããããã®ã©ã€ãã©ãªã次ã®ãããžã§ã¯ãã«ç°¡åã«è»¢éã§ããŸããããã¹ãŠã1ã€ã®ãã¡ã€ã«ã«æžã蟌ããšãå®æããã©ã€ãã©ãªã®ç§»æ€æ§ã®åé¡ã¯éåžžã«å°é£ã«ãªããŸãã巚倧ãªãã¡ã€ã«ãããã©ã°ã¡ã³ããåé¢ããã®ã«ã©ãã ã䟿å©ãªã³ãŒããã
ãããžã§ã¯ããæŽçãããã¹ãŠã1ã€ã®main.luaãã¡ã€ã«ã«æžã蟌ãã®ãééã£ãŠããå Žåãä»ã®åé¡ãçºçããå¯èœæ§ããããŸãããã¬ãã¹ã³ã§ã¯ãããè¡ããããããžã§ã¯ãã«éžæããæ¹æ³ã瀺ããŸããããªãã®ãã®ãèãåºãã®ã¯ããªã次第ã§ãããç§ã¯ãã®æ¹æ³ã§ãããžã§ã¯ãã®ãããªãäŸãäœæããŸãã ãããã£ãŠããããžã§ã¯ããœãŒã¹ãããã€ãã®ãã¡ã€ã«ã«åå²ããå¿ èŠããããããã«ãããã®ãã¡ã€ã«ã«ã¯ããŸããŸãªç®çããããããã«åºã¥ããŠããã¡ã€ã«ã®åã¿ã€ãã«ã¯ååã®ãã¬ãã£ãã¯ã¹ã«ãã£ãŠæ±ºå®ãããç¬èªã®åœåé åºããããšããçµè«ã«éããŸããã ãã®æ¹æ³ã¯å人çã«ç§ã®ãã®ã§ãããç§ã¯ãããæåã ãšäž»åŒµããŠããŸããããç§ã®èšäºã§èŠãã²ãŒã ã®ãããªãäŸã¯ãããžã§ã¯ããèšèšããããã®ãã®ãããªã¡ã«ããºã ãæã£ãŠããã®ã§ãç§ã¯ãããåºç€ãšããããšã«ããŸããã 䟿å©ã«ãªãå¯èœæ§ã®ãããã¡ã€ã«ã®çš®é¡ã«ã€ããŠç°¡åã«èª¬æããŸãã
ã·ãŒã³
ã·ãŒã³-æ¥é èŸsc ãã¡ã€ã«åã®åœ¢åŒã¯scName.luaã§ãã ååã倧æåã§å§ãŸãããã¡ã€ã«ã®ç®çã決å®ããŸãã ä»ã®ã¿ã€ãã®å Žåããã®ã«ãŒã«ãé©çšãããããããã¬ãã£ãã¯ã¹ã®ã¿ãæå®ããŸãã ã·ãŒã³ãã¡ã€ã«ã®åœ¢åŒã¯ããªãå³å¯ã§ããã Corona SDKã©ã€ãã©ãª-composerã®èŠä»¶ã«ãã£ãŠæ±ºãŸããŸã ã ãããŸã§ã®ãšããããœãŒã¹ãã¡ã€ã«ãã³ãã¬ãŒããé©çšããããã«ããã®ã©ã€ãã©ãªãæ€èšããããã®å¥ã®ã¬ãã¹ã³ãè¡ããŸãã
local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- -- "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- -- ----------------------------------------------------------------------------------- -- function scene:create( event ) local sceneGroup = self.view -- , end -- function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- elseif ( phase == "did" ) then -- end end -- function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- elseif ( phase == "did" ) then -- end end -- () function scene:destroy( event ) local sceneGroup = self.view -- end -- ----------------------------------------------------------------------------------- -- -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
ã·ãŒã³ãã¡ã€ã«ã¯ãã³ã³ããŒã¶ã©ã€ãã©ãªã®äœ¿çšã®äžéšãšããŠäœæããããããã©ã®ãããªæ¹æ³ã§ããããžã§ã¯ãã«æ¥ç¶ããå¿ èŠã¯ãããŸããã
ãŠãããŒãµã«ã©ã€ãã©ãª
ãŠãããŒãµã«ã©ã€ãã©ãªã¯libãã¬ãã£ãã¯ã¹ã§ãã ãããã®ãã¡ã€ã«ã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªéšåã§åŸã§äœ¿çšã§ããæ¢è£œã®æ±çšé¢æ°ãé 眮ããå¿ èŠããããŸããããšãã°ããããžã§ã¯ãã®äžè§é¢æ°ãlibTriginom.luaãã¡ã€ã«ã«é 眮ãããšããããã®é¢æ°ã¯è£å ããã次ã®ãããžã§ã¯ãã§ã¯ãã¡ã€ã«ã転éããã ãã§ç°¡åã«äœ¿çšã§ããŸãæ¥ç¶ããããšã«ããã ãŠãããŒãµã«ã©ã€ãã©ãªã®ã¢ããªã±ãŒã·ã§ã³ã®ã°ã©ãã£ãã¯ãã¶ã€ã³èŠçŽ ãžã®ãã€ã³ããé¿ããåæå€ãåŒã³åºããã©ã¡ãŒã¿ãŒã«è»¢éããŠãã ããã ç°¡åãªã©ã€ãã©ãªã®äŸã瀺ããŸãã
--------------------- -- -- -- libTrigonom.lua -- --------------------- local M = {} -- a,b M.hypotenuse = function(a,b) --c = â(a²+b²) local c = math.sqrt(a*a + b*b) return c end -- M.line_len = function(x1,y1,x2,y2) --length = â((X2-X1)²+(Y2-Y1)²) local length = math.sqrt((x2 - x1)^2 + (y2 - y1)^2) return length end -- M. get_angle = function(x1,y1,x2,y2) return ((math.atan2(y1 - y2, x1 - x2) / (math.pi / 180)) + 270) % 360 end return M
main.luaã«æ¬¡ã®ã³ãŒããé 眮ããããšã«ããããã®ã©ã€ãã©ãªãæ¥ç¶ã§ããŸãã
Trigonom = require("libTrigonom")
ãããžã§ã¯ãã®ä»»æã®éšåã§é¢æ°ã䜿çšããäŸã瀺ããŸãã
local a,b = 3,4-- local c = Trigonom.hypotenuse(a,b) -- print(c)-->> 5 local x1,y1 = 34,-56 -- A local x2,y2 = -134,56 -- B local length = Trigonom.line_len(x1,y1,x2,y2) -- print(length)-->> 201.91087142598 local angle = Trigonom.get_angle(x1,y1,x2,y2) print(angle)-->> 236.30993247402
ãŠã£ãžã§ãã/ãµãŒãã¹
ãŠã£ãžã§ãã/ãµãŒãã¹-svcãã¬ãã£ãã¯ã¹ã ãŠã£ãžã§ããã¯ã©ã€ãã©ãªã«é¡äŒŒããŠããŸãããäž»ãªæ©èœã¯ã°ã©ãã£ã«ã«ã³ã³ããŒãã³ãã®äœæã«åºã¥ããŠããŸãã ãŠã£ãžã§ããã䜿çšãããšãè€åã€ã³ã¿ãŒãã§ãŒã¹ãäœæãããšäŸ¿å©ã§ãã scãã¡ã€ã«ã®ã¡ã€ã³ã³ãŒãã®äžéšãšããŠäœæãããã·ãŒã³ã®åºæ¬çãªéçã³ã³ããŒãã³ãããããéçã³ã³ããŒãã³ãã®äžã«ããããã¢ãããå¯åãã©ãŒã ããã®ä»ã®ã¢ã¡ããã£ã®åœ¢ã§åçãŠã£ãžã§ãããäœæã§ããŸãã ããšãã°ã次ã®ããã«ããã¹ãŠã®ãããžã§ã¯ããŠã£ãžã§ãããåäžã®ã€ã³ã¿ãŒãã§ã€ã¹ïŒ é¢æ°ã®æšæºã»ãã ïŒã§èšèšããã®ãæã䟿å©ã§ãã
- showïŒïŒ-ãŠã£ãžã§ããæ©èœãæã€ãŠã£ã³ããŠãäœæããç»é¢äžã®æå®ãããå Žæã«é 眮ããŸã
- refreshïŒïŒ-ãŠã£ãžã§ããã³ã³ããŒãã³ãã®ç¶æ ãæŽæ°ããŠãçŸåšã®ç¬éã«é¢é£ããããã«ããŸãã ããšãã°ããã®ãŠã£ãžã§ãããæèšã®å Žåã1ç§ãŸãã¯1åã«1åæŽæ°ããå¿ èŠããããŸãïŒç§éããªãå ŽåïŒã
- hideïŒïŒ-ãŠã£ãžã§ããã€ã³ã¿ãŒãã§ã€ã¹å šäœãé衚瀺ãŸãã¯åé€ããŸã
ç°ãªããŠã£ãžã§ããã«åãã¡ãœããïŒ é¢æ° ïŒåããããšãããªã¹ã¯ã¯ãªãããšã«æ³šæãã䟡å€ããããŸã-ãŠã£ãžã§ããåãè¿œå ããããã«å¿ èŠãªé¢æ°ã«ã¢ã¯ã»ã¹ããããã«è¡šç€º/æŽæ°/éè¡šç€ºïŒ ã©ã€ãã©ãªã®å Žåã®ããã« ïŒããã®ããåå空éã¯ã°ããŒãã«ã§ãè©°ãŸãããšã¯ãããŸããã
ãŠã£ãžã§ããïŒ clock ïŒã®äŸã瀺ããŸãã
------------------------- -- -- ------------------------- M = { GR = {}, -- GUI = {},-- } -- M.get_timezone = function() return os.difftime(os.time(), os.time(os.date("!*t", os.time()))) / 3600 end -- id M.refresh = function(id) local cur = M.GUI[id].capt local tm = os.date("!*t", os.time() + 3600*cur.GTM) -- 0 10 local norn_dig = function(n) return n < 10 and '0'..n or n end local sec = cur.is_sec and ":"..norn_dig(tm.sec) or '' cur.text = norn_dig(tm.hour)..':' .. norn_dig(tm.min) .. sec end -- , id --( ): -- x - x ( x) -- y - y ( y) -- is_sec - ( - true) -- GTM - , M.show = function(p) -- p = p and p or {} px = px and px or _W * .5 py = py and py or _H * .5 if p.is_sec == nil then p.is_sec = true end if p.GTM == nil then p.GTM = M.get_timezone() end -- local id = #M.GR + 1 M.GR[id] = display.newGroup()-- M.GUI[id] = {}-- -- - M.GUI[id].bg = display.newRoundedRect(M.GR[id], px, py, _W * .33, _H * .08, _H * .02) M.GUI[id].bg.strokeWidth = _H * .005-- M.GUI[id].bg:setStrokeColor(0,1,.5)-- M.GUI[id].bg:setFillColor(1,.5,0)-- -- M.GUI[id].bg:addEventListener('touch',function(event) if event.phase == 'began' then M.hide(id) end end) -- M.GUI[id].capt = display.newText(M.GR[id], '', px, py, nil, _H * .05) M.GUI[id].capt:setFillColor(0) M.GUI[id].capt.GTM = p.GTM M.GUI[id].capt.is_sec = p.is_sec M.refresh(id) -- timer.performWithDelay( 500, function(event) if not M.GUI[id].capt.text then timer.cancel( event.source ) else M.refresh(id) end end, 0 ) end -- id id M.hide = function(id) if id then display.remove(M.GR[id]) else for i = 1,#M.GR do display.remove(M.GR[i]) end end end return M
ãµãŒãã¹ãæ¥ç¶ããŠäœ¿çšããæé ã¯æ¬¡ã®ãšããã§ãã
_W = display.contentWidth _H = display.contentHeight Clock = require "svcClock" Clock.show()
ãµãŒãã¹ãšã©ã€ãã©ãªã¯ãåå©çšã®åè£ã§ããããããéåžžã«æ±çšçã«ããå¿ èŠããããŸããã»ãšãã©ã®ãã©ã¡ãŒã¿ïŒ çæ³çãªå Žåã¯ãã¹ãŠ ïŒããªãã·ã§ã³ã«ããå¿ èŠããããŸãã ããã©ã«ãå€ã§ã
ããŒã¿ããŒã¹
ããŒã¿ããŒã¹-dbãã¬ãã£ãã¯ã¹ã ãããã®ãã¡ã€ã«ã«ã¯é¢æ°ã¯å«ãŸããŠããŸãããããŠãããã®ç¹æ§ãªã©ãã·ã¹ãã ãªããžã§ã¯ãã®éçèšå®ã«é¢ããæ å ±ãä¿åãããŠããŸãã ãŠãããèšå®ãå«ãããŒã¿ããŒã¹ã®äŸã瀺ããŸãã
return { peasant = { title = {ru = '', en = 'Peasant'}, force = 1, defence = 2, speed = 1, }, spearman = { title = {ru = '', en = 'Spearman'}, force = 3, defence = 2, speed = 2, }, archer = { title = {ru = '', en = 'Archer'}, force = 5, defence = 1, speed = 3, }, knight = { title = {ru = '', en = 'Knight'}, force = 7, defence = 3, speed = 4, }, }
倧èŠæš¡ãªããŒã¿ããŒã¹ã®åæ§ã®ã¿ã€ãã®å®è£ ã¯ããã®ãããªå®è£ ã§ç°¡åã«çœ®ãæããããšãã§ããããšã«æ³šæããŠãã ãã
local M = { name = {'peasant','spearman','archer','knight'}, title = { {ru = '', en = 'Peasant'}, {ru = '', en = 'Spearman'}, {ru = '', en = 'Archer'}, {ru = '', en = 'Knight'}, }, stats = { {force = 1, defence = 2, speed = 1,}, {force = 3, defence = 2, speed = 2,}, {force = 5, defence = 1, speed = 3,}, {force = 7, defence = 3, speed = 4,}, }, M.res = {}, } for i = 1,#M.name do M.res[M.name[i]] = { title = M.title[i] force = M.stats[i].force, defence = M.stats[i].defence, speed = M.stats[i].speed, } end return M.res
å®éãããã¯ãŸã£ããåãã§ããæåã®å Žåã¯ãã¹ãŠãããã«åæåããã2çªç®ã®å Žåã¯ã©ã€ãã©ãªãæ¥ç¶ããããšãµã€ã¯ã«ãå®è¡ããããŸã£ããåãããŒãã«ããã£ã±ãã«ãªããŸãã2çªç®ã®æ¹æ³ã¯ãæåã«ãã®ããŒã¿ããã䟿å©ã«ç·šéã§ãããããããæ®éçã§ã倧éã®ããŒã¿ãèšé²ãå€§å¹ ã«åæžã§ããå Žåã æ¥ç¶ããã«ã¯ã次ã®ãããªããŒã¿ããŒã¹ã䜿çšããŸãã
units = require('dbUnits') print(units.archer.title.ru)--
ã³ãŒãæ¿å ¥
ã³ãŒãã®æ¿å ¥ã¯ãã¬ãã£ãã¯ã¹insã§ãã ãã¡ã€ã«ã®ãµã€ãºãã©ã®ããã«åæžããããšããŠãããããåžžã«å¯èœã§ãããšã¯éããŸãã;ãã®å Žåãå ±éã®ç®æšã«ãã£ãŠçµåãããäžéšã®ã»ã¯ã·ã§ã³ãå¥ã®ãã¡ã€ã«ã«åãåºãããšãã§ããŸãã äŸããããŸãããã³ãŒãããããŸãïŒ
--main.lua local P = '123' k = 23.2 local function sum(a,b) return a+b end local function razn(a,b) return ab end local a,b = 2,3 print(sum(a,b)) print(razn(b,a))
ããã§ãsumãšrazné¢æ°ãå¥ã®ãã¡ã€ã«InsExample.luaã«åãåºããŸãã2ã€ã®ãã¡ã€ã«ããããŸãã
-- InsExample.lua function sum(a,b) return a+b end function razn(a,b) return ab end --main.lua local P = '123' k = 23.2 require 'insExample' local a,b = 2,3 print(sum(a,b)) print(razn(b,a))
å¥ã®ãã¡ã€ã«ã«è»¢éãããšããé¢æ°ãã°ããŒãã«ã«ããïŒ ããŒã«ã«ãåé€ãã ïŒããšã«æ³šæããŠãã ãããããããªããšãé¢æ°ã¯main.luaã®ç¯å²å€ã«ãªããŸãã ãŸããinsExample.luaãã¡ã€ã«å ã§ã¯ããŒã«ã«å€æ°Pã¯è¡šç€ºãããŸããããã°ããŒãã«å€æ°kã¯è¡šç€ºãããrequireã®åŸã«å€æ°kã宣èšãããšè¡šç€ºãããªããªããŸãã
éèŠ ïŒ ãããããŠãŒã¹ã±ãŒã¹ã§ããã¡ã€ã«æäœãå¿ èŠã§ãããã®åŒã³åºãã¯ãå®è¡ã¹ã¬ããããã®ã³ãŒãã»ã¯ã·ã§ã³ãåããŠééãããšãã«1åã ãè¡ãããŸããããã¯ãé·ãéè€éãªãã°ã«æ©ãŸãããªãå Žåã¯ãåžžã«èæ ®ã«å ¥ããå¿ èŠããããŸãã ãŸããç§ã®ããã«ãdb / lib / svcã®ãããªã¢ãžã¥ãŒã«ã§ãæ»ãåã«ç¹å®ã®Må€æ°ã䜿çšããŠããŒã¿ãåéããå ŽåïŒ ãŸãã¯ãã®ä» ïŒããã®å€æ°ãããŒã«ã«ã«ããããšãå¿ããªãã§ãã ãããããããªããšãå次ã®èŠæ±ãåã®çµæãäžæžãããããã«ãããããã«è€éãªãšã©ãŒãçºçããŸãã
æ¡ä»¶æ
Luaã®ä»ã®ã»ãšãã©ã®èšèªãšåæ§ã«ãæ¡ä»¶ä»ãã³ãŒãåå²æäœãäœæããããšãã§ããŸãããã®ç®çã®ããã«ãããã€ãã®ã¿ã€ãã®ifã¹ããŒãã¡ã³ãã䜿çšãããããªã䟿å©ãª3é åå²æ¹æ³ã䜿çšãããŸãã
æ¯èŒæŒç®åã
ããŒã¿ãæ¯èŒããã«ã¯ãæ¯èŒæŒç®ã䜿çšãããŸãã ãã®ãããªåæäœã¯2ã€ã®å€æ°ã§æ§æããããã®éã«æ¯èŒæŒç®åããããLuaã«ã¯6ã€ã®å€æ°ããããŸãã
- ==çãã
- ã=çãããªã
- <å°ãªã
- >ãã£ãš
- <=ããå°ãããçãã
- > =以äž
å®éãæ¯èŒæŒç®ã®çµæã¯falseãŸãã¯trueïŒ falseãŸãã¯true ïŒã§ããããããã®å€ã¯åïŒããŒã«ïŒã®ç¹æ§ã§ãããä»ã®åãšãšãã«ä»¥äžã§èª¬æããŸãã 次ã«ãæ¯èŒæŒç®ãé©çšãããèšèªæ§æèŠçŽ ãæ€èšããŸãã
IFã¹ããŒãã¡ã³ã
ããšãã°ãaãbãã倧ããå Žåãtrueã«èšå®ããŸã
if a > b then c = true end
ã芧ã®ãšãããã¢ããªã±ãŒã·ã§ã³ã¯éåžžã«ã·ã³ãã«ã§ãããããããã€ãã®ããã«åŸ®åŠãªç¹ããããŸã-ifãããã¯ã®å 容ã¯æäœãããã¯ã§ããããŒã«ã«ã®å¯èŠæ§å¶éã®ç¯å²ãããªãã¡ å€æ°cãããŒã«ã«ã«ãããšãçµäºåŸã«è¡šç€ºãããªããªããŸãããã¡ãããifãããã¯ã®åŸãã«è¡šç€ºãããããŒã«ã«å€æ°cãå¿ èŠãªå Žåã¯ãifã®åã«å®£èšããå¿ èŠããããŸãã
local c = false fa > b then c = true end
äžã§èšã£ãããã«ãåå²ãç·šæãã3ã€ã®æ¹æ³ããããäžèšã®ã³ãŒãã¯ãã®æ¹æ³ã§ç°¡åã«æžãããšãã§ããŸãã
local c = a > b
ããã¯ãšãŠãç°¡åã§ã:)ããŠãifã§ããè€éãªæ¡ä»¶ãäœãæ¹æ³ã«é¢ããããã€ãã®èšèãè«çæŒç®åãšïŒååšãããšïŒãããã³ãŸãã¯ïŒãŸãã¯ïŒããããã¯ç¬èªã®ç¹æ§ãæã£ãŠããŸãããã»ãšãã©ã®èšèªãšã»ãŒåãããã«æ©èœããŸãã
ãããŠ
andæŒç®åã«ãã£ãŠçµåãããæ¡ä»¶ãæºããããŠããå¿ èŠããããŸã;æ¡ä»¶ã¯å·Šããå³ã«æºããããŠããŸã;ãã§ãã¯äžã«1ã€ã®æ¡ä»¶ãæºããããªãå Žåã次ã®ãã§ãã¯ã¯å®è¡ãããŸãããããã¯éåžžã«éèŠãªãã€ã³ãã§ãããèªåã®ç®çã®äž¡æ¹ã§äœ¿çšã§ãããã®æ©èœã®ããã«å€ãã®è€éãªãã°ããããããæ確ã«ç解ããå¿ èŠããããŸããæçšãªäœ¿çšäŸã瀺ããŸããä»ã®ãªããžã§ã¯ããžã®æè³ã®3çªç®ã®æ·±ãã«ãããªããžã§ã¯ãããããŸãããŸãããã®ååšã確èªãããobj1.obj2.obj3ãšããæåã®ãã¥ãŒã§ã¯ãããè¡ãããšãã§ããŸãã
if obj1.obj2.obj3 then c = true end
ããã¯è¯ãèãã®ããã«æãããããããŸããããå®éã¯ããã§ã¯ãããŸãããobj1ãŸãã¯obj2ãªããžã§ã¯ããååšããªããšããŸãããããã®å Žåããšã©ãŒãçºçããŸããæ€èšŒã¯æ¬¡ã®ããã«è¡ãå¿ èŠããããŸãã
if obj1 and obj1.obj2 and obj1.obj2.obj3 then = true end
ããã§ããã§ãã¯ã¯ãšã©ãŒãªãã§å®å šã«å®è¡ãããŸããäžé æŒç®åã«ãã£ãŠå®è£ ãããå Žåã®ããªãé¡äŒŒããã¡ã«ããºã
local c = obj1 and obj1.obj2 and obj1.obj2.obj3 and true
ãŸãã¯
å°ãªããšã1ã€ã®æ¡ä»¶ãæºãããããªãã¬ãŒã¿ãŒã«ãã£ãŠåé¢ãããŠããå ŽåããŸãã¯ãããªãæ€èšŒãåæ¢ãããŠããå Žåãæ¡ä»¶ã¯çã§ãããšèŠãªãããŸãã ããªãã¡ãã®æŒç®åã¯ãandãšåæ§ã®ååã«åºã¥ããŠåäœããŸãããä»ã®èŠä»¶ãããå Žåããããã¯çµ¶å¯Ÿçã§ããããããŸãã¯æå°ã§ããoræŒç®åã䜿çšããäžè¬çãªæ¯èŒã®äŸã瀺ããŸãã
if a>b or c>b or k<0 then c = true end
äžå å®è£ ã¯å®å šã«é¡äŒŒããŠããŸãïŒ
local c = a>b or c>b or k<0
ãªã
åŠå®ã®è«çæŒç®ãããããåã«æ¡ä»¶ãæç«ããªãããšã¯ãéã«ç解ãããŸããa> bã®å Žåãããã¯aãbããã倧ãããšè§£éãããa> bã§ã¯ãªãaãbããã倧ãããªããšè§£éãããŸãã
ä»ã®å Žå
å€ãã®å Žåã次ã®ã¿ã€ãã®åå²ãå¿ èŠã§ããæ¡ä»¶ãæºããããå Žåãã¢ã¯ã·ã§ã³ãå®è¡ããŸãããã以å€ã®å Žåã¯ãå¥ã®ã¢ã¯ã·ã§ã³ãå®è¡ããŸããããã¯if elseã¹ããŒãã¡ã³ãã«ãã£ãŠå®è£ ãããå®è£ ã¯æ¬¡ã®ãšããã§ãã
if a>b then c= true else c =false end
ã芧ã®ãšãããè€éãªããšã¯äœããããŸããããã®äŸã®3é å®è£ ã«ã¯ãANDæŒç®åãšORæŒç®åã®äž¡æ¹ãå«ãŸããŸãã
local c = a>b and true or false
IF ELSEIF ELSE
æ¡ä»¶ã«ã¯ãã1ã€ã®ããªã¢ã³ãããããŸããæ¡ä»¶1ãæºããããå Žåãã¢ã¯ã·ã§ã³1ãæ¡ä»¶2ãè¡ãããå Žå-act2 ...æ¡ä»¶Nãè¡ãããå Žå-actionNãããã§ãªãå Žåã¯actionXãå€ãã®èšèªã§ã¯ããã®ã¿ã€ãã®åå²ã¯ãã¹ã€ããã®ãããªè€æ°ã®åå²ã®ç¹å¥ãªæŒç®åã«ãã£ãŠå®è£ ãããŸããLuaã§ã¯ãããã«ã¯ç¬èªã®æ¹æ³ããããŸããã
if a>b or d<b then k = 1 elseif b>c and a<b then k = 2 elseif c>d then k = 3 else k = 0 end
ã芧ã®ãšããããã¹ãŠãã·ã³ãã«ã§ããè€åIF ELSEIF ELSEã¹ããŒãã¡ã³ãã®å®è¡é åºã«ã¯ããã€ãã®ç¹æ§ããããŸãã1ã€ç®ã¯ãªãã·ã§ã³ã§ããã2ã€ç®ã¯ãæ¡ä»¶ã®æåã®çºçãçºçããå Žåããããªããã§ãã¯ã¯å®è¡ããããçµäºçµäºåŸã®è¡ãžã®ç§»è¡ããããŸããè€åã¹ããŒãã¡ã³ãããã®æ©æçµäºã¯åé¡ã§ã¯ãªãããšã©ãŒãåŒãèµ·ããããšã¯ãªãããã«æãããããããŸããããããã§ã¯ãããŸããããã®ååã誀解ãããšäºæ³å€ã®çµæãçããå¯èœæ§ãããããšã瀺ãäŸã瀺ããŸãã
k = 1 if k > 0 then k = 2 print(k) elseif k > 1 then k = 3 print(k) end
ãã®ã¢ã¯ã·ã§ã³ã®çµæã¯ã1å°å·-> 2ã®ã¿ã«ãªããŸããçµè«ãšããŠãIF ELSEIF ELSEãäžé æŒç®åãšãšãã«äœ¿çšããæåã®äŸãå®è£ ããæ¹æ³ã瀺ããŸãã
local k = (a>b or d<b) and 1 or (b>c and a<b) and 2 or c>d and 3 or 0
ãã®çç±ããããŸãã¯åã«ãã®æ©èœã«åºã¥ããŠããŸãã¯ãããããé«ãåªå 床ãæã£ãŠããããšã«æ³šæããŠãã ããã
éèŠïŒãã®ç« ã§ã¯ãäžé ä»£å ¥ã䜿çšããæ¹æ³ã瀺ããŸãããã³ãŒããæŽçããéåžžã«é åçã§ç°¡åãªæ¹æ³ã®ããã«æãããŸãããã®ã¡ã«ããºã ã®äœ¿çšæé ã«ã€ããŠå°ã説æããŸãããŸããã³ãŒããå®è¡ã§ããªãå Žåã«ã®ã¿äžé æŒç®åã䜿çšããŸãå¯èªæ§ãäœãã2çªç®ã«ããã®ã¡ãœããã䜿çšããæåã«ããããã®è¡ãæ éã«ãããã°ããŸããæåã«æ£ããæžã蟌ãããšãåžžã«å¯èœã§ãããšã¯éããªãããã§ãã
èšäºã®ç¶ãïŒããŒã2/3ïŒ