Tuesday, March 6, 2018

Swift Tutorial Animation the Knight in RPG game

In this tutorial, we will learn:
+ Create animation with texture atlases
+ Change the direction the bear faces based on the moving location
+ Make the ninja move to the touch location
+ Knight will stand and move

# Create the Swift Project
To start the tutorial, you need to create a Swift Project.
Start up you Xcode, select File\New\Project… (if there is no project), choose the iOS/Game Template and click on Next Button.

Game Project with Sprite Kit

Enter LapKanAnimationKnight for the Product Name.
Choose Swift for Language (Important)
Sprite Kit for Game Technology.
Next to create Project.

=> We have a ready project to start.

# Download the asset: Link

These images from Tokegameart, they are really good for RPG Games, so if you see this is good assets, buy from them, they are royal free.
Dark Knight Atlas

# Texture Atlases:

Copy these asset to Project.
Drag and drop these file to the project.

# Make simple animation first:
Create the variable for code:

private var knight = SKSpriteNode()
 private var knightWalkingFrames: [SKTexture] = []
 private var knightIdleFrames: [SKTexture] = []

# Setting up the Texture Atlas:
Now, we write the code to set the texture for each action
Action for walking from 0 -> 23.
Action for standing from 0 -> 17.
If you have more actions, you need to write more code for each action.

func buildKnight() {
        let knightAnimatedAtlas = SKTextureAtlas(named: "DarkKnight")
        // Walking Frames
        var walkingFrames: [SKTexture] = []
        for i in 0...23 {
            let knightTextureName = String(format: "Walking_%03d", arguments: [i])
        knightWalkingFrames = walkingFrames
        // Idle Frames
        var idleFrames: [SKTexture] = []
        for i in 0...17 {
            let knightTextureName = String(format: "Idle_%03d", arguments: [i])
        knightIdleFrames = idleFrames

So we have the function buildNinja, now the only thing we need to create a ninja is use

func animatedKnight() {
        knight.run(SKAction.repeatForever(SKAction.animate(with: knightWalkingFrames, timePerFrame: 0.03, resize: false, restore: true)), withKey: "walkingInPlaceKnight")

# Make Stand Frames:
After the knight go to the goal point, we remove all action and set the action for standing.
func knightStand() {
        knight.run(SKAction.repeatForever(SKAction.animate(with: knightIdleFrames, timePerFrame: 0.03, resize: false, restore: true)), withKey: "idleInPlaceKnight")

# Change Animation Facing Direction
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for t in touches { self.touchUp(atPoint: t.location(in: self)) }
        let touch = touches.first!
        let location = touch.location(in: self)
        moveKnight(location: location)

# Make Knight Moving:

func moveKnight(location: CGPoint) {
        if knight.action(forKey: "idleInPlaceKnight") != nil {
            knight.removeAction(forKey: "idleInPlaceKnight")
        var multiplierForDirection: CGFloat
        let knightSpeed = frame.size.width / 3.0
        let moveDifference = CGPoint(x: location.x - knight.position.x, y: location.y - knight.position.y)
        let distanceToMove = sqrt(moveDifference.x * moveDifference.x + moveDifference.y * moveDifference.y)
        let moveDuration = distanceToMove / knightSpeed
        if moveDifference.x < 0 {
            multiplierForDirection = -1.0
        } else {
            multiplierForDirection = 1.0
        knight.xScale = abs(knight.xScale) * multiplierForDirection
        if knight.action(forKey: "walkingInPlaceKnight") == nil {
        let moveAction = SKAction.move(to: location, duration: (TimeInterval(moveDuration)))
        let doneAction = SKAction.run( {
          [weak self] in self?.knightStand()
        let moveActionWithDone = SKAction.sequence([moveAction, doneAction])
        knight.run(moveActionWithDone, withKey: "knightMoving")

Full Code Done: Link

Wednesday, February 7, 2018

Simple Dog Life

Dog is popular pet over the world.
Do you want to know what the dog do in his life?

Just go around and get food.

Link: Download

Thursday, January 11, 2018

Awful Trip

Swordman John is a famous person in tiny empire. The kingdom now have the invasion of monster. He need to go back to the castle to combine with tiny army against the monsters.

Now he lost in the forest and he see reaper and skeleton warrior go after him. He can fight with them but it waste a lot of time, so try to avoid them and escape from the forest.

Can you show him how to get out of the forest and find the way to save his friend?

Important Note: Reaper and Skeleton are faster than you. There are many traps in the forest wait for you. This time is for your smart brain (Or I just make a mistake, Just kidding).

Download: Link

Thursday, December 14, 2017

Sticker Me Shining Boy

Cute boy with square faces will make you happy and make your chat more exciting.
It is include 9 animation stickers for you to chat with your friends.
Show your emotion with Shining Boy!

Suitable with new iMessage in IOS 10.

Download: Link

Wednesday, December 13, 2017

Sticker Me Shining Cloud

From sky, cloud now become your avatars. It is so cute.
It is include 9 animation stickers for you to chat with other.
Show your emotion with Shining Cloud!

Suitable with new iMessage in IOS 10.

Download: Link

Thursday, November 23, 2017

Tiny Empire Tiny Monster Attack

Tiny Town is secret place in the world.
All of villages is tiny and live here in a long time ago.

In this this, all monsters are attacking on the town.

Guide: Touch to kill these monster and stop the attack.

Download: Link

Tuesday, November 21, 2017

Tiny Empire Runner Heroes

Tiny Town is secret place in the world.
All of villages is tiny and live here in a long time ago.
This is time for Tiny Knight come back to the town.

Guide: Touch to go forward. Avoid the enemys. Be safe.