Showing posts with label game tutorial. Show all posts
Showing posts with label game tutorial. Show all posts

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])
            walkingFrames.append(knightAnimatedAtlas.textureNamed(knightTextureName))
        }
        knightWalkingFrames = walkingFrames
     
        // Idle Frames
        var idleFrames: [SKTexture] = []
        for i in 0...17 {
            let knightTextureName = String(format: "Idle_%03d", arguments: [i])
            idleFrames.append(knightAnimatedAtlas.textureNamed(knightTextureName))
        }
        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.removeAllActions()
        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 {
            animatedKnight()
        }
   
        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

Monday, January 20, 2014

Development is not a simple work

Development is not a simple work and cannot do by only some people.

Coding a game only the first step of developing a game.
- First step is very important because you decide to join in this era. However, it is not all. You have a lot of works to do to make sure your game successful. At the beginning of this era, if you game is good, it will be accepted by user because there aren't many games to play and user have enough time to test most of game. This time is very different, there are more than 100.000 games in AppStore and user cannot test all of these game.

* These are things you need to do:
- Make your title impressive
- Focus on your description
- Make beautiful screenshot
- Let people know you publish a game

* There are something you must do:
- Don't join some market, just create it.
- If you cannot create a market for your game, clone top game, not normal game.
- It is always enough space for your game, just do it or you never know how good your game is.

Saturday, January 18, 2014

How can I start programming game on Mobile?

What do you do when starting programming game?


First of all, I saw all people (not only programmer) think making a game is very easy. They only see what happen in a top game and see certain feature, they think it is easy because many feature are in a lot of game.

And here is my advices, this is not easy. All of feature you must do or find them on Internet. You won't know anything about game, you will be very hard to find stuff to do this. So try a small game and you will see how much you must do to finish a game.

There are many things you must do to create a game (not good game) that is accepted by Apple (not the users). You must do step by step to collect experience and stuff to do game. It is simple if you like playing game, but harder if you only want to create game for commercial. Try to get some developer that like game and they do it because of their hoppy.


There are 5 level of games:

+ Tutorial game: Game that only created by some programer to test or teach you do something. It is lack of feature. Normally, it only have game play scene and no more (sometime only 1 scene). It is used only for learning not for publish. Apple won't accept these game in AppStore.

+ Simple game: Game that be accepted by Apple. It is a game because this have all feature to call a game:
- A gameplay
- Menu
- Conclusion
=> However, these game is not keep user long. They will become boring very fast and never come back to your game. It only use for learning and testing your game. But this is what you need to do when you begin programming. Try to publish some simple game and you will gain a lot of experience  and stuff to do your next game.

+ Good game: Game is accepted by some of user. Now you game is better, they have some good feature and attractive your user,
This will have some of these feature:
- A good gameplay
- Keep user longer (1 - 3hours advance, this is good to keep user 3 hours)

+ True game: This game is attractive by a lot of user (milestone is 10.000 users). Your game is very good now.
This will have:
- Good gameplay
- Multiple mission
- Addiction
- Suitable with some user (they will play it a lot - 100 hours)

+ Top game: Your game have a unique feature (Facebook connection, Server - Client, ... ). You have huge fans and some of them are crazy because of your game.

* After you done a simple game (level 2) you will get a lot of experience and stuff to do next game. Please don't try to go over this level. You cannot finish a Good game immediate when you just start. Moreover, you will done 30 % your good game after you finish your simple game because most of them can be reuse very easy.

Friday, January 17, 2014

Working with Sprite Kit

Sprite Kit is a new engine from Apple. It is started using from IOS 7.

Sprite Kit is a powerful graphic framework not only for IOS 7, it is also use for Mac. You can create side shooter, puzzle or a platform if you want. It is the recommend tool for any developer have interesting in Apple product.

It is the flexible framework that allow you can control all your object (SKNode) without knowledge about OpenGL. It means you can setup position, rotation, gravity and many more thing. All of child node can easy access the parent node and call function without creating new delegate. It is so awesome framework for new programmer!

It is a big step for Apple developer. All of this engine is free to use without paying. It is a big advance   for Apple developer with other developer.

The only disadvantage of this engineer is it only work with IOS 7 and more. But it will be disappear  after IOS 7 become more popular.

This blog will give you some things about Sprite Kit and give you the reason to choose this as your main tool to develop game.