I'm starting to use Cocos2dx and I'm having an issue creating a CCSprite from a .png I have. It's like it couldn't found the image from the resources or it is not compatible, because if I choose another one, it works. I also tried with a jpg and it didn't work, so apparently, it just works with some kind of images.
How can I make an image compatible for the CCSprite?
Thanks
You don't need to add it the project as build-native.sh (or.bat) does that.
The image should be in the folder called 'resources' (which will be in the same folder as 'Classes' and 'Proj.Android'.
When you build you app it will be copied in proj.android/assets so check that it gets put in there after you build.
Related
I'm unable to load an image that I added to a .xcassets file today.
let image = UIImage(named: "slider_star")
print(image) // nil
Other older images from the exact same assets file load just fine (in the exact same spot in code). I can see the image just fine in .xib files, and if I put it in a UIImage in a .xib file it appears just fine in the simulator, too.
I've tried cleaning my build folder, restarting Xcode, using different simulators, and loading it as an Image Literal (can select it from the image list, but simulator crashes when it tries to render the image). I also made sure the target membership is correct, and that the assets file is in copy bundle resources, and that the image files are indeed inside the assets file in Finder. Also all settings for the image set are the same as other working image sets.
Any idea why this is happening?
edit: More things I've tried from suggestions in the comments:
change name from "star" -> "slider_star"
check that the color space of all images are the same as working ones
check that there is no extra white space at the end of slider_star.
also tried making another new image set, and re-using some of the confirmed working images in it, but this also comes back nil. I think this probably rules out any issue with the image files themselves, at least. It's almost like xcode isn't seeing the updates to the .xcassets file, but that's strange because the updates are showing up and working fine in .xib files.
Finally figured this out. This is a fairly large project with multiple targets, and it seems that the code in the target I'm working in is for some reason looking at the .xcassets file from another target (I checked the other xcasset file's target membership, and it's not included in the target I'm working in, so I don't understand why this is happening).
I can work around this by putting my images in the other xcasset file (don't really like this), or specifying the bundle with UIImage(named:in:with:).
If anyone knows why this is happening, I'd love to fix the root issue (maybe it's not an issue, and I'm just not understanding how it's supposed to work). I'll let this sit for 24 hours before accepting this as an answer.
I am new to cocos2D.
As my title says, how can I change my default splash image?
In my project, I removed all of the built-in images (splash image) come with cocos2d when you create a project. Then I ran my app. Why do I still see the built-in image (splash image that i removed) when my project it started?
I tried to find my solution on google but i could not find anything useful.
So, please help me resolve this issue. It may be very useful for a beginner.
I think the file is called 'Default.png', and you replace it with what you want. If you've already deleted the 'Default.png' file, create a new one.
The 'Default.png' should be placed in the root.
Then Build ->Clean All Targets
Create an image 320×480 for portrait mode
Place the following
#define CC_CODE_IDE_DEBUG_SUPPORT 0
at
Appdelegate.cpp
Which is at
Framworks --. runtime-src -->classes folder
Just delete "Default.png" from your resources. And add an image with name Default.png which you want as Splash into your resources.
Thanks
Be sure you replace all the Default files in the Resources folder with your own art. For example:
Default-568#2x.png
Default.png
Default#2x.png
I have used test images for my developing process and now I want to change my test images to another images. so I deleted the whole test image folder and change to new folder. But it still shows old images. How do I remove these reference from old images and use new images?
Clean your project (in the Xcode menu) images are cached when building and never go away when you want them to.
First of all, there is finally NinePatch support for the iPhone, BIG thanks to the Tortuga 22 team for that. Unfortunately for me I have not been able to add their library to my project.
What is NinePatch?
The Tortuga 22 blog post.
The source code at git hub.
If I just drag and drop the source-files into my project I get a ton of "No such file or directory"-errors. If I reference the libNinePatch.a-file as an external framework I get the same result.
What is the proper way of doing this? There are no instructions from their part so I guess there must a fairly straight forward way of doing this.
Thanks in advance.
//Abeansits
I just like to tell everyone still struggling with this that I've uploaded a podspec to CocoaPod's repository.
This means that if your project uses CocoaPods (and why wouldn't it?), you can just add:
pod 'Tortuga22-NinePatch'
To your Podfile and you'll have NinePatch support. (notice it's still not ARC-compatible, pull requests are welcome!)
I know this is an old question, but just to help people that are searching for ninePatch in objective c, I want to inform that the UIImage class from ios 5 on, have a method to do what ninePatch do.
From UIImage reference:
Discussion
You use this method to add cap insets to an image or to
change the existing cap insets of an image. In both cases, you get
back a new image and the original image remains untouched.
During scaling or resizing of the image, areas covered by a cap are
not scaled or resized. Instead, the pixel area not covered by the cap
in each direction is tiled, left-to-right and top-to-bottom, to resize
the image. This technique is often used to create variable-width
buttons, which retain the same rounded corners but whose center region
grows or shrinks as needed. For best performance, use a tiled area
that is a 1x1 pixel area in size.
Availability Available in iOS 5.0 and later.
Declared In UIImage.h
An example of use if you want a image with a fix top:
UIImage* image = [UIImage imageNamed:#"YourImage.png"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(25., 0, 0, 0)]
Hope it help.
You should be able to add the files to your project. Answers to this SO question may help.
Also, be aware that UIImage does provide stretchable images. See -stretchableImageWithLeftCapWidth:topCapHeight: for details. That won't help you if you need to read images in actual nine patch format, perhaps for sharing resources with an Android app, but it's often all that's really needed.
Are you #include-ing the main header file(s) in whichever classes you need them or in the prefix.pch file?
If you download their source package from GitHub, you'll see that they've included an example project, NinePatchDemo. Inspecting this should give you all the information you need.
You'll see that they just dropped the NinePatch Xcode Project into the NinePatchDemo project, under "Other Sources". You can drag and drop the NinePatch project into your own in the same way. You can check the build and target settings to make sure you're including any paths/libraries that you need in order to build.
It looks like you want -all_load -ObjC in Other Linker flags for your target, and if your project folder is at the same level as the ninepatch folder (as in the download from github), you'll also want to set the Header Search Paths on your target to ../NinePatch//**, varying accordingly if you've moved any folders around.
Other than that the only thing I can see is that you will, of course, need to include the headers with #import <TUNinePatch.h>
NinePatchDemo built fine for me, so I can verify that their source does work.
I've got a mysterious problem with images and caching. In my project I've got 20 photos that elegantly fade in and out with a random function that changes up the order a bit.
I found that I didn't like one image in particular, image_1.png and wanted to push it back in the rotation (each time the app starts the images start with image_1.png). So, I swapped the name of image_1.png with that of image_16.png. When I look at image in the project folder and in Resources indeed the images are as they should be but when I run the app its the same old image that starts things out.
I have reset the sim, deleted the app from my iPhone, removed the images from the project and reimported them and still the same image.
Even odder.. I have an image_0.png that is no longer in the project file at all ... its not even on my hard drive.... but it shows up as well.
Do I have a ghost in my Mac or is this just seriously persistent cache?
Clean All Targets
Sounds like a persistent cache.
Let me guess: you have your images in a directory that you add to your project as a reference?
Yeah, that stuff's weird and buggy. Even in the latest xcode. I find it helps to recreate the folder with the new contents in a different place, then remove the old one from the project and add the new one. Perhaps even closing the project before re-adding.
XCode sucks.