Spritekit mobile game joystick joystick use--by Ifiero game development tutorial

Source: Internet
Author: User
Tags spritekit

# # 工欲善其事, its prerequisite

Sometimes it's important to learn how to apply third-party libraries, because we don't have to reinvent our own wheels, and here we use gravity sensing to manipulate the plane instead of using joystick joystick to manipulate it as follows:
```
Statement game joystick;
private Var joystick:analogjoystick! Game joystick;
```
> Create a function, new game joystick node, and add to Gamescene
```
mark:-//adding gamepad
Func Createjoystick () {
Joystick = Analogjoystick (Diameter:cgfloat (250.0))//joystick diameter
Joystick.stick.image = UIImage (named: "Jstick")//Joystick diagram
Joystick.substrate.image = UIImage (named: "Jsubstrate")//joystick background
Joystick.zposition = 1
Joystick.position = Cgpoint (x: -380.0, y:-720.0)
Self.addchild (Joystick)
Joystick.alpha = 0.8
Control just started.
Joystick.beginhandler = {[unowned self] in
Guard Let Sprite = Self.playernode else {
Return
}
Print ("Begin", Sprite);
}
Tracking controls
Joystick.trackinghandler = {[unowned self] data in
Guard Let Sprite = Self.playernode else {
Return
}
Let x = data.velocity.x * 0.12
Let y = data.velocity.y * 0.12
Let XPos = sprite.position.x + x
Let YPos = sprite.position.y + y
Sprite.position = Cgpoint (X:xpos, Y:ypos)//Update aircraft location
Sprite.zrotation = data.angular//aircraft angle steering;
}
When the joystick is stopped;
Joystick.stophandler = {[unowned self] in
Guard Let Sprite = Self.playernode else {
Return
}
Print ("Stop", Sprite);
}
}
```
> Add joystick function to the override Func Didmove (to View:skview) {}
```
Game Handle Start
Override Func Didmove (to View:skview) {
Createjoystick ()
}
```
Just take these steps above, you can add cool game joystick, it's so simple!!!

Game Teaching: http://www.iFIERO.com
SOURCE Portal: Https://github.com/apiapia/SpaceBattleSpriteKitGame

Spritekit mobile game joystick joystick use--by Ifiero game development tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.