cocos2d-x 3.7 Initialize with hwnd - cocos2d-x

I'm going to make some tools for game using cocos2d.
but i couldn't find any function to bind hwnd as cocos2d render window.
isn't there any functions like GLView::setHwnd or
some way to archieve what i want?
my cocos2d-x version is 3.7.

The built in GLView is not going to support being initialized with an external hwnd.
However the Cocos2d-x director is initialzied with a user created GLView, so all you need to do is specialize GLView / GLViewImpl, create and initialize your specialized GLView and pass that when initializing Cocos:
auto director = Director::getInstance();
auto glView = MyGLView::create();
glView->initWithExternalHWND(_hwnd);
director->setOpenGLView(glView);
auto scene = MyScene::create();
director->runWithScene(scene);

Related

In WinRT MVVM Using Prism how do I listen for a SetProperty notification?

I am using Prism for Windows Runtime to help with my MVVM implementation. It has a built in SetProperty command for properties. How do I listen for a property change from within the View Model to make something else happen?
You can handle INotifyPropertyChanged.PropertyChanged event and check the name of the property. If you want to avoid string comparisons - you can define a new event and raise it for specific property. It can either be a regular CLR event or an EventAggregator one if you want to broadcast it to any interested listeners in the app.

Cocos2d-x: deprecated class Object

I'm trying to learn from a sample source code (Since the framework is utterly undocumented) that was written for cocos2d-x 3.0alpha, the code is using the deprecated class "Object", I'm trying to port the code to version 3.0 but I'm not sure which class be used instead of Object.
Do you have any idea?
https://github.com/OiteBoys/Earlybird/blob/master/Earlybird/Classes/Number.h
Edit: pretty sure the class I need is Ref
Current issue I'm trying to solve is finding the equivalent of EGLView::getInstance()
Edit II: GLView::create("view"); seems to be it.
Yes, you need Ref. Here are the release notes for Version 3.0. It describes this here. This changes was done since C++ doesn't have and doesn't need a base object. Object was created for that reason originally but now deprecated.
https://github.com/cocos2d/cocos2d-x/blob/v3/docs/RELEASE_NOTES.md
For EGLView create a quick sample "Hello World" project using the cocos command-line tool and have a look at AppController.mm, RootViewController.mm and AppDelegate.cpp. These have changed a good deal for version 3.0+.
Edit: based upon your edit look at: bool AppDelegate::applicationDidFinishLaunching()
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}

sound effects are not playing in my game

I am developing a game for windows phone. The target version of game is 7.1 and 7.1 games and apps will be supported on wp8 devices.
Here is my code:
public SoundEffect l1;
public SoundEffectInstance level1sound;
l1 = contentManager.Load<SoundEffect>("sound/level1");
level1sound = l1.CreateInstance();
level1sound.IsLooped = true;
level1sound.Play();
Gaming sounds are working fine in simulator of 7.1 but when I deploy on wp8 device nothing works.
How to fix this issue?
If you develop Silverlight game, you must call FrameworkDispatcher.Update() method in every frame to dispatch messages that are in the XNA Framework message queue
sound file properties should set to soundeffect type

starling atf textures not displaying

So i'm running air 3.7, the latest starling frameworks, added -swf-version=20 -target-player=11.7 in compiler arguments and running the code
[Embed(source="/assets/wtf4.atf", mimeType="application/octet-stream")]
private static const why:Class;
var data:ByteArray = new why();
var texture:starling.textures.Texture = starling.textures.Texture.fromAtfData(data);
var image:Image = new Image(texture);
addChild(image);
if I'm using the starling atf that came with the framework demo it works fine, but whenever i try to display my own png that I create in photoshop converted into atf it gives me a error saying
ArgumentError: Error #3677: Texture decoding failed. Internal error.
The image I'm trying to convert into atf is just a red square png with 512x512 sizes with the compiler arguments: png2atf -c -i example.png -o example.atf. I'm not sure whether my flash builder isn't setup to decode atfs or if i'm creating the atfs wrong for some reason, if someone could shed some light on this it would be awesome!
When creating the .atf, did you created mipmaps also? If not, you need to set the second argument of the Texture.fromAtfData() function to false - don't use Mipmaps.
From Starlign wiki:
"If you omit mipmaps, you must set the parameter “useMipMaps” of the “Texture.fromAtfData()” method to “false”! Otherwise, you'll get a run-time error."
http://wiki.starling-framework.org/manual/atf_textures
The latest version of ATF requires AIR 3.8 (which is currently in beta). You need to download the AIR installer, and the latest AIR SDK. More details here: http://forum.starling-framework.org/topic/error-3677-texture-decoding-failed-internal-error

cocos2d-x c++ -> java for android

Currently I'am developing a game using cocos2d-x.
Of course, for multi-platform use.
basically I use a xcode for coding and development.
I want to attach IAP(In app purchases) separately to each coding for iPhone and Android
Problem to try to call a function of a certain class in Android that did not work.
Sources include the following:
cpp side
MyClass::invoke_init()
{
JavaVM* jvm = JniHelper::getJavaVM();
JNIEnv* env;
jvm->GetEnv((void **) &env, JNI_VERSION_1_2);
jclass cls;
jmethodID method;
cls = env->FindClass("com/joycestudios/game/SampleActivity");
method = env->GetMethodID(cls, "initFunc", "()V");
env->CallVoidMethod(cls, method);
}
java side
public class SampleActivity extends Cocos2dxActivity
{
public void initFunc()
{
Log.v("LOG_INFO", "initFunc()");
}
}
The first test as follows: I'm in progress.
build from xcode and build from build_natvie.sh and last build from eclipse.
But after run on eclipse, Just black screen and shuts down.
How to call a function of a java class?
What I looked at several samples, including also analyze the problem, I do not see any problems?
Can you tell if you find any error log?
First check if your game is working fine on android..
Den we can have a look how to call the function.
Generally for calling native method I use MessageJni class available in Cocos2d-x library.
I create my methods in MessageJni class which calls for native methods.
Its easy and convenient way of calling native methods.
Just google using MessageJni class. It will ease your work.
:)