A simple spritesheet animation system for Raylib on Swift.

Overview

About

A simple spritesheet animation system for Raylib on Swift.

Aeni allows you to quickly and easily animate your spritesheet in your Raylib for Swift project! It divides the process into two simple steps to create a working animation.

Aeni is a shortened word for "aenimeisheon" in Korean which translates to "Animation".

Instructions

Getting Aeni set up and running is easy, you can have it ready to go in no more than three minutes!

Firstly make sure you added Aeni as your dependency package!

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "Aeni Example",
    dependencies: [
        .package(url: "https://github.com/STREGAsGate/Raylib.git", .branch("master")),
        .package(url: "https://github.com/conifer-dev/Aeni.git", .branch("main"))
    ],
    targets: [
        .executableTarget(name: "AeniExample",
                          dependencies: ["Raylib", "Aeni"],
                          resources: [.process("Assets")]),
    ]
)

The library is split into two parts, the Sprite type that is used to create a custom Sprite type and the Sprite Animator that accepts Sprite as a requirement in order to animate through the spritesheet that the Sprite holds.

Check the example below to see how to easily set it up:

import Raylib
import Aeni

Raylib.initWindow(800, 450, "Aeni Example")
Raylib.setTargetFPS(60)

let spriteLocation = Bundle.module.url(forResource: "player_sheet", withExtension: "png")
let playerSprite = Raylib.loadTexture(spriteLocation!.path)
let player = Sprite(spriteSheet: playerSprite, frameDimensions: Vector2(x: 24, y: 24), scale: Vector2(x: 2, y: 2))
let playerIdle = SpriteAnimator(sprite: player, position: Vector2(x: 50, y: 50), origin: Vector2(x: 0, y: 3), rotation: 0, startingFrame: 0, endingFrame: 4, column: 0, duration: 0, animationSpeed: 0.17, repeatable: true, tintColor: .white, debugMode: true)

// You can continue adding more animations using the same Sprite and easily swap them around using a variable 
// that holds the current animation or store them in a dictionary.

while !Raylib.windowShouldClose {
    Raylib.beginDrawing()
        Raylib.clearBackground(.black)
        playerIdle.render()
        playerIdle.update()
    Raylib.endDrawing()
}
Raylib.unloadTexture(playerSprite)
Raylib.closeWindow()

A very barebones example of how to get Aeni running! Yes, this is all you need!

Let's go through Sprite and SpriteAnimator one by one and the properties mean:

Sprite

Property Example Description
spriteSheet - Texture2D playerSprite Required path to the spritesheet itself.
frameDimensions - Vector2 Vector2(x: 24, y: 24) These are the dimensions of the animation frames stored in a Vector2 type, x representing width and y representing height. These dimensions will be the same size as your character. In our example, the character is 24x24.
scale - Vector2 Vector2(x: 2, y: 2) The scale represents how much we would like to scale up our sprite by. If you don't want to scale up your sprite you can simply put 1 on both x & y.

Sprite Animator

Property Example Description
sprite - Sprite player Sprite type required to for the Sprite Animator to work.
position - Vector2 Vector2(x: 50, y: 50) Position property represents the location of your sprite, its x & y properties can be used to move the sprite in your window/game.
origin - Vector2 Vector2(x: 0, y: 3) The origin point of the Sprite (rotation/scale point and your hitboxes) will usually be 0 on both axies, however. It's worth nothing that this highly depends on your sprite. Its highly recommended to turn on debug mode and align your origin appropriately.
startingFrame - UInt 0 The starting point of your animation.
endingFrame - UInt 4 The last frame in the row of your animation is where your animation will end or begin looping through if repeatable is set to true.
column - UInt 0 Which column you would like to animate through. Every spritesheet starts from 0, therefore your first row of animation will be on column 0.
duration - Float32 3 How long you would like your animation to last. It's counted in seconds.
animationSpeed - Float32 0.17 How fast you would like to have your sprite to be animated.
repeatable - Bool true This value when set to true will loop your animation.
tintColor - Color .white Tint color of your sprite, if you don't want to include any, use white.
debugMode - Bool true Debug mode will render out the destination rectangle/hitbox of your animation.

Future plans

There are many things I want to add to Aeni, mainly internal collision detection between two Sprites so that it would be integrated within the Sprite type. If you have any suggestions on what to add please let me know and I will do my best!

Closing notes

This is the first-ever public library I've ever made... I'm no professional programmer, but a simple beginner who's trying to learn as much as possible so please bear with me, and if you think there's any way Aeni can be updated to work better feel free to send a PR! I would love to learn more and know better ways of programming in Swift & overall.

A massive thank you to Dustin from STREGAsGate for the neverending support and as a massive inspiration to me. Not to also forget the best man Novacti for his support during my work on Aeni.

You might also like...
MobilePillowTalkLite - An iOS & SwiftUI server monitor tool for linux based machines using remote proc file system with script execution A DSL to make animation easy on iOS with Swift.
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Elegant SVG animation kit for swift
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

Gemini is rich scroll based animation framework for iOS, written in Swift.
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Pulse animation for iOS written with Swift.
Pulse animation for iOS written with Swift.

Pulsator Pulse animation for iOS written with Swift. Great For: Pulses of Bluetooth, BLE, beacons (iBeacon), etc. Map Annotations Installation CocoaPo

A fantastic Physical animation library for swift
A fantastic Physical animation library for swift

A fantastic Physical animation library for swift(Not Just Spring !!!), it is base on UIDynamic and extension to it, friendly APIs make you use it or c

Swift animation made easy
Swift animation made easy

Fluent Swift Animations made Easy Installation Add the following to your Podfile and run pod install pod 'Fluent', '~ 0.1' or add the following

A powerful, elegant, and modular animation library for Swift.
A powerful, elegant, and modular animation library for Swift.

MotionMachine provides a modular, powerful, and generic platform for manipulating values, whether that be animating UI elements or interpolating prope

Swift animation library for iOS, tvOS and macOS.
Swift animation library for iOS, tvOS and macOS.

anim is an animation library written in Swift with a simple, declarative API in mind. // moves box to 100,100 with default settings anim { self.bo

Owner
Conifer
Just another wannabe game-dev. Self-taught newbie
Conifer
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022
YapAnimator is your fast and friendly physics-based animation system

YapAnimator is your fast and friendly physics-based animation system. YapAnimator was built with ease-of-use in mind, keeping you sane and your design

Yap Studios 1.9k Dec 6, 2022
An experiment for using SwiftUI's custom timing Animation to create an orbital-like animation.

Orbital-SwiftUI-Animation An experiment for using SwiftUI's custom timing curve to create an orbital-like animation. How it looks: How it works: Apply

Mostafa Abdellateef 7 Jan 2, 2023
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
TTouchAnimatedButton is a simple and flexible animation component fully written in Swift

TTouchAnimatedButton is a simple and flexible animation component fully written in Swift. TTouchAnimatedButton is developed to make user feel button click becomes more vivid and realistic.

Nguyen Duc Thinh 2 Aug 18, 2022
Simple water drops animation 💧

WaterDrops Simple water drops animation ?? Example override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = U

Oh Hyungjun 403 Nov 10, 2022
Sample way of integrating animations into a design system for iOS app projects.

Animations in Design System The project presents a sample way of integrating animations into a design system for iOS developers. Project setup A sampl

Bulat Khabirov 1 Nov 26, 2021
Design-system-demo - This example code is bare-bones to show you what this framework can do

Basic Style Dictionary This example code is bare-bones to show you what this fra

Tylen St Hilaire 0 Feb 3, 2022