![]() We may either use app.pixelColor or bitwise operators. Since we are setting colors in bulk, we use integers, not Colors. To flip the y axis, we subtract the green channel from 255 in other cases, however, we may have to negate y or subtract y from the height of the image. The coordinates are in turn converted to red and green. For y, we use floor division to avoid overflow. Alternatively, we could increment an array index i, then convert the one-dimensional index to two dimensional coordinates with x = i % w and y = i // w. We retrieve the pixel’s coordinates from each element returned by the iterator. We then get a pixel iterator from the image via the pixels method. ![]() Below is a pink circle orbiting around a central point. With a basic understanding of frames and cels under our belt, let’s make an animation. The steps taken by the script are registered in the history and can be undone by going to Edit > Undo or by using the shortcut Ctrl+Z. The app must be refreshed for the changes made by the script to be visible. To tell the tool where to go on the sprite, we need a table of Points, which are created from an x and y. We select which tool to use with a string, "pencil" in this case. This method corresponds to the tools on the right side of the GUI. (We could’ve used app.activeBrush if it didn’t matter.) With that we have most of the ingredients needed for app.useTool. To govern the size and shape of the pencil stroke, we create a Brush. Cels are formed at the intersection of the two. Frames are the columns in the example above, labeled 1, 2, 3 and 4. The relationship is easier to understand by looking at the Aseprite GUI, where layers are the rows in a 2D grid. Layers in rows intersect with frames in columns to make cels. As the documentation explains, “a frame is the set of cels for all layers in a specific time.” A cel should not be confused with a frame. The term is inherited from traditional animation, where cel is short for celluloid. The sprite should already have a layer, but we’re establishing a habit of always creating a layer so as to not interfere with any work done prior to the script execution.Ī cel is an image on a layer at a given frame of animation. For that reason, we select the app.activeSprite if it is nil, we create a new Sprite.Īfter we have access to a Sprite, we create a new Layer and Cel. A dialog window may be opened before a new Sprite is even created. We access information about the Aseprite editor via the variable app. The fields in args correspond to the ids we provided to dlg:color, slider and number. To read the information from the dialog, we cache dlg.data. The number method’s decimals parameter is the maximum decimal places before the number is rounded. The first argument, "%.1f" specifies the decimal places to print, 1 in this case. To accomplish this we supply a number as the second argument to string.format. The number dialog’s text parameter requires a string. We’ll draw a large blue dot with the pencil tool. Now let’s create a dialog that uses inputs to change a sprite’s canvas. Last but not least, we need to call show for the dialog to appear. Text in this console cannot be selected or copied. Whenever a Lua script contains at least one print call, the Aseprite console will appear. In this case we print, then close the dialog. The button method’s most important parameter is onclick, where we will define a function of our own to be called when the button is clicked. The option parameter specifies the selected option, while the options parameter specifies the possibilities. The combo box works with a table of strings that acts as an enumeration. There is a shades input if we wish to handle multiple colors. We could also construct a color using hue, saturation and value (HSV) hue, saturation and lightness (HSL) or an ABGR hexadecimal, such as 0xffccbbaa. Above, we’ve created a color by supplying the red, green, blue and alpha channels in the range. The color picker input works with a Color object. If we wanted real number inputs, or didn’t have a bounding range, we could use a number input instead. The first input, a slider, works on integers with a min (minimum) and max (maximum). The colon syntax implicitly passes the dlg instance as the first argument into the method as self. Because the methods which create a slider, color selector and combo box are instance methods of dlg, we call them with a colon : rather than a dot. The local keyword limits the scope of the variable. Arguments that we do not specify fall back to a default.Īfter we create a Dialog, we assign an instance to a local variable dlg. ![]() We use Lua’s table syntax, curly braces, to call dialog methods because we can label each argument that we pass to a method with a named parameter followed by an equal sign =.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |