Advanced use of the drawing API
OpenFL supports an advanced set of drawing features. The drawing API enhancements for these runtimes expand upon the standard drawing methods so you can establish data sets to generate shapes, alter shapes at runtime, and create three-dimensional effects. The drawing API enhancements consolidate existing methods into alternative commands. These commands leverage vector arrays and enumeration classes to provide data sets for drawing methods. Using vector arrays allows for more complex shapes to render quickly and for developers to change the array values programmatically for dynamic shape rendering at runtime.
The following tasks are things you’ll likely want to accomplish using the advanced drawing API in OpenFL:
- Using Vector objects to store data for drawing methods
- Defining paths for drawing shapes programmatically in a single operation
- Defining winding rules to determine how overlapping shapes are filled
- Reading the vector graphics content of a display object, such as to serialize and save the graphics data, to generate a spritesheet at runtime, or to draw a copy of the vector graphics content
- Using triangles and drawing methods for three-dimensional effects
Important concepts and terms
The following reference list contains important terms that you will encounter in this section:
- Vector: An array of values all of the same data type. A Vector object can store an array of values that drawing methods use to construct lines and shapes with a single command.
- Path: A path is made up of one or more straight or curved segments. The beginning and end of each segment are marked by coordinates, which work like pins holding a wire in place. A path can be closed (for example, a circle), or open, with distinct endpoints (for example, a wavy line).
- Winding: The direction of a path as interpreted by the renderer; either positive (clockwise) or negative (counter- clockwise).
- GraphicsStroke: A class for setting the line style. While the term "stroke" isn’t part of the drawing API enhancements, the use of a class to designate a line style with its own fill property is part of the new drawing API. You can dynamically adjust a line’s style using the GraphicsStroke class.
- Fill object: Objects created using display classes like openfl.display.GraphicsBitmapFill and openfl.display.GraphicsGradientFill that are passed to the drawing command
Graphics.drawGraphicsData(). Fill objects and the enhanced drawing commands introduce a more object-oriented programming approach to replicating
OpenFL ni programu ya kuchora API ambayo inasaidia seti ya juu ya vipengele vya kuchora. Kuongeza kwa API ya kuchora kwa runtimes hizi huongeza juu ya mbinu za kawaida za kuchora ili uweze kuanzisha seti za data kuzalisha maumbo, kubadilisha maumbo wakati wa kukimbia, na kuunda athari za pande tatu. Kuongeza API ya kuchora kuunganisha mbinu zilizopo katika amri mbadala. Amri hizi leverage vector arrays na enumeration madarasa kutoa seti ya data kwa ajili ya mbinu za kuchora. Kutumia vector arrays inaruhusu kwa maumbo tata zaidi kutoa haraka na kwa watengenezaji kubadilisha maadili array programmatically kwa ajili ya maumbo ya nguvu kutoa wakati wa kukimbia. Kazi zifuatazo ni mambo ambayo unaweza kutaka kutimiza kwa kutumia API ya kuchora ya hali ya juu katika OpenFL: Kutumia vitu vya vector kuhifadhi data kwa njia za kuchora - Kufafanua njia za kuchora maumbo kwa programu katika operesheni moja - Kufafanua sheria za kuunganisha ili kuamua jinsi maumbo ya kuingiliana yanavyojazwa - Kusoma yaliyomo ya picha za vector ya kitu cha kuonyesha, kama vile kuunganisha na kuhifadhi data za picha, kuunda spritesheet wakati wa kukimbia, au kuchora nakala ya picha ya picha za vector. Vector kitu inaweza kuhifadhi safu ya maadili kwamba mbinu kuchora kutumia kujenga mistari na maumbo na amri moja. - Njia: Njia ni alifanya juu ya moja au zaidi ya moja kwa moja au curved sehemu. Mwanzo na mwisho wa kila sehemu huonyeshwa kwa kuratibu, ambazo hufanya kazi kama pini zinazoshikilia waya mahali pake. Njia inaweza kuwa imefungwa (kwa mfano, mduara), au wazi, na pointi za mwisho tofauti (kwa mfano, mstari wa mawimbi). - Winding: mwelekeo wa njia kama tafsiri na renderer; ama chanya (kwa upande wa saa) au hasi (kinyume cha saa). - GraphicsStroke: darasa kwa ajili ya kuweka mtindo wa mstari. Wakati neno "stroke" si sehemu ya kuboresha kuchora API, matumizi ya darasa kuteua mtindo mstari na mali yake mwenyewe kujaza ni sehemu ya kuchora API mpya. Unaweza dynamically kurekebisha line<unk>s style kutumia GraphicsStroke darasa. - kujaza kitu: Vitu kuundwa kwa kutumia kuonyesha madarasa kama vile openfl.display.GraphicsBitmapFill na openfl.display.GraphicsGradientFill kwamba ni kupita kwa amri ya kuchora Graphics.drawGraphicsData (). Jaza vitu na kuimarishwa amri kuchora kuanzisha zaidi kitu-oriented programu mbinu ya kuiga