-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working with Font/Bitmap/ByteArray assets
- Loading branch information
1 parent
3442940
commit 278f095
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Working with font assets {#working-with-font-assets} | ||
|
||
Using font assets allows custom fonts to be included with your OpenFL project. In some cases, font assets will be embedded in the | ||
generated binary, and in others, they will be included as separate files. | ||
However, the API for working with either option is the same, allowing you to | ||
write code once and target many platforms. | ||
|
||
## Specifying font assets | ||
|
||
In a | ||
[Lime _project.xml_ file](https://lime.openfl.org/docs/project-files/xml-format/), | ||
include font image files using the | ||
[`<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets). | ||
Font assets may be of the `font` type only. | ||
|
||
- font | ||
|
||
```xml | ||
<assets path="assets"> | ||
<font path="fnt/MyFont.ttf" id="MyFont" /> | ||
<font path="fnt/AnotherFont.otf" /> | ||
</assets> | ||
``` | ||
|
||
## Using font assets | ||
|
||
The following code works with a font asset with the id "fnt". The code gets | ||
an instance of the font asset and uses it with a TextField: | ||
|
||
```haxe | ||
import openfl.utils.Assets; | ||
import openfl.display.Sprite; | ||
import openfl.text.Font; | ||
import openfl.text.TextFormat; | ||
import openfl.text.TextField; | ||
class FontAssetExample extends Sprite | ||
{ | ||
public function new() | ||
{ | ||
super(); | ||
var fnt:Font = Assets.getFont("MyFont"); | ||
var tf:TextField = new TextField(); | ||
tf.defaultTextFormat = new TextFormat(fnt.getName()); | ||
tf.text = "Hello world"; | ||
addChild(tf); | ||
} | ||
} | ||
``` | ||
|
||
## More Help topics | ||
|
||
- [openfl.utils.Assets class](https://api.openfl.org/openfl/utils/Assets.html) | ||
- [project.xml `<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Working with bitmap assets {#working-with-bitmap-assets} | ||
|
||
Using bitmap assets, instead of loading bitmaps from a web URL, a file system | ||
path, or generating the bitmap data manually, is another possibility for | ||
rendering bitmap images. In some cases, bitmap assets will be embedded in the | ||
generated binary, and in others, they will be included as separate files. | ||
However, the API for working with either option is the same, allowing you to | ||
write code once and target many platforms. | ||
|
||
## Specifying bitmap assets | ||
|
||
In a | ||
[Lime _project.xml_ file](https://lime.openfl.org/docs/project-files/xml-format/), | ||
include bitmap image files using the | ||
[`<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets). | ||
Bitmap assets may be of the `bitmap` type only. | ||
|
||
- image | ||
|
||
```xml | ||
<assets path="assets"> | ||
<image path="img/MyImage.png" id="MyImage" /> | ||
<image path="img/AnotherImage.jpg" /> | ||
</assets> | ||
``` | ||
|
||
## Using bitmap assets | ||
|
||
The following code works with a bitmap asset with the id "MyImage". The code | ||
gets an instance of the bitmap asset and passes it to a new Bitmap display | ||
object: | ||
|
||
```haxe | ||
import openfl.utils.Assets; | ||
import openfl.display.Bitmap; | ||
import openfl.display.BitmapData; | ||
import openfl.display.Sprite; | ||
class BitmapAssetExample extends Sprite | ||
{ | ||
public function new() | ||
{ | ||
super(); | ||
var bmd:BitmapData = Assets.getBitmapData("MyImage"); | ||
addChild(new Bitmap(bmd)); | ||
} | ||
} | ||
``` | ||
|
||
## More Help topics | ||
|
||
- [openfl.utils.Assets class](https://api.openfl.org/openfl/utils/Assets.html) | ||
- [project.xml `<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets) |
51 changes: 51 additions & 0 deletions
51
working-with-byte-arrays/working-with-byte-array-assets.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Working with byte array assets {#working-with-byte-array-assets} | ||
|
||
Using byte array assets, instead of loading binary data from a web URL or a file | ||
system pat is another possibility for reading byte arrays. In some cases, byte | ||
array assets will be embedded in the generated binary, and in others, they will | ||
be included as separate files. However, the API for working with either option | ||
is the same, allowing you to write code once and target many platforms. | ||
|
||
## Specifying byte array assets | ||
|
||
In a | ||
[Lime _project.xml_ file](https://lime.openfl.org/docs/project-files/xml-format/), | ||
include binary files using the | ||
[`<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets). | ||
Byte array assets may be of the `binary` type only. | ||
|
||
- image | ||
|
||
```xml | ||
<assets path="assets"> | ||
<binary path="img/MyBytes.dat" id="MyBytes" /> | ||
<binary path="img/AnotherFile.bin" /> | ||
</assets> | ||
``` | ||
|
||
## Using byte array assets | ||
|
||
The following code works with a byte array asset with the id "MyBytes". The code | ||
gets an instance of the byte array asset and prints its length to the debug | ||
console: | ||
|
||
```haxe | ||
import openfl.utils.Assets; | ||
import openfl.display.Sprite; | ||
import openfl.utils.ByteArray; | ||
class BinaryAssetExample extends Sprite | ||
{ | ||
public function new() | ||
{ | ||
super(); | ||
var bytes:ByteArray = Assets.getBytes("MyBytes"); | ||
trace(bytes.length); | ||
} | ||
} | ||
``` | ||
|
||
## More Help topics | ||
|
||
- [openfl.utils.Assets class](https://api.openfl.org/openfl/utils/Assets.html) | ||
- [project.xml `<assets>` element](https://lime.openfl.org/docs/project-files/xml-format/#assets) |