GithubHelp home page GithubHelp logo

tea18andlife / cocos2d-x_cpp_to_java_via_jni_samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elliotmebane/cocos2d-x_cpp_to_java_via_jni_samples

0.0 1.0 0.0 68.72 MB

Samples of communication to Java from C++ via JNI. Using Cocos2d-x v3.2 and newest (non-deprecated) approaches.

CMake 0.13% C++ 1.02% Python 0.11% Java 0.17% Makefile 97.80% Objective-C 0.03% Objective-C++ 0.17% C 0.01% C# 0.56%

cocos2d-x_cpp_to_java_via_jni_samples's Introduction

Cocos2d-x_CPP_to_Java_via_JNI_Samples

Samples of communication to Java from C++ via JNI. Using Cocos2d-x v3.2 and newer (non-deprecated) approaches.

Content Notes

This sample demonstrates the use of JNI for C++ to Java communication with Cocos2d-x v3.2. The foundation of these samples are based on these posts:

It was a challenge to get C++ to Java communication working with the latest version of Cocos2d-x because Cocos2d-x v.3.0 introduced significant changes and as a result a lot of the tutorials I found on this topic were outdated or incomplete. I prefer complete working samples over tutorials when I'm learning new code concepts. I hope this working sample helps make things a lot easier for you than they were for me as I tried to figure this stuff out! This sample has been compiled and tested but please notify me if you discover any problems.

JNI communication
Buttons that call methods in Java (and often launch native Java dialogs).

  • Calling a Java method from C++
  • Passing an int from C++ to Java
  • Passing an int from C++ to Java method and receiving a String return
  • Passing a String and an int from C++ to Java method and receiving a String return
  • Calling a Java method from C++ to detect Latitude/Longitude, receiving a Java Double Array return, converting it to a C++ vector.
  • Calling a Java method to launch a URL in the native device web browser. Implementation based on solution here:
    http://discuss.cocos2d-x.org/t/how-to-open-url/8440/5

Java Dialog
Resources that helped construct a solution to launch native Java dialogs:

Menu

Dev/Test environment

  • Cocos2d-x 3.2
  • Mac/OSX 10.9.4
  • Eclipse Luna 4.4.0
  • Google Nexus 4 phone
  • Android 4.4.2
  • (XCode6.0 Beta)*
    * Tested in XCode iPhone simulator to verify cross-platform compilation. Android-exclusive conditionals are verified. When publishing on iOS no dialog launcher menu nor dialogs are displayed.
I haven't made a sample of communication from Java to C++, but I may apply the info from Nguyen's second post and make a sample.
http://stnguyen.com/cocos2d-x/call-cpp-functions-from-java.html

Elliot Mebane
http://www.roguish.com/blog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.