Return to site

Cocos2d For Mac

broken image


  1. Cocos2d-x is an open source, cross-platform game engine. It allows developers to code in C, Lua and Javascript deployment into iOS, Android, Windows Phone, Mac.
  2. We also compared previous versions of Cocos Creator, Cocos2d-js, Cocos2d-x and Cocos2d-lua to ensure we were testing in a broad spectrum, to provide the most accurate data. The results: On Android native, the performance of Cocos Creator v2.2.0 is 1.5x - 1.7x Cocos2d-lua and Cocos Creator v1.9.3.
  3. Targets the Operating Systems linux, mac or windows on Pc-like hardware. Provides some conventions and classes to help you structure a 'scene based application'. A cocos2d application consists of several scenes, and a workflow connecting the different scenes.

It is based on cocos2d-iphone, but instead of using Objective-C, it uses C. It works on iOS, Android, macOS, Windows and Linux. It works on iOS, Android, macOS, Windows and Linux. Cocos2d-x is a mature open source cross-platform game development framework that supports 2D and 3D game creation. The engine provides rich functions such as graphics rendering, GUI, audio, network, physics, user input, etc., and is widely used in game development and interactive application construction.

The official C++ client handles all communication in realtime with the server. It implements all features in the server and is written with C++11.

Download¶

The client SDK can be downloaded from GitHub releases. You can download 'nakama-cocos2d-x-sdk_$version.zip'.

For upgrades you can see changes and enhancements in the CHANGELOG before you update to newer versions.

Help and contribute

The Cocos2d-x C++ client is open source on GitHub. Please report issues and contribute code to help us improve it.

Setup¶

When you've downloaded the Nakama Cocos2d archive and extracted it to NAKAMA_COCOS2D_SDK folder, you should include it in your project.

We don't recommend to copy Nakama Cocos2d SDK to your project because it's quite big in size (~600 Mb).

Copy NakamaCocos2d folder¶

Copy NakamaCocos2d folder from NAKAMA_COCOS2D_SDK to your Classes folder.

Setup for Mac and iOS projects¶

  1. Add NAKAMA_COCOS2D_SDK/include in Build Settings > Header Search Paths
  2. Add libs folder in Build Settings > Library Search Paths:
    • NAKAMA_COCOS2D_SDK/libs/ios - for iOS
    • NAKAMA_COCOS2D_SDK/libs/mac - for Mac
  3. Add all .a files located in libs folder to General > Frameworks, Libraries, and Embedded Content
  4. Add NAKAMA_COCOS2D_SDK/NakamaCocos2d folder to your XCode project as group (not a reference).

Setup for Android projects¶

If you use CMake then see Setup for CMake projects section.

Download

If you use ndk-build then add following to your Android.mk file:

Android uses a permissions system which determines which platform services the application will request to use and ask permission for from the user. The client uses the network to communicate with the server so you must add the 'INTERNET' permission.

Setup for CMake projects¶

Open for edit your CMakeLists.txt file and find following existing code:

add next code before:

At bottom of your CMakeLists.txt file add following:

T racks for mac. The T-RackS 5 MAX collection for Mac/PC comprises 38 superb modules that range from compressors and limiters to equalizers, channel strips, reverbs and more. All the gear has been modeled after some of the most sought-after production equipment of all time and chosen for its unique sonic character. T-RackS 5 has evolved into the most powerful mix and master modular system ever, offering maximum processing versatility, an improved audio engine, 4 new processors for a total of 38 high-quality modules on a flexible 16 processor series/parallel chain, a comprehensive broadcast ready professional metering tool section, a new completely redesigned, smart single-window GUI as well as an album.

Setup for Visual Studio projects¶

