Last active
July 6, 2021 18:15
-
-
Save oeloeloel/c920bccf5389438ae97ea6801243a7ba to your computer and use it in GitHub Desktop.
Supersampling for even rotation of odd sized sprites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# supersampling for fancy sprite rotation | |
# solves uneven rotation of odd-sized sprites | |
# using an upscaled render target | |
def tick(args) | |
args.state.size ||= 7 # width/height of sprite (odd) | |
args.state.upsample ||= 8 # 2 minimum, 8 is better | |
args.state.path ||= 'sprites/rotate5.png' # path to sprite | |
args.state.upsample_size ||= args.state.size * args.state.upsample | |
args.outputs[:supsam].w = args.state.upsample_size | |
args.outputs[:supsam].h = args.state.upsample_size | |
# normal rotation on the left | |
normal_rotation = { | |
x: 56, | |
y: 35, | |
w: args.state.size, | |
h: args.state.size, | |
path: args.state.path, | |
angle: args.tick_count | |
}.sprite | |
# fancy rotation on the right | |
args.outputs[:supsam].primitives << { | |
x: 0, | |
y: 0, | |
w: args.state.upsample_size, | |
h: args.state.upsample_size, | |
path: args.state.path, | |
angle: args.tick_count | |
} | |
fancy_rotation = { | |
x: 66, | |
y: 35, | |
w: args.state.size, | |
h: args.state.size, | |
path: :supsam, | |
}.sprite | |
# borders around sprites to show the center drift | |
borders = [ | |
{ | |
x: 55, | |
y: 34, | |
w: 9, | |
h: 9, | |
}.border, | |
{ | |
x: 65, | |
y: 34, | |
w: 9, | |
h: 9, | |
}.border | |
] | |
# magnifies output purely to make the result easier to see | |
# send directly to outputs.sprites|primitives under normal conditions | |
args.outputs[:enlarger].primitives << [ | |
normal_rotation, | |
fancy_rotation, | |
borders, | |
] | |
args.state.magnification ||= 10 | |
args.outputs.sprites << { | |
x: 0, | |
y: 0, | |
w: args.grid.w * args.state.magnification, | |
h: args.grid.h * args.state.magnification, | |
path: :enlarger | |
} | |
# labels | |
args.outputs.labels << { | |
x: 640, | |
y: 460, | |
text: "Normal Fancy", | |
alignment_enum: 1 | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment