Centralization tool

Can we get a centralization tool? Something that shows where the center of the canvas is and also allow us to move a selection to the cente? I spend so much time drawing lines and couting pixels to find the center and i think that a tool like that would be really cool, useful and time saving!

3 Likes

I’ve only been using asesprite since earlier today, and I also think this would be useful. I put together a quick script that does it.

You can grab my script from this git repository.

Here is the current content for anyone who just wants to look… if you want to use it, go to the repository, as that is where I will put any improvements I make:

----------------------------------------------------------------------
-- Center the current selection on the sprite
-- Copyright 2020 Geoff Beier <geoff@tuxpup.com>
-- Licensed under the MIT license. See LICENSE.txt for details.
----------------------------------------------------------------------

-- bail if there's no active sprite
local spr = app.activeSprite
if not spr then return end

-- bail if nothing's selected
local sel = spr.selection
if sel.isEmpty then return end

--print("sel:"..sel.bounds.x..","..sel.bounds.y)

-- The MoveMask command requires us to specify X <units> up, Y <units> down
-- rather than just specifying new coordinates.
new_x = spr.bounds.width/2 - sel.bounds.width/2
x_dir = "right"
x_distance = 0
if new_x < sel.bounds.x then
	x_dir = "left"
	x_distance = sel.bounds.x - new_x
elseif new_x > sel.bounds.x then
	x_dir = "right"
	x_distance = new_x - sel.bounds.x
end

new_y = spr.bounds.height/2 - sel.bounds.height/2
y_dir = "down"
y_distance = 0
if new_y < sel.bounds.y then
	y_dir = "up"
	y_distance = sel.bounds.y - new_y
elseif new_y > sel.bounds.y then
	y_dir = "down"
	y_distance = new_y - sel.bounds.y
end

--print('need to move ' .. x_dir .. ' ' .. tostring(x_distance) .. ' and ' .. y_dir .. ' ' .. tostring(y_distance))

if x_distance ~= 0 then
	app.command.MoveMask{
		direction=x_dir,
		units="pixel",
		quantity=x_distance
	}
end

if y_distance ~= 0 then
	app.command.MoveMask{
		direction=y_dir,
		units="pixel",
		quantity=y_distance
	}
end
5 Likes

So this script has me perplexed, it works on one computer I have, but not the other.

On the computer it doesn’t work on it just moves the selection area and not the sprite / art work.

Step one select the section I want to center.

step 2 run the script, it centers the selection marks, but not the sprite…

Any ideas?

I love the script on the system it works on it saves me a ton of time, but it’s kind of… annoying having to send everything I want centered to another computer. XD

I’ve tried completely removing Aseprite from the non-working computer and copying over the Aseprite and all it’s appdata settings over and that doesn’t fix the issue. I’ve also tried a completely fresh Aesprite with only this script installed and still no.

System info:
Windows 10 20h1 current version of Aesprite.

I’ve figured it out! “target=‘content’,” was missing from the “app.command.MoveMask” command, so for some reason unknown to me it defaults to content on one system and boundaries on the other. Here’s the fixed version if anyone else runs into this issue.

----------------------------------------------------------------------
-- Center the current selection on the sprite
-- Copyright 2020 Geoff Beier <geoff@tuxpup.com>
-- Licensed under the MIT license. See LICENSE.txt for details.
----------------------------------------------------------------------

-- bail if there's no active sprite
local spr = app.activeSprite
if not spr then return end

-- bail if nothing's selected
local sel = spr.selection
if sel.isEmpty then return end

--print("sel:"..sel.bounds.x..","..sel.bounds.y)

-- The MoveMask command requires us to specify X <units> up, Y <units> down
-- rather than just specifying new coordinates.
new_x = spr.bounds.width/2 - sel.bounds.width/2
x_dir = "right"
x_distance = 0
if new_x < sel.bounds.x then
	x_dir = "left"
	x_distance = sel.bounds.x - new_x
elseif new_x > sel.bounds.x then
	x_dir = "right"
	x_distance = new_x - sel.bounds.x
end

new_y = spr.bounds.height/2 - sel.bounds.height/2
y_dir = "down"
y_distance = 0
if new_y < sel.bounds.y then
	y_dir = "up"
	y_distance = sel.bounds.y - new_y
elseif new_y > sel.bounds.y then
	y_dir = "down"
	y_distance = new_y - sel.bounds.y
end

--print('need to move ' .. x_dir .. ' ' .. tostring(x_distance) .. ' and ' .. y_dir .. ' ' .. tostring(y_distance))

if x_distance ~= 0 then
	app.command.MoveMask{
		target='content',
		direction=x_dir,
		units="pixel",
		quantity=x_distance
	}
end

if y_distance ~= 0 then
	app.command.MoveMask{
		target='content',
		direction=y_dir,
		units="pixel",
		quantity=y_distance
	}
end
1 Like

Another small edit, this time instead of bailing / ending if nothing is selected the layer content is selected and centered.

For myself this is a big time savor as I often just want to center what’s on the layer, so this skips the longest manual step for me.

----------------------------------------------------------------------
-- Center the current selection on the sprite
-- Copyright 2020 Geoff Beier <geoff@tuxpup.com>
-- Licensed under the MIT license. See LICENSE.txt for details.
----------------------------------------------------------------------

-- bail if there's no active sprite
local spr = app.activeSprite
if not spr then return end

-- Select Content if nothing's selected
local sel = spr.selection
if sel.isEmpty then
	app.command.MaskContent()
	local spr = app.activeSprite
end
--print("sel:"..sel.bounds.x..","..sel.bounds.y)

-- The MoveMask command requires us to specify X <units> up, Y <units> down
-- rather than just specifying new coordinates.
new_x = spr.bounds.width/2 - sel.bounds.width/2
x_dir = "right"
x_distance = 0
if new_x < sel.bounds.x then
	x_dir = "left"
	x_distance = sel.bounds.x - new_x
elseif new_x > sel.bounds.x then
	x_dir = "right"
	x_distance = new_x - sel.bounds.x
end

new_y = spr.bounds.height/2 - sel.bounds.height/2
y_dir = "down"
y_distance = 0
if new_y < sel.bounds.y then
	y_dir = "up"
	y_distance = sel.bounds.y - new_y
elseif new_y > sel.bounds.y then
	y_dir = "down"
	y_distance = new_y - sel.bounds.y
end

--print('need to move ' .. x_dir .. ' ' .. tostring(x_distance) .. ' and ' .. y_dir .. ' ' .. tostring(y_distance))

if x_distance ~= 0 then
	app.command.MoveMask{
		target='content',
		direction=x_dir,
		units="pixel",
		quantity=x_distance
	}
end

if y_distance ~= 0 then
	app.command.MoveMask{
		target='content',
		direction=y_dir,
		units="pixel",
		quantity=y_distance
	}
end
2 Likes