In Project Settings add following:

  1. Add NAKAMA_COCOS2D_SDK/include to C/C++ > General > Additional Include Directories
  2. Add folder to Linker > General > Additional Library Directories:
    • NAKAMA_COCOS2D_SDK/libs/win32/v140 - for VS 2015 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v140 - for VS 2015 x64
    • NAKAMA_COCOS2D_SDK/libs/win32/v141 - for VS 2017 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v141 - for VS 2017 x64
    • NAKAMA_COCOS2D_SDK/libs/win32/v142 - for VS 2019 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v142 - for VS 2019 x64
  3. Add all .lib files located in above folder to Linker > Input > Additional Dependencies
  4. Add sources from Classes/NakamaCocos2d to your Visual Studio project.

Usage¶

Include nakama helper header.

Initialize logger with debug logging level.

The client object is used to execute all logic against the server.

Note

By default the client uses connection settings '127.0.0.1' and 7350 port to connect to a local Nakama server.

Tick¶

The tick method pumps requests queue and executes callbacks in your thread. You must call it periodically (recommended every 50ms) in your thread.

Cocos2d for mac tutorial

Cocos2d Macos

Without this the default client and realtime client will not work, and you will not receive responses from the server.

Authenticate¶

With a client object you can authenticate against the server. You can register or login a user with one of the authenticate options.

To authenticate you should follow our recommended pattern in your client code:

1. Build an instance of the client.

2. Authenticate a user. By default Nakama will try and create a user if it doesn't exist.

Tip

It's good practice to cache a device identifier on Android when it's used to authenticate because they can change with device OS updates.

In the code above we use authenticateDevice() but for other authentication options have a look at the code examples.

Sessions¶

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a NSession object.

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

A full example class with all code above is here.

Send requests¶

When a user has been authenticated a session is used to connect with the server. You can then send messages for all the different features in the server.

This could be to add friends, join groups, or submit scores in leaderboards. You can also execute remote code on the server via RPC.

All requests are sent with a session object which authorizes the client.

Have a look at other sections of documentation for more code examples.

Realtime client¶

The client can create one or more realtime clients. Each realtime client can have it's own event listener registered for responses received from the server.

Cocos2d for mac os

Note

The socket is exposed on a different port on the server to the client. You'll need to specify a different port here to ensure that connection is established successfully.

Don't forget to call tick method. See Tick section for details.

You can use realtime client to send and receive chat messages, get notifications, and matchmake into a multiplayer match. You can also execute remote code on the server via RPC.

To join a chat channel and receive messages:

There are more examples for chat channels here.

Handle events¶

A realtime client has event handlers which are called on various messages received from the server.

Event handlers only need to be implemented for the features you want to use.

CallbacksDescription
onDisconnectHandles an event for when the client is disconnected from the server.
onNotificationReceives live in-app notifications sent from the server.
onChannelMessageReceives realtime chat messages sent by other users.
onChannelPresenceIt handles join and leave events within chat.
onMatchStateReceives realtime multiplayer match data.
onMatchPresenceIt handles join and leave events within realtime multiplayer.
onMatchmakerMatchedReceived when the matchmaker has found a suitable match.
onStatusPresenceIt handles status updates when subscribed to a user status feed.
onStreamPresenceReceives stream join and leave event.
onStreamStateReceives stream data sent by the server.

Logging¶

Client logging is off by default.

To enable logs output to console with debug logging level:

Errors¶

The server and the client can generate logs which are helpful to debug code.

Cocos2d For Mac Os

To enable client logs see Logging section.

In every request in the client you can set error callback. It will be called when request fails. The callback has NError structure which contains details of the error:

The client writes all errors to logger so you don't need to do this.

Full Cocos2d-x C++ example¶

You can find the Cocos2d-x C++ example here

Client reference¶

You can find the C++ Client Reference here.

When I was starting Cocos2d-x, I found it very very hard to find supporting documentation and tutorials for beginners. There are some but most of them are outdated and/or unapplaicable to version 2.0.So I decided to make my own tutorial for the latest version of Cocos2d-x and Android SDK. Now, let's get started. We need to set up a few things first before we can actually work on a cross-platform mobile game.

