zoukankan      html  css  js  c++  java
  • LOVE2D-03-完整的LOVE2D程序

    一个完整的love2d源码包含2个基本的lua文件

    main.lua  和  conf.lua

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

    conf.lua主要是对游戏程序的不必要的一些其他管理,如窗口大小,窗口标题,是否全屏,鼠标样式等等

    man.lua主要是整个游戏的灵魂文件,所有资源的加载定义都必须在这个文件中完成,当然,也可以调用外部lua文件,和其他的文件。

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

    conf.lua会被首先执行,

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

    conf.lua 常用配置

    function love.conf(win)
    
    --设置标题和窗口大小
    win.title = "My Love APP" 
    win.screen.width = 800
    win.screen.height = 600
    
    end
    

    conf.lua 默认配置项

      使用conf.lua主要是管理游戏加载时的一些加载资源的管理

    其中最主要的时conf.lua用来管理模块的加载与禁用,以提升游戏的加载速度,如:

    function love.conf(win)
    win.title = "Untitled" -- The title of the window the game is in (string)
    win.author = "Unnamed" -- The author of the game (string)
    win.url = nil -- The website of the game (string)
    win.identity = nil -- The name of the save directory (string)
    win.version = "0.8.0" -- The LÖVE version this game was made for (string)
    win.console = false -- Attach a console (boolean, Windows only)
    win.release = false -- Enable release mode (boolean)
    win.screen.width = 800 -- The window width (number)
    win.screen.height = 600 -- The window height (number)
    win.screen.fullscreen = false -- Enable fullscreen (boolean)
    win.screen.vsync = true -- Enable vertical sync (boolean)
    win.screen.fsaa = 0 -- The number of FSAA-buffers (number)
    win.modules.joystick = true -- Enable the joystick module (boolean)
    win.modules.audio = true -- Enable the audio module (boolean)
    win.modules.keyboard = true -- Enable the keyboard module (boolean)
    win.modules.event = true -- Enable the event module (boolean)
    win.modules.image = true -- Enable the image module (boolean)
    win.modules.graphics = true -- Enable the graphics module (boolean)
    win.modules.timer = true -- Enable the timer module (boolean)
    win.modules.mouse = true -- Enable the mouse module (boolean)
    win.modules.sound = true -- Enable the sound module (boolean)
    win.modules.physics = true -- Enable the physics module (boolean)
    end
    

      但是绝不能禁止love.filesystem模块和love模块,如果禁止,在main.lua中就无法用love进行函数回调或调用,love.filesystem则是提供一个接口给用户的文件系统。

     

     main.lua常用函数

    function love.load() --资源加载回调函数,仅初始化时调用一次
    
    end
    
    function love.draw() --绘图回调函数,每周期调用
    
    end
    
    function love.update(dt) --更新回调函数,每周期调用
    
    end
    
    function love.keypressed(key) --键盘检测回调函数,当键盘事件触发是调用
    
    
    end

     main.lua所有回调函数

    love.draw    
    love.focus    
    love.joystickpressed    
    love.joystickreleased    
    love.keypressed    
    love.keyreleased   
    love.load    
    love.mousepressed   
    love.mousereleased    
    love.quit   
    love.run  
    love.update  
    

      在以后将专门开设一篇文章来专门进行解释love2D中的所有函数

  • 相关阅读:
    素数路径Prime Path POJ3126 素数,BFS
    Fliptile POJ3279 DFS
    Find the Multiple POJ1426
    洗牌Shuffle'm Up POJ3087 模拟
    棋盘问题 POJ1321 DFS
    抓住那只牛!Catch That Cow POJ3278 BFS
    Dungeon Master POJ2251 三维BFS
    Splitting into digits CodeForce#1104A
    Ubuntu下手动安装Nvidia显卡驱动
    最大连续子序列和
  • 原文地址:https://www.cnblogs.com/releed/p/6350146.html
Copyright © 2011-2022 走看看