Skip to content

lmmgh-ai/Love2D-grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

网格背景绘制库 (Love2D)

描述:

本身断断续续使用Love2d几年了,一直毫无章序写代码,今日突发奇想把一些库整理起来以备后用!!

本库为后续开发[节点编辑器,工作流编辑器]提供无依赖便携库支持....

平台相关

平台兼容性验证 版本love11.5:

  • **Windows **
  • Linux
  • MocOS
  • Web
  • Android

功能:

  1. X/Y坐标轴可分别设置颜色,其他轴线共用一个颜色
  2. 可设置网格原点坐标
  3. 支持缩放(滚轮缩放),支持拖动
  4. 提供接口绘制坐标轴上的数值
  5. 无限网格技术(只绘制视口内网格),性能优化,缩放自动更新
  6. 动态绘制网格,文字与线条粗细随缩放保持一致,线条稠密度随缩放保持一致

参数:

 -- 坐标轴颜色
  self.axis_color_x 
  self.axis_color_y 
  self.grid_color 

  -- 原点坐标(以屏幕像素为单位)
  self.origin_x 
  self.origin_y 

  -- 网格间隔(单位长度,像素)
  self.grid_spacing 

  -- 缩放比例
  self.scale

  -- 拖动相关
  self.is_dragging 
  self.drag_start_x 
  self.drag_start_y 
  self.origin_drag_start_x
  self.origin_drag_start_y 

  -- 缩放最小/最大
  self.scale_min =  0.1
  self.scale_max =  10

  -- 视口
  self.viewport_w = love.graphics.getWidth()
  self.viewport_h = love.graphics.getHeight()

  -- 坐标数值字体
  self.font = love.graphics.newFont(13)

函数:

Grid:setAxisColor(x_color, y_color)-- 设置坐标轴颜色
Grid:setGridColor(color)-- 设置其他网格线颜色
Grid:setOrigin(x, y)-- 设置原点坐标
Grid:setScale(scale)-- 设置缩放
Grid:wheelmoved(dx, dy)-- 鼠标滚轮缩放函数
grid:mousepressed(x, y, button)
grid:mousereleased(x, y, button)
grid:mousemoved(x, y, dx, dy)
grid:wheelmoved(dx, dy)
Grid:getValueAtScreen(x, y)-- 获取屏幕坐标对应的网格坐标
Grid:getScreenAtValue(gx, gy)-- 获取网格坐标对应屏幕坐标

必要回调:

grid:update(dt)--处理动态变化
grid:draw()

可重写回调:

Grid:axis_value_formatter(v)--绘制坐标轴数值参数 描述不好写更改试一下吧!!!!!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages