Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Lerg/extension-nativetext
Native Text Rendering extension for Defold.
https://github.com/Lerg/extension-nativetext
Last synced: 4 months ago
JSON representation
Native Text Rendering extension for Defold.
- Host: GitHub
- URL: https://github.com/Lerg/extension-nativetext
- Owner: Lerg
- License: mit
- Created: 2019-09-24T13:01:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T20:58:39.000Z (about 1 year ago)
- Last Synced: 2023-12-14T21:41:59.548Z (about 1 year ago)
- Language: Objective-C++
- Size: 261 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-defold - NativeText
README
# extension-nativetext
Native Text Rendering extension for Defold.
This extension renders text into an image resource, that can be applied as a texture.
Supported platforms: macOS, iOS, Android.
# Project Settings
Add this URL to the dependencies section in `game.project`.
- `https://github.com/Lerg/extension-nativetext/archive/master.zip`
# API reference
## nativetext.init(params)
Optionally call this function to set maximum texture size to be allowed to generate.
### `params` reference
- `max_texture_width`, number. Maximum texture width.
- `max_texture_height`, number. Maximum texture height.## nativetext.new(params)
Generate an image resource with rendered text.
### `params` reference
- `text`, string. Text.
- `width`, number. Maximum width to fit the text in. Height is restricted by maximum texture height. Optional.
- `size`, number. Font size. Optional.
- `underline`, boolean. Set to `true` for underlined text. Optional.
- `spacing_add`, number. Add distance between lines. Optional.
- `align`, number. Text alignment. See below. Optional.
- `color`, vector4. Text color. Optional.
- `outline_size`, number. Outline size. Optional.
- `outline_color`, vector4. Outline color. Optional.
- `shadow_size`, number. Shadow size. Optional.
- `shadow_x`, number. Shadow x offset. Optional.
- `shadow_y`, number. Shadow y offset. Optional.
- `shadow_color`, vector4. Shadow color. Optional.
- `background_color`, vector4. Background color. Optional.## Text alignment
### nativetext.align_normal
Normal alignment.### nativetext.align_left
Left alignment.### nativetext.align_right
Right alignment.### nativetext.align_center
Center alignment.### nativetext.align_justified
Justified alignment. iOS/macOS only.### Syntax
```language-lua
-- Set maximum allowed texture size.
nativetext.init{
max_texture_width = 2048,
max_texture_height = 2048
}-- Generate text image.
local image_resource = nativetext.new{
text = 'This is a test ど러연关\nыыыьщюш\nตตต ตัตัตั ตั้ตั้ตั้',
width = 250,
size = 30,
spacing_add = 50,
align = nativetext.align_center,
color = vmath.vector4(0, 1, 1, 1),
outline_size = 8,
outline_color = vmath.vector4(0.9, 0.1, 0.1, 1),
shadow_size = 8,
shadow_x = 8, shadow_y = -8,
shadow_color = vmath.vector4(0, 0, 0, 1),
background_color = vmath.vector4(0.1, 0.2, 0.8, 1)
}-- Resize game object to the image size.
go.set_scale(vmath.vector3(image_resource.header.width, image_resource.header.height, 1))-- Apply image to a model.
resource.set_texture(go.get('#model', 'texture0'), image_resource.header, image_resource.buffer)
```