Interact with Cocos2d-x Scene at android / ios native window - android

I'd like to know if Its possible to interact with Cocos2d-x Scene?
Like if I press the button, I can call a method inside Cocos2d-x, for example to start an animation.
If yes, please provide me a sample.

Yes, it's possible.
So on iOS: it's very simple, you just need to import the C++ header file in your objective c(mm file) and call. You might need to save the instance somewhere. This still applies to cocos2d-x - Calling C++ method from Objective C
Android: You need to define JNI function on C++ side and call from java.
Please refer this link : http://stnguyen.com/cocos2d-x/call-cpp-functions-from-java.html

For exchanging information between native layer and cocos2d-x versions 3.x and higher you can use this project:
https://github.com/alfonsocejudo/EasyNDK-for-cocos2dx3
It works well for Android, iOS and OSX.

Related

How to create a simple app from C++ source code

I have written a very basic program in C++. It only interacts with the user via text from the console.
How can I turn this into an app for my android phone? I just want to do the exact same thing, interact via boring text in a black screen (no graphs, no fancy interface, no nothing)
Is there a simple way to achieve that? I was told that I should translate my program into Java, and then go from there; is that the only way, or better, the simplest way?
As far as I know, you will need a Java UI even for "boring text in a black screen". (The project https://github.com/jraska/Console looks like it might help with that. But note I haven't used it, can't vouch for how it works, and might be mistaken about what it does.)
But you probably don't need to translate absolutely all your C++ code to Java. The official Android Developer page https://developer.android.com/studio/projects/add-native-code describes how to include C++ code into an Android app, using the Java Native Interface (JNI). You will need to provide interface functions using JNI so that the Java code can call the C++ functions. And you may need to generalize how your C++ code handles input and output, e.g. to use streams or strings instead of std::cin and std::cout directly.

How to call a C function from a react-native code?

I have developed a small android application using react-native. For what it was developed, it works fine. Now to accommodate a small requirement, we need to call a library written in C. I am not sure if there will be a way to call the C code from JavaScript! But I still wanted to ask you all.
Is there a way to do this from react-native? Like I want to call some functions in the C library. If this possible, could you please suggest how? How could I start to test a very basic setup?
You are going to have to write some native code, search for how to call a C lib on Android, then look for react native way to link a native code with a js call.
Native Module link https://facebook.github.io/react-native/docs/native-modules-android.html
StackOverflow question on how to run c/cpp code on android how to use c/cpp library/functions in android
Basically it includes 3 parts.
JavaScript to Java or Kotlin
check out React Native's guide to Android Native Module.
Java or Kotlin to C
Calling C functions from Java is enabled with a mechanism called Java Native Interface (JNI) . check out how to add C and C++ code here.
see more here https://thebhwgroup.com/blog/react-native-jni

Android NDK develop method

I'd like to make a library for Android with C++.
Normally there is no problem with function calls via JNI.
However, there will be many approaching if both Android(app) and C++(library) need same class(or data structure) definition.
What is the best approaching?
Is there any reference or example?

Native Code Generation in Titanium

How is native code generated in Titanium ?? I have read the documentaion on the internet and from it i can only understand the high level architecture but i need more details about the in depth working. For eg. when we create a button in Titanium using Ti.UI.createButton() how is this binded with native code and how do we get the same button as we get using native code.
Is UIButton object created and returned (talking only abt iOS) or the execution flow is different ? Also where should i look in the native code to for better understanding ?
First of all, how it works is different for each platform, so it is impossible to generalize effectively since the platforms are so specific.
For iOS Titanium uses native bridge wrapper objects called a KrollObject. These proxy objects form a bridge from a Javascript object to the native object in native code. For your UIButton use-case, the UIButton is created but is not returned to the Javascript, you control it through the Kroll bridge. (As a side note, Kroll is the process of refining the material titanium, punny).
Really you dont need to know the really intrinsic details of how it works to write modules, especially since it requires a huge amount of native platform knowledge (in which case theres no reason for you to use titanium).
Here is a great video on how it all works from the last Codestrong. If you really want to know how garbage collection and lifecycle of objects works study this video.

100% Native C Application on Android?

Is there anyway I could write 100% native C code for Android? I know there are ways to write some C code inside Java code, but I don't know any Java and I hate Java anyway.
Is there anyway I could write pure C code that will run under Android?
There is, as of Android 2.3: NativeActivity. But you don't get access to any of the niceties of Android's Java libraries; you're on your own in the wild west. This is really intended for people writing high-performance games.
Yes, there is support for writing completely native activities. You can check out the native-activity sample application.
I would not recommend this path, though, as in my experience applications that are heavy in NDK code are very difficult to debug. I would rate the Android native debugging experience as lacking.
Edit - one caveat is that you will still be doing plently of Java--just through the JNI.
Might be more trouble than it's worth, you could possibly write your logic in C code and import that to java using extern or external (I forget which now) and then do the GUI in java. There's really no point to using straight C in android unless you want to REALLY optimized your logic. Most of the calls you can make are wrapped anyways so you would have to make those calls to access certain things on an android device. Long story short : not a good idea unless you need faster logic.
You can write most of the application in C around a NativeActivity. However, some Android features can only be used from Java, so you'll need to use JNI instead of pure native. See the official overview.

Categories

Resources