The COCOS2D-X Library

In order for us to make a cross-platform game, we need to get the Cocos2d-x library and install in your Mac.

1. Download the library here. The link will take you directly to the official Cocos2d-x download, so just save the ZIP file when you are prompted. NOTE: I am using Cocos2d-x v2.0.4 for this tutorial.

Photoshop cs6 serial numbers for mac. There are numerous adobe Photoshop CS6 serial numbers and keygen which are available on the internet but since the use of such hacking tools has been very limited. Use the given Serial Key of Adobe Photoshop CS6. Adobe Photoshop CS6 Serial Key For Windows: 1325-1009-9360-7441-3800-8396 1325-1004-0648-4659-0595-7342 1325-1000-3965-7421-2700-8520. Adobe Photoshop CS6 Crack + Serial Number 2018 Windows + MAC Adobe Photoshop CS6 Crack is most fit and Adobe's pioneer picture adjusting programming. Over the span of late decades, Adobe Photoshop has transformed into the key choice of visual designers and Professional Photographers.

2. Unpack the ZIP file to a location of your choice. I recommend putting it in an easily accessible place. Rename it as you wish but it would be better to just leave it be once you unpacked it. For this tutorial, we will assume the path to which the library is located would be /Users/LGDev/Documents/cocos2d-x and I'll refer to this as the Cocos2d-x Root.

3. Now open up the Terminal and change the directory to the Cocos2d-x Root using the cd command. Like so:

4. When inside the Cocos2d-x Root run the install-templates-xcode.sh using the sudo command, like so:

You might be asked for a password so just enter your password if you are asked. You might need admin permission to continue.

5. Once that is done, open up Xcode and create a new project. On the left side of the dialog box, you will find cocos2d-x listed under iOS. Select it and you will are all the templates installed for cocos2d-x. Choose cocos2dx and click Next. Xcode will now make your new cocos2d-x project.

6. If you want, try to run it and you will see the Hello World application pop up on the screen.

The Hello World project in action.

You might also want to go back to the Terminal and edit your .bash_profile. Type in this command:

AutoFormat Options #3 – Alt Code Keyboard ShortcutsThe above two methods are the correct way to insert bullets. You will see the AutoCorrect options when you type like this.Choose 'Control AutoFormat Options' to change the settings,if you don't want Word, Outlook or PowerPoint to create bullets automatically. Word for mac shortcut. Because it will create bullets for each new line automatically.

It will open up the GNU NANO tool. Find an empty line and export a variable pointing to your Cocos2d-x Root.

7. Once that is done, the Cocos2d-x library is now installed on your machine. The next step is to set up your machine for Android development. To do this, we must install the Android SDK and NDK on your machine, as well as the IDE we're going to use, which is Eclipse.

The Android SDK and NDK

Before proceeding, check if your JDK is installed and is greater than 1.6.0. Open up the Terminal and type in:

You should see something like this:

Once you've checked it, you can start setting up your Mac for Android Development.

1. Get the SDK from here.

2. Once the download has been completed, unpack it on a safe place. For this tutorial, we will assume our SDK is on /Users/LGDev/Documents/AndroidSDK and I'll refer to this as the Android SDK Root.

Cocos2d For Mac Download

3. Go to the Android SDK Root, tools folder, and run the android executable file. This will open up the Android SDK and the Android Manager. Alternatively, you can run the android executable file via the Terminal.

Locate the tools folder and open the Android Manager App

4. On the Android Manager, check Tools and all the Android API you want to work on. You might also want to check Extras. Once that is done, click Install Packages… and you will be presented by a dialog screen. Click Accept All and then Install to start the installation. Wait for the installation to finish.

Cocos2d For Mac Installer

Use the Android Manager to download the Android API you need.

5. Next, get the Android NDK from here. Download the Mac version of the NDK. Once the download is done, unpack the NDK and put it in an accessible place, preferably in the same folder as the Android SDK Root. For this tutorial, we will assume the Android NDK is on /Users/LGDev/Documents/AndroidNDK and I'll refer to this as the Android NDK Root.

