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
6 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
2 Likes

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
3 Likes