How to animate 2D characters using swift for a fighting game?

Viewed 167

Hello I have a basic knowledge of programming in swift and also one simple app on the store already. I have an idea of a new app which would include some animations. It would be very simple "fighting game". I want to animate a 2D characters which would be drawn frame by frame. Something similar to old 2D fighting games "street fighter etc." I don't know where to start. What tools do I need to use? Do I have to learn SpriteKit? Or is there some better simpler way? Can you guide me where to start and how to achieve by goal? All I need is for the character to do a few simple moves. It doesn't have to be smooth as an animated movie but it has to look like the character is hitting the other one. I will hire someone to draw the pictures for me I just want to do the coding Thank you for an answer.

1 Answers

There really isn't a correct answer to this question without providing additional details. It all kind of depends on what your app is supposed to do exactly. If it's a game, then it would be reasonable to learn SpriteKit since that gives you a head start and a lot of things that help in game-related mechanics out of the box, like hitboxes, movement, characters, score etc.

It also depends on what kind of animation you would want to achieve. If it's for example, just a static character on screen, that moves one arm, maybe you could achieve the animation effect with UIKit, by just rotating/moving a view, that represents the arm. I'm just giving you an example.

If you just want to create some kind of repeatable animation, like a .gif image, then you can just loop an array of images/sprites/frames and create an illusion of animation.

var imageView = UIImageView()
let arrayOfImageNames = ["frame1.png", "frame2.png", "frame3.png"] //etc
let imageFrames = arrayOfImageNames.compactMap{ UIImage(named: $0) } //get all the image frames as [UIImage]
imageView.animationImages = imageFrames
imageView.animationDuration = 2 //duration of animation in seconds
imageView.startAnimating()

Like I said, it all kind of depends on what you want to create, and how complicated you want your app to be and how the animated character interacts with its environment.

Related