FAQ Database Discussion Community


UIImage to Sprite in cocos2dx?

uiimage,ccsprite,cocos2d-x-3.0
First I save image from URL in document directory: NSURL *imageURL = [NSURL URLWithString:userImage]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"image name.png"]; [UIImagePNGRepresentation(image) writeToFile:savedImagePath atomically:YES];...

Initialized property CCArray is still NULL after new CCArray

cocos2d-x,cocos2d-x-3.0
I have in scene class property in private section like private: CCArray* objects; and in init I initialize objects = new CCArray(); but when I put breakpoint in line below objects is NULL and I don't know why. It crashes when I call objects->count(); Why I cannot initialize property ?...

Cocos2d-x editor for Linux?

linux,ubuntu,editor,cocos2d-x,cocos2d-x-3.0
I'm currently using Ubuntu for developing purposes and in free time I wanted to check out Cocos2d-x. The problem is that there aren't provided any officially supported editors for Linux. Regarding the fact that Cocos2d-x has very poor documentation, I don't think I can use it without a decent editor....

CCScrollView returns one children

cocos2d-x,cocos2d-x-3.0,ccscrollview
I am working on cocos2dx 3.0, and working on cocos2d::extension::ScrollView, getting a strange problem, is the scrollview doesn't return all the Nodes added to it, just returns one child, that too a different one.. See my code below void Characters::setupScroll(){ Size winSize = Director::getInstance()->getWinSize(); if(!scrollView){ scrollView=cocos2d::extension::ScrollView::create(Size(winSize.width*1.0,winSize.height*0.8)); scrollView->setDirection(cocos2d::extension::ScrollView::Direction::HORIZONTAL);...

cocos2dx 3.3 animation implementation

c++,cocos2d-x,cocos2d-x-3.0,cocos2d-android,cocos2d-js
I am new in cocos2dx development.I almost learn all basic level of cocos2dx (version 3.3) in android using cpp language. I showing that there are lots of update over cocos2dx.org. In android I am currently developing the tetris game using cocos2dx version 3.3, I want to know what is the...

Round decimal for a float number

c++,visual-c++,integer,cocos2d-x-3.0
in VC++ I have a float number say 1.32544354353 i.e float num=1.32544354353; I want only first 1 digit after point. i.e 1.3 (not 1.300000000). How can I get this? Please help me... If their is a solution in Cocos2dx thats better(I want this in my cocos2d-x game)

Cocos2dx Android and IOS build

cocos2d-iphone,cocos2d-x,cocos2d-x-3.0
I have downloaded latest version of cocos2d-x from this link. And worked on Visual Studio Environment and finished. Now I am going to build it to Android and IOS for extra processes. What can I do?...

Cocos2dx soundengine issue on Android Lolipop

android,cocos2d-x,android-5.0-lollipop,cocos2d-x-3.0,cocos2d-x-2.x
I am having an issue with Cocos2dx 2.2.6 on Android 5. After playing my game for a little while it starts to severely lag. This does not happen with Android 4. After doing some research many people have said it is a problem with Android 5 working with Cocos2dx's Audio...

Simultaneous touches on scene

touch,cocos2d-x,cocos2d-x-3.0
I am having one problem while working on touches on the screen. I have two modules attached on the screen, on the Left there is a Joystick which has its own touches, and on the right side I have set of Buttons which have its own actions or, touches, both...

How to get the width of a Node?

c++,cocos2d-x,cocos2d-x-3.0
The idea is that I have a parent Node as a container with a bunch of Sprites as children, and that I can have the Node's width include the width of the children, since I'm assuming the size would encompass its children, but it doesn't look like it. I've got...

How to retrieve the visible texture from a png image in cocos2d-x

cocos2d-x,cocos2d-x-3.0
I am making a question answer game in which the answer images are made as sprites from png images. The answer image is like this: I am making rect on the image like this: Rect rect = Rect(answerSprites.at(i)->getBoundingBox().origin.x, answerSprites.at(i)->getBoundingBox().origin.y, answerSprites.at(i)->getBoundingBox().size.width, answerSprites.at(i)->getBoundingBox().size.height); Then i am detecting touch on the rect as...

Use Spine in Cocos2dx

cocos2d-x-3.0
In cocos2dx, I use the class skeletonAnimation to create the skeleton animation which uses the resources exported by spine. We know the class skeletonAnimation is the subclass of node not is sprite. How to do to make the skeleton animation flip the node as it like to use the method...

cc.textureCache.addImage blocking UI