6. Download Eclipse from here. The Classic Version is the most recommended one. I am using Helios but you can use the latest one (Juno as of writing).

Cocos2d For Mac Tutorial

7. Unpack Eclipse and run it. You might want to put it on the Desktop or on the Dock for easier access.

8. On Eclipse, go to Help > Install New Software… and you will see a new window pop up.

9. We'll first set up Eclipse so that it can read C++ codes. On the Install window, on the Work With box, select your Eclipse version.

10. Wait for the list to be populated and select Programming Languages > C/C++ Development Tools and click Next.

11. Follow the process until it is done. You will have to restart Eclipse once the plugins are installed for it to take effect. Do so and proceed.

Cocos2d

If you use ndk-build then add following to your Android.mk file:

Android uses a permissions system which determines which platform services the application will request to use and ask permission for from the user. The client uses the network to communicate with the server so you must add the 'INTERNET' permission.

Setup for CMake projects¶

Open for edit your CMakeLists.txt file and find following existing code:

add next code before:

At bottom of your CMakeLists.txt file add following:

T racks for mac. The T-RackS 5 MAX collection for Mac/PC comprises 38 superb modules that range from compressors and limiters to equalizers, channel strips, reverbs and more. All the gear has been modeled after some of the most sought-after production equipment of all time and chosen for its unique sonic character. T-RackS 5 has evolved into the most powerful mix and master modular system ever, offering maximum processing versatility, an improved audio engine, 4 new processors for a total of 38 high-quality modules on a flexible 16 processor series/parallel chain, a comprehensive broadcast ready professional metering tool section, a new completely redesigned, smart single-window GUI as well as an album.

Setup for Visual Studio projects¶

In Project Settings add following:

  1. Add NAKAMA_COCOS2D_SDK/include to C/C++ > General > Additional Include Directories
  2. Add folder to Linker > General > Additional Library Directories:
    • NAKAMA_COCOS2D_SDK/libs/win32/v140 - for VS 2015 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v140 - for VS 2015 x64
    • NAKAMA_COCOS2D_SDK/libs/win32/v141 - for VS 2017 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v141 - for VS 2017 x64
    • NAKAMA_COCOS2D_SDK/libs/win32/v142 - for VS 2019 x86
    • NAKAMA_COCOS2D_SDK/libs/win64/v142 - for VS 2019 x64
  3. Add all .lib files located in above folder to Linker > Input > Additional Dependencies
  4. Add sources from Classes/NakamaCocos2d to your Visual Studio project.

Usage¶

Include nakama helper header.

Initialize logger with debug logging level.

The client object is used to execute all logic against the server.

Note

By default the client uses connection settings '127.0.0.1' and 7350 port to connect to a local Nakama server.

Tick¶

The tick method pumps requests queue and executes callbacks in your thread. You must call it periodically (recommended every 50ms) in your thread.

Cocos2d Macos

Without this the default client and realtime client will not work, and you will not receive responses from the server.

Authenticate¶

With a client object you can authenticate against the server. You can register or login a user with one of the authenticate options.

To authenticate you should follow our recommended pattern in your client code:

1. Build an instance of the client.

2. Authenticate a user. By default Nakama will try and create a user if it doesn't exist.

Tip

It's good practice to cache a device identifier on Android when it's used to authenticate because they can change with device OS updates.

In the code above we use authenticateDevice() but for other authentication options have a look at the code examples.

Sessions¶

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a NSession object.

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

A full example class with all code above is here.

Send requests¶

When a user has been authenticated a session is used to connect with the server. You can then send messages for all the different features in the server.

This could be to add friends, join groups, or submit scores in leaderboards. You can also execute remote code on the server via RPC.

All requests are sent with a session object which authorizes the client.

Have a look at other sections of documentation for more code examples.

Realtime client¶

