Przeglądaj źródła

Added dynamic atlas and texture creation (#324)

* update physics

* update input

* update

* update code sharing in getting-help.md

* Export Compliance

* update on file i/o

* pi / 4

* inputs

* forum url

* read only user

* html5 gamepad

* sdk api update

* update

* image properties

* update editor

* defold sdk update

* animation updates

* animation fix

* run as admin

* update bob

* update about AndroidX support

* software render

* linux-faq.md update

* 4.28.2021 updates

* Basis Universal format

* sound & mesh

* gamepad event mapping

* admob url

* Minor edit to building blocks intro text

* update gamepad & ios

* project settings

* libffi version

* scaling

* image compression

* update gamepads

* increase memory

* caching assets

* update 2021/10/6

* update 2021/10/16
blend-modes.md

* update 2021/11/12

* allow dynamic transforms update

* Bundle update

* update faq

* bullet & bob

* script properties update

* editor-styling

* build server url

* editor templates

* spine extension update

* Fix typo in the "optimizations" word in Chinese docs

* Update to material.md - Constants buffers

* Verify Graphics Calls

* H5 parameters

* OpenJDK downloads

* cn update corresponds to [pull 259](https://github.com/defold/doc/pull/259)

* application security

* porting guidelines

* update for 8f1651f

* cn update for 094bf6f

* cn update for 20fdfc5 & 6263317

* cn update for 7/19/2022

* title

* profiling update

* update editor.md

* update bob.md

* update shortcuts

* update fixed update note

* Update properties.md

* Update material.md

* Updates links

* Update bob help with the latest info

* camera & renderer

* Updated android keystore info zh_cn

* bundling.md release vs debug zh_cn

* update bob.md & gui-clipping.md

* contentless bundle

* consoles update

* model animation link

* gamepad & faq

* remove a camera lib

* font shadow render mode fix

* updates about app-manifest and others

* Update script.md

* includes in shaders

* editor scripts

* material updates

* Added dynamic atlas and texture creation

* fixes for atlas and some others
COCO 2 lat temu
rodzic
commit
201402bd9e

+ 89 - 0
docs/zh/manuals/atlas.md

@@ -114,3 +114,92 @@ Playback
   - `Loop Forward` 从第一张图片到最后一张图片循环播放.
   - `Loop Backward` 从最后一张图片到第一张图片循环播放.
   - `Loop Ping Pong` 从第一张图片播放到最后一张图片再反向循环播放.
+
+## 运行时纹理及图集建立
+
+自从 Defold 1.4.2 版本, 可以在运行时创建纹理和图集.
+
+### 在运行时创建纹理资源
+
+使用 [`resource.create_texture(path, params)`](https://defold.com/ref/stable/resource/#resource.create_texture:path-table) 创建纹理资源:
+
+```lua
+  local params = {
+    width  = 128,
+    height = 128,
+    type   = resource.TEXTURE_TYPE_2D,
+    format = resource.TEXTURE_FORMAT_RGBA,
+  }
+  local my_texture_id = resource.create_texture("/my_custom_texture.texturec", params)
+```
+
+纹理创建好之后就可以用 [`resource.set_texture(path, params, buffer)`](https://defold.com/ref/stable/resource/#resource.set_texture:path-table-buffer) 设置纹理的像素:
+
+```lua
+  local width = 128
+  local height = 128
+  local buf = buffer.create(width * height, { { name=hash("rgba"), type=buffer.VALUE_TYPE_UINT8, count=4 } } )
+  local stream = buffer.get_stream(buf, hash("rgba"))
+  for y=1, height do
+      for x=1, width do
+          local index = (y-1) * width * 4 + (x-1) * 4 + 1
+          stream[index + 0] = 0xff
+          stream[index + 1] = 0x80
+          stream[index + 2] = 0x10
+          stream[index + 3] = 0xFF
+      end
+  end
+  local params = { width=width, height=height, x=0, y=0, type=resource.TEXTURE_TYPE_2D, format=resource.TEXTURE_FORMAT_RGBA, num_mip_maps=1 }
+  resource.set_texture(my_texture_id, params, buf)
+```
+
+::: sidenote
+可以使用 `resource.set_texture()` 更新局部纹理, 方法是设置 buffer 的 width 和 height 小于纹理完整尺寸, 然后指定 `resource.set_texture()` 的 x 和 y 参数.
+:::
+
+纹理可以用 `go.set()` 直接应用于 [模型组件](/manuals/model/) 上:
+
+```lua
+  go.set("#model", "texture0", my_texture_id)
+```
+
+### 运行时创建图集
+
+如果纹理要用在 [sprite 组件](/manuals/sprite/) 上, 要先转换成图集. 使用 [`resource.create_atlas(path, params)`](https://defold.com/ref/stable/resource/#resource.create_atlas:path-table) 创建图集:
+
+```lua
+  local params = {
+    texture = texture_id,
+    animations = {
+      {
+        id          = "my_animation",
+        width       = width,
+        height      = height,
+        frame_start = 1,
+        frame_end   = 2,
+      }
+    },
+    geometries = {
+      {
+        vertices  = {
+          0,     0,
+          0,     height,
+          width, height,
+          width, 0
+        },
+        uvs = {
+          0,     0,
+          0,     height,
+          width, height,
+          width, 0
+        },
+        indices = {0,1,2,0,2,3}
+      }
+    }
+  }
+  local my_atlas_id = resource.create_atlas("/my_atlas.texturesetc", params)
+  -- 给当前游戏对象上的 'sprite' 组件指定图集
+  go.set("#sprite", "image", my_atlas_id)
+  -- 播放 "逐帧动画"
+  sprite.play_flipbook("#sprite", "my_animation")
+```

+ 1 - 1
docs/zh/manuals/collection-proxy.md

@@ -174,7 +174,7 @@ DEBUG:SCRIPT: update() with timestep (dt) 0.016666667535901
 
 `update()` 仍然是每秒调用 60 次, 但是 `dt` 值变了. 可以看到只有 1/5 (0.2) 的 `update()` 调用包含 1/60 秒的 `dt` 参数, 其他都是 0. 物理模拟也基于 dt 每 5 帧步进一次.
 
-:::注意
+::: sidenote
 可以使用集合的时间步功能来暂停游戏, 例如弹出窗口或者游戏窗口失去焦点时, 使用 `msg.post("#myproxy", "set_time_step", {factor = 0, mode = 0})` 暂停游戏, 然后使用 `msg.post("#myproxy", "set_time_step", {factor = 1, mode = 1})` 继续游戏.
 :::
 

+ 1 - 1
docs/zh/manuals/extensions-script-api.md

@@ -42,7 +42,7 @@ Defold 编辑器为所有 Defold API 功能以及用户引用的Lua模块提供
 ```
 
 数据类型有 `table, string , boolean, number, function` 几种. 如果一个值有多个类型则这样写 `[type1, type2, type3]`.
-:::注意
+::: sidenote
 目前编辑器里不显示类型. 但是还是鼓励输入类型以便以后编辑器可以显示出来.
 :::
 

+ 2 - 2
docs/zh/manuals/shader.md

@@ -98,7 +98,7 @@ Varying 变量
 Defold 中的 shader 支持引入项目文件内以 `.glsl` 为扩展名的着色器代码. 要将 glsl 代码引入 shader, 请使用 `#include` 关键字后跟双引号或小括号. 引入的文件要么是基于项目的相对路径, 要么是基于引入文件的相对路径:
 
 ```glsl
-// 需要引入代码的文件 /main/my-shader.fs
+// 需要引入代码的文件 /main/my-shader.fp
 
 // 完整路径
 #include "/main/my-snippet.glsl"
@@ -153,7 +153,7 @@ const float PI = 3.14159265359;
 // In red-color.glsl
 vec3 my_red_color = vec3(1.0, 0.0, 0.0);
 
-// In my-shader.fs
+// In my-shader.fp
 vec3 get_red_color()
 {
   #include "red-color.glsl"