cocos2d-x,cocos2d-x-3.0,cocos2d-js
I want to cache lot of textures in a running scene without blocking it, theoretically cc.textureCache.addImage do caching async if you call it the three arguments. This is not happening. Code: rainOfArrows: { _animFrames:[], loaded: function(){ console.log('>>>>>>>>>>>>>>LOAD!') }, load: function(){ /* Load all animation arrow sprites in memory & generate...

Can I refactor name libcocos2dcpp.so?

android,cocos2d-x,cocos2d-x-3.0,cocos2d-x-2.x
libcocos2dcpp.so is located at path proj.android\libs\armeabi 1) I want to learn to modify how it looks after changing the name "libcocos2dcpp.so" to some "randomname.so" (Intention being, not sure but it might help in protecting my game's source code if people won't know in which thing it is made, I mean...

cocos2d draw something on top of the sprite

cocos2d-x,cocos2d-x-3.0
I am very new to cocos2d. I have read the basic concept of sprite and action. I was wondering after I created a sprite (from an image file). and I want to draw some numbers on the sprite on the fly, is that something doable? or you can not draw...

libcocos2dx resource error: resource directory does not exist

android,eclipse,box2d,cocos2d-x-3.0
Yesterday I tried to add Box2D to my cocos2dx project. One error appeared and I haven't been able to solve it. The error: [2015-03-06 10:41:41 - libcocos2dx] ERROR: resource directory 'C:\devAndroid\cocos2d-x-3.2\cocos2d-x-3.2\SuperCars\cocos2d\cocos\platform\android\java\res' does not exist The point is that the package explorer itself only shows a red exclamation in the project...

cocos2dx-store on andorid issued with path

android,c++,android-ndk,cocos2d-x-3.0
here is my code, I tried different version of cocos2d-x and the newest cocos2d-x-store, which the program runs well on ios device. The problem is when ever i try to complied to android platfrom, it shows Android NDK: WARNING: APP_PLATFORM android-21 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml make: Entering...

Cocos2dx 3.x button sprite [C++]

c++,cocos2d-x,cocos2d-x-3.0
I can't find a way to load the button image from a given .plist file instead of a plain texture. Using Button::create("normal_image.png", "selected_image.png", "disabled_image.png"); or button->loadTextures("normal_image.png", "selected_image.png", "disabled_image.png"); Search for a png and not use the sprite file in the cache. [EDIT] I just want to put a sprite instead...

adding files to all platforms of a cocos2d-x project

cocos2d-x,cocos2d-x-3.0
This is a very basic question, but I have not been able to find the answer anywhere. I just got Cocos 2Dx 3.3, made a new project and built the HelloWorld scene that was generated. It generated projects for all platforms, but I am currently compiling and running the Mac...

Integrating iAd with AdMob displays only black screen

objective-c,admob,cocos2d-x,iad,cocos2d-x-3.0
I am facing issues while combining iAd and Admob in Cocos2d 3.0. The whole screen goes black. I have created a view controller which handles loading of iAd and Admob. Here is my code on pastie.org, I believe required steps to integrate iAd and Admob are known to users reading...

Cocos2d-x: How can I draw a resizing rectangle?

c++,cocos2d-x-3.0
I'm working on a project with Cocos2d-x 3.4 (wonderful framework BTW :) ). I was wondering how I can draw a simple translucence selection, the same selection you can see on Windows ? http://cdn.maximumpcguides.com/windows-7/wp-content/uploads/2010/11/use-translucent-select-rectangle-2.png I tried to use the DrawNode class, but failed to achieve this :'( I hope that...

How to include SimpleAudioEngine to Linux build in cocos2d-x v3.3 project?

linux,cocos2d-x,cocos2d-x-3.0
I'm trying use SimpleAudioEngine in my project. I include the SimpleAudiEngine header to AppDelegate. #include "SimpleAudioEngine.h" When I build my project for Android everything compiles and build is fine. SimpleAudioEngine working is correct. If run build for Linux, I get an error message: fatal error: SimpleAudioEngine.h: No such file or...

CCLabelTTF::setString not accepting white space at start and end of string

c++,windows-phone-8.1,cocos2d-x-3.0,cclabelttf
I'm trying to set value of a label in cocos2d-x. It's not showing spaces if I add them on start or end of string, like label->setString("10 10"); working correctly. But if I use label->setString(" 10"); label->setString("10 "); it only show "10" , spaces are trimmed....

make: *** [obj/local/armeabi/objs/cocos2dcpp_shared/hellocpp/main.o] Error 1

android,eclipse,android-ndk,cocos2d-x,cocos2d-x-3.0
I am trying to port cocos2dx game on android plat from. When I build the project the following message appears Build of configuration Release for project test_pro python /Users/itronix/Documents/Rizwan_Projects/cocos2dx_3_2/workspace/test_pro/proj.android/build_native.py -b release all Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml Android NDK: WARNING:jni/../../cocos2d/cocos/./Android.mk:cocos2dx_static: LOCAL_LDLIBS is always...

Include msgpack in cocos2d-x 3

cocos2d-x-3.0,msgpack
I want to use msgpack with cocos2d-x 3. I add include_directories(msgpack/include) in cocos2d/cocos/CMakeLists.txt. but not found msgpack.hpp. How I can include and compile msgpack with cocos2d?

Setting a custom shader messes up the scale and position of a Sprite

cocos2d-x,cocos2d-x-3.0
I am using a custom shader on cocos2dx 3.1 trying to accomplish an special effect on a sprite used as a background (has to cover the whole screen) However If i do not use the shader, the sprite is perfectly scaled and positioned, but when i do use it its...

How to add a Label to a ProgressTimer's Sprite in Cocos2dx?

c++,cocos2d-x,cocos2d-x-3.0
I'm trying to get a ProgressTimer to work with a Sprite that's got a Label as a child. It seems like only the Sprite and none of its children are being used as the sprite for the progress bar. I've got the label created, added it to the sprite. I...

How To Change A Sprite Image When Tapped

c++,ios,cocos2d-x,cocos2d-x-3.0
I know this is probably one of the easiest questions ever to answer, but I've done some searching and can't seem to find the answer to this... How do I change a sprites image when the user taps on it in Cocos2d-x? The only way I know of is using...