The client can create one or more realtime clients. Each realtime client can have it's own event listener registered for responses received from the server.

Note

The socket is exposed on a different port on the server to the client. You'll need to specify a different port here to ensure that connection is established successfully.

Don't forget to call tick method. See Tick section for details.

You can use realtime client to send and receive chat messages, get notifications, and matchmake into a multiplayer match. You can also execute remote code on the server via RPC.

To join a chat channel and receive messages:

There are more examples for chat channels here.

Handle events¶

A realtime client has event handlers which are called on various messages received from the server.

Event handlers only need to be implemented for the features you want to use.

CallbacksDescription
onDisconnectHandles an event for when the client is disconnected from the server.
onNotificationReceives live in-app notifications sent from the server.
onChannelMessageReceives realtime chat messages sent by other users.
onChannelPresenceIt handles join and leave events within chat.
onMatchStateReceives realtime multiplayer match data.
onMatchPresenceIt handles join and leave events within realtime multiplayer.
onMatchmakerMatchedReceived when the matchmaker has found a suitable match.
onStatusPresenceIt handles status updates when subscribed to a user status feed.
onStreamPresenceReceives stream join and leave event.
onStreamStateReceives stream data sent by the server.

Logging¶

Client logging is off by default.

To enable logs output to console with debug logging level:

Errors¶

The server and the client can generate logs which are helpful to debug code.

Cocos2d For Mac Os

To enable client logs see Logging section.

In every request in the client you can set error callback. It will be called when request fails. The callback has NError structure which contains details of the error:

The client writes all errors to logger so you don't need to do this.

Full Cocos2d-x C++ example¶

You can find the Cocos2d-x C++ example here

Client reference¶

You can find the C++ Client Reference here.

When I was starting Cocos2d-x, I found it very very hard to find supporting documentation and tutorials for beginners. There are some but most of them are outdated and/or unapplaicable to version 2.0.So I decided to make my own tutorial for the latest version of Cocos2d-x and Android SDK. Now, let's get started. We need to set up a few things first before we can actually work on a cross-platform mobile game.

The COCOS2D-X Library

In order for us to make a cross-platform game, we need to get the Cocos2d-x library and install in your Mac.

1. Download the library here. The link will take you directly to the official Cocos2d-x download, so just save the ZIP file when you are prompted. NOTE: I am using Cocos2d-x v2.0.4 for this tutorial.

Photoshop cs6 serial numbers for mac. There are numerous adobe Photoshop CS6 serial numbers and keygen which are available on the internet but since the use of such hacking tools has been very limited. Use the given Serial Key of Adobe Photoshop CS6. Adobe Photoshop CS6 Serial Key For Windows: 1325-1009-9360-7441-3800-8396 1325-1004-0648-4659-0595-7342 1325-1000-3965-7421-2700-8520. Adobe Photoshop CS6 Crack + Serial Number 2018 Windows + MAC Adobe Photoshop CS6 Crack is most fit and Adobe's pioneer picture adjusting programming. Over the span of late decades, Adobe Photoshop has transformed into the key choice of visual designers and Professional Photographers.

2. Unpack the ZIP file to a location of your choice. I recommend putting it in an easily accessible place. Rename it as you wish but it would be better to just leave it be once you unpacked it. For this tutorial, we will assume the path to which the library is located would be /Users/LGDev/Documents/cocos2d-x and I'll refer to this as the Cocos2d-x Root.

3. Now open up the Terminal and change the directory to the Cocos2d-x Root using the cd command. Like so:

4. When inside the Cocos2d-x Root run the install-templates-xcode.sh using the sudo command, like so:

You might be asked for a password so just enter your password if you are asked. You might need admin permission to continue.

5. Once that is done, open up Xcode and create a new project. On the left side of the dialog box, you will find cocos2d-x listed under iOS. Select it and you will are all the templates installed for cocos2d-x. Choose cocos2dx and click Next. Xcode will now make your new cocos2d-x project.

