Aseprite-Script-Examples
Aseprite-Script-Examples copied to clipboard
Example of how to use "app.command.MoveMask"?
I'm trying to create a "parallax" script that would take a layer, create X frames for this layer, and move the content in the cell in a direction by a small number of pixels per frame. I'm able to create the X frames correctly, but I can't get the content to move. Here's my code so far:
local spr = app.activeSprite
if not spr then
app.alert("There is no sprite to export")
return
end
local num_frames = 4
local vertical_drift = 2
local horizontal_drift = 0
for frame_i = 1, num_frames - 1 do
spr.selection:select(Rectangle(0, 0, spr.width, spr.height))
app.command.CopyMerged()
app.command.NewFrame()
app.command.Paste()
spr.selection:deselect()
local s = Selection(Rectangle(0, 0, spr.width, spr.height))
app.command.MoveMask(
s,
"up",
"pixel",
vertical_drift
)
s:deselect()
end
The current behaviour: the content does not move at all, in any direction for any amount.
I have tried doing app.activeCel.position = ...
, and also spr.selection.bounds = ...
but those didn't work either. Can someone give me guidance? 😄
I tried asking something the same on the community help forums some weeks ago, but no luck either ^^U https://community.aseprite.org/t/lua-scripting-can-you-move-a-selection/2773 If I learn how to use MoveMask command I'll write it there, and here as well :) Please let me know if you succeed at it first! ;)
Last time I check the MoveMask wasn't working from scripts. I'll try to fix it for the next version if it's possible to do it quickly (as next week I'd like to release a patch for some important fixes).
That would be great :D Thank you very much David! :D
Here again, finally I was able to test a little the MoveMask
command and create some documentation about it:
I think MoveMask
will work only when the UI is available.
Thanks a lot! :D
I was very hyped when I read that you were able to test and document the MoveMask
command, but then I tested the example and it didn't work XD
So i thought, "I must be doing something wrong" and started checking and trying several things, after a while and when I was about to make a small video showing that it didn't worked for me just in case, I had an idea: "Mmmm... Maybe it's because of the quotes?" and yeah that was the problem XD
I'm using Windows 7 (Ultimate-64) and Aseprite v1.2.13-x64, and it seems that it doesn't like sigle quotes '
, but if you use double quotes "
, it works like a charm :D
So, I'd like to suggest you to test if it also does work on your usual OS (you were using Mac nowadays if I'm not mistaken?), and if it also works there, please replace the single quotes symbols by double quotes, so it'll work for everybody :)
-- Code with corrected quotation marks (for Windows 7 at least):
local spr = app.activeSprite
spr.selection = Selection(Rectangle(1,1,spr.width-2,spr.height-2))
app.command.MoveMask{
direction="right",
units="pixel",
quantity=2
}
app.command.MoveMask{
direction="up",
units="pixel",
quantity=2
}
app.command.DeselectMask()
Again, thank you very much David, you are the best! :D
You're welcome @jjhaggar! I'll check that issue about the quotes on Windows later; it shouldn't differ between macOS vs Windows (because the Lua parser code is the same on both platforms), but I'll give a try.
Just in case, see if the copy-and-paste process of the code from the web browser to your text editor didn't mess the quotes (something that is really common on both platforms).
I didn't copy-paste the text, I directly downloaded the raw file from here: https://gist.githubusercontent.com/dacap/7be7102ea6845774e30d2d664dcfd964/raw/d49012f4cb89e7eb5d38145178be8e6dd1de931f/MoveMask%2520Test.lua (I usually do that in order to avoid these kind of problems)
Maybe I have something installed that interferes with my Lua parser? I have no idea ^^U
I didn't test on Windows yet, but I think it's related to other issue that I forgot in the Test.lua
file: the target
field (which is not initialized on the C++ code, so it's invalid at the very beginning).
I've updated the example.
Oh, thank you so much! :D I was trying again today (using the double quotation marks) and it wasn't working, I was really confused XD
I have tried your updated example and it works perfectly! So the quotation type, single or double, seems to be irrelevant (I probably did something between one test and another, and it worked just by coincidence, and I thought it was the quotations).
Again, thank you very much!! :D :D :D
I can't seem to get MoveMask to move more than one pixel when the target is 'boundaries' as opposed to 'content'. Here is the code I'm using:
app.command.MoveMask{ target='boundaries', direction='right', units='pixel', quanitity=10, wrap=true }