SpriteBuilder image file not found - ios

I have added a .png image in sprit builder resource folder and I have published it.
I see the added image in sprite builder all folder in Resources under Published-IOS.
Here I have tried to access the added image in following ways.
_hero.spriteFrame = [CCSpriteFrame frameWithImageNamed:#"Down.png"];
[_hero setTexture:[CCTexture textureWithFile:#"Game/Down.png"]]
But none of these methods are working.
it show error in log as.
-[CCFileUtils fullPathForFilename:contentScale:] : cocos2d: Warning: File not found: Down.png
Please help me with this to resolve.Am a newbie using this sprit builder.

Change #"Down.png" to #"Resources/Down.png" because you have to include the folders created in SpriteBuilder for any references to resource files managed by SpriteBuilder.
Likewise if you had some.ccb in a subfolder named "Levels" you'd have to load it with the string #"Levels/some.ccb".

Related

How do I put custom image on 3D Sphere in ARCore

The following is my code for building a 3D Earth and showing it:
com.google.ar.sceneform.rendering.Texture.Builder builder= com.google.ar.sceneform.rendering.Texture.builder();
builder.setSource(context,R.drawable.earth);
builder.build().thenAccept(texture ->
MaterialFactory.makeOpaqueWithTexture(context, texture).
thenAccept(material -> {
earthSphereRenderable =
ShapeFactory.makeSphere(0.1f, new Vector3(0.0f, 0.0f, 0.0f), material);
Toast.makeText(context,"All done",Toast.LENGTH_SHORT).show();})
);
The Toast message is coming but I am not able to see any object. Please note that R.drawable.earth is the Earth.jpg file that I put in there, which I want to show in AR.
Here is where I am rendering it
cornerNode = new Node();
cornerNode.setParent(this);
cornerNode.setLocalPosition(localPosition);
cornerNode.setRenderable(earthSphereRenderable);
Moreover, if I replace makeOpaqueWithTexture with makeOpaqueWithColor and but color as Red then the whole thing is working fine (i.e. I can see the sphere)
What must I change here in order to be able to see the sphere with Earth's texture on it?
At this time Google Sceneform 1.8 supports 3D assets in the following formats: .obj, .glTF for which animations not supported) and .fbx with or without animations. Supported textures' formats are: .mtl, .bin, .png and .jpg.
To import a new 3D asset with textures follow these steps:
Verify that your project's app folder contains a sampledata folder. To create the folder, right-click on the app folder in the Project window, then select New > Sample Data Directory.
The sampledata folder is part of your Android Studio project, but its contents will not be included in your APK. Copy your 3D model source asset file (.obj, .fbx, or .gltf), and all of its dependencies in any of the following formats:
.mtl
.bin
.png
.jpg
into the sampledata folder.
Do not copy these source files into your project's assets or res folder, as this will cause them to be included in your APK unnecessarily. Right click the 3D model source asset and select Import Sceneform Asset to begin the import process.
The values are used by the sceneform.asset() entry in the app's build.gradle, and determine where the .sfa and .sfb – ascii and binary asset definition – files (as well as their corresponding texture files .sfm) will be generated in your project. If you're importing a model for the first time, use the default values.
Hope this helps.
Ok, I got the answer to this. It does not accept jpg files but it accepts png files. Weird stuff!

List of files in flutter

I have images and I want to load them to my appplication.
my_app/lib/... - here my source files
my_app/assets/images/... - here my images
I need to get list of files in assets/images/ and after that show some of them (according to other logic)
I'm trying this
final dir = Directory("assets/images/");
print(dir.existsSync()); // <---- it also print: false
var files = dir.listSync().toList();
files.forEach((e) => list.add(MyImageItem(e.path)));
The problem is: I recieve exception
FileSystemException: Directory listing failed, path = 'assets/images/'
(OS Error: No such file or directory, errno = 2)
I've tried different ways: assets/images/, images/, images and so on
My pubspec.yaml
flutter:
assets:
- assets/images/
- assets/
When I create Image directly all is fine
new Image(image: AssetImage("assets/images/cat.png"))
I knew that previously (month ago) each resource has to be declared in pubspec.yaml directly, but now assets/images/ is ok.
I can load file by direct path. Why I can't access a directory? How to get list of files in directory to get them from my code?
When you add files to your assets, it means that you already know their paths.
Store all the images paths in a list and access them whenever you need.
For example if you have 3 images in
your_app/assets/images/image1.jpg
your_app/assets/images/image2.jpg
your_app/assets/images/image3.jpg
create a list and store all of them like:
List<String> imagePaths = ['assets/images/image1.jpg', 'assets/images/image2.jpg', 'assets/images/image3.jpg'];
and for example if you want to access your first image, use
AssetImage(imagePaths[0])
I keep a json file inside assets which records the file tree of assets folder.
When file list is needed, I just read from the json file.
Such json file can be easily generated by code.
However, this does not solve your problem directly when u have 5-10k images.
Only one json file might be too large to read.
Images should be grouped and recorded in separated json files.

Resource Directory Path Issue in iOS

3.2 for developing a game.I have developed game in android but facing a problem in iOS i.e
I am facing problem to read resource images.In my game have 3 stages "Simple","Medium" and "Hard".I have put images on the following path
# "Simple/1.png","Medium/1.png","Hard/1.png"
# "Simple/2.png","Medium/2.png","Hard/2.png"
# ------------------------------------------
# ------------------------------------------
# "Simple/n.png","Medium/n.png","Hard/n.png"
In android getting correct image by using full path of image.
But in iOS it is not working.
How i can fetch image of same name from different directory in iOS.
You should probably use FileUtils::addSearchPath() and add "Simple", "Medium" or "Hard", depending on the game stage and then you can use just "1.png" to refer to the file from various Cocos2d-x APIs.
landge,
Please try this:
See my screenshot using cocos2d-x-3.6
http://prntscr.com/7zwty9
It shows Xcode with 3 files with the same name 1.png in different absolute directories: hard/medium/simple.
vector<string> searchPaths = fu->getSearchPaths();
fu->addSearchPath("res/medium");
CCLOG("fpff = %s", fu->fullPathForFilename("1.png").c_str());
This is the console output:
fpff = /Users/javier.fuchs/Library/Developer/CoreSimulator/Devices/68F9EE6B-2829-420E-9359-00EC30C6372D/data/Containers/Bundle/Application/E586FE31-AFC2-4052-9826-9B27AA75182A/MyCppGame iOS.app/res/medium/1.png
Please make sure where is the file, and take a look of the full path, inside the project.
There is no guaranty with search paths, even if you doing:
auto& list = fu->getSearchPaths();
for( const auto &item : list) {
CCLOG("%s", item.c_str());
}
You will see that adding a relative path that does not exist, the relative path will be included anyway.

SKTexture: Error loading image resource

This seems to work perfectly fine:
and when I created a new project with exactly the same thing, just new images, it doesn't work:
I even tried
var mainChartxt = SKTexture(imageNamed: "mainC.png")
and it still gives me the same error:
SKTexture: Error loading image resource: "img/mainC.png"
I tried cleaning the project and deleting the derived data folder and still no luck as the image doesn't show up on the app!
Thanks.
Where / How did you add the image in your project ?
The second syntax (without the path) should be ok. You don't even have to specify .png if that's the file format (but you need to if it something else : .jpg, .jpeg, ...
You might want to check that your asset is "checked" for the target membership. On the right side (Utilities) > File Inspector > Target Membership : check your target (not the tests one if you don't have any tests).
A similar error occurred to me while following a tutorial to develop a game using spritekit.
Error was "SKTexture: Error loading image resource:"imagename""
In my case the path was not set properly.
We can recheck to be sure that the path is always set correctly.

XNA error - file not found

I am working on XNA with XML reading. While I'm debugging the code its shows file not found error, but I added my XML file in Content reference folder. While I'm using this code I got the error.
System.IO.Stream stream = TitleContainer.OpenStream("ProductSchema");
Thanks in advance.
Bharathi.G
Shawn explains this very well in this post: Shawn's blog entry
Try adding the extension:
System.IO.Stream stream = TitleContainer.OpenStream("ProductSchema.xml");
Check whether that file is present in the bin folder where your game .exe file lives (bin\Windows Phone\Debug\Content). If not, then this may be the problem. To solve this :
right click the file >> select property >> change build action to None and copy to output directory to Copy if newer.
This works for me while loading/reading binary files in my game.

Resources