6. If you want, try to run it and you will see the Hello World application pop up on the screen.

The Hello World project in action.

You might also want to go back to the Terminal and edit your .bash_profile. Type in this command:

AutoFormat Options #3 – Alt Code Keyboard ShortcutsThe above two methods are the correct way to insert bullets. You will see the AutoCorrect options when you type like this.Choose 'Control AutoFormat Options' to change the settings,if you don't want Word, Outlook or PowerPoint to create bullets automatically. Word for mac shortcut. Because it will create bullets for each new line automatically.

It will open up the GNU NANO tool. Find an empty line and export a variable pointing to your Cocos2d-x Root.

7. Once that is done, the Cocos2d-x library is now installed on your machine. The next step is to set up your machine for Android development. To do this, we must install the Android SDK and NDK on your machine, as well as the IDE we're going to use, which is Eclipse.

The Android SDK and NDK

Before proceeding, check if your JDK is installed and is greater than 1.6.0. Open up the Terminal and type in:

You should see something like this:

Once you've checked it, you can start setting up your Mac for Android Development.

1. Get the SDK from here.

2. Once the download has been completed, unpack it on a safe place. For this tutorial, we will assume our SDK is on /Users/LGDev/Documents/AndroidSDK and I'll refer to this as the Android SDK Root.

Cocos2d For Mac Download

3. Go to the Android SDK Root, tools folder, and run the android executable file. This will open up the Android SDK and the Android Manager. Alternatively, you can run the android executable file via the Terminal.

Locate the tools folder and open the Android Manager App

4. On the Android Manager, check Tools and all the Android API you want to work on. You might also want to check Extras. Once that is done, click Install Packages… and you will be presented by a dialog screen. Click Accept All and then Install to start the installation. Wait for the installation to finish.

Cocos2d For Mac Installer

Use the Android Manager to download the Android API you need.

5. Next, get the Android NDK from here. Download the Mac version of the NDK. Once the download is done, unpack the NDK and put it in an accessible place, preferably in the same folder as the Android SDK Root. For this tutorial, we will assume the Android NDK is on /Users/LGDev/Documents/AndroidNDK and I'll refer to this as the Android NDK Root.

6. Download Eclipse from here. The Classic Version is the most recommended one. I am using Helios but you can use the latest one (Juno as of writing).

Cocos2d For Mac Tutorial

7. Unpack Eclipse and run it. You might want to put it on the Desktop or on the Dock for easier access.

8. On Eclipse, go to Help > Install New Software… and you will see a new window pop up.

9. We'll first set up Eclipse so that it can read C++ codes. On the Install window, on the Work With box, select your Eclipse version.

10. Wait for the list to be populated and select Programming Languages > C/C++ Development Tools and click Next.

11. Follow the process until it is done. You will have to restart Eclipse once the plugins are installed for it to take effect. Do so and proceed.

12. Go back to Help > Install New Software… and you will be presented back to the Install window.

13. This time, we will install Android plugins. Click Add and put https://dl-ssl.google.com/android/eclipse/ on the Location box. Give it a distinct name like Android for Eclipse.

14. Wait for the list to be populated and click Select All. Click Next and follow the instructions in the wizard to install the Android plugins. You will have to restart Eclipse afterwards. Do so and proceed.

15. We're now ready to start developing cross-platform games using Cocos2dx. However, we need to do a bit of a tweak just so that everything goes smoothly. Open up the Terminal and enter the following commands:

Cocos2d For Android

The GNU NANO Tool will show up. Find an empty line and add these lines:

Don't forget to change the values to your Android SDK Root and Android NDK Root. We will need these variables later on.

We now have set up your Mac for cross-platform development using Cocos2dx. The next step is creating a cross-platform project that synchronizes on both Xcode and Eclipse, with Cocos2dx of course.

I hope you found this tutorial useful. I will link this to the next step Creating a cross-platform project on Eclipse and Xcode. Stay tuned!





broken image