-
Hi folks, I've created a new Axmol project. To do so, I used the documentation found here:
I created the project with the following command template:
and then built it for iOS using:
I then opened the generated Xcode project, compiled it, and successfully ran it on my iPhone. Now, I'd like to add an image file to the project and display it as a Sprite but I'm not sure how. First, some background. I've been a fan of the Cocos engine for a long time. To give you an idea, I published the Musical Meter suite of apps for iOS using the original Cocos2d engine. These past years, I've been immersed in the creation of a Cocos2d-x 4.0 project. When I surfaced to research ad solutions and found the Cocos2d-x community all but abandoned, you can imagine how happy I was to discover the Axmol fork and its beautiful contributors. My plan is to generate a clean Axmol project, move my source and resource files to it, and tweak until functional. The problem is that my Sprite::create("image.png") function can't seem to find the image file. With my Cocos2d-x project for Mac, I just had to drag the image file into my Xcode project and run. With my iOS project, I had to run cmake ../.. from the proj.ios_mac/ios folder to add the new resource and then run. What's the process in Axmol? I've been through the github and Discord discussions and it was mentioned that you had to run either Axmol or cmake first but I don't know what parameters I should use. I tried rerunning the Axmol build command and a variety of cmake options but my create function always returns null. Are Axmol and cmake interchangeable? Can you go back and forth between methods? In my Cocos project, I keep my .png's in the res folder and I have sub-folders for audio and data files. I would inform the engine about this with the following code:
Is this still a good idea? If someone could enlighten me as to the correct process, I'd really appreciate it. I expect the solution is simple given my history of overlooking the obvious. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
This is most likely the issue. The location of the resources should be in the folder named "Contents", and the build process will take care of copying those resources to the correct place. If you need an example of the file structure required, then the Regarding the search paths, this is what you would end up with:
The root folder is already in the search path, so no need to add that. One suggestion regarding the above search path additions though is that it may be better not to do this, which means you would prefix the resources you need. For example:
The reason why is to avoid filename clashes, where the file that exists in the first path checked is the one that is returned. If, for example, you have a file named "audio/file.mp3" and "data/file.mp3", then given this:
The file that is used would be the one in "audio", not the one in "data", since "audio" is higher up in the search list. Prefixing allows you to explicitly choose which file you want. There is an added benefit to doing this too. Let's say you offer downloadable content, or some kind of quick fixes to resources, without forcing users to download the entire application again. These would go into the writable folder, and as an example. let's say you create a folder named "dlc" in the writable folder. You then add this "dlc" path to the search list, but at the front of the list:
What you can now do is place any kind of downloadable content in the "dlc" path, such as "dlc/audio/file.mp3". Given that this path is at the front of the list, any time you refer to that file, such as with the following:
It will use the one in the "dlc" folder instead of the one bundled in your app. There are many uses to this, such as temporary file replacements for specific periods of the year, like a file for a specific holiday, and after that holiday is over, you would delete the "dlc" file associated with it, and your application would simply use the original resource again. I hope that helps. |
Beta Was this translation helpful? Give feedback.
-
They are unrelated. CMake is the build system for Axmol, so everything related to the project should be done via CMake (such as in the Also, the generated build files should not be checked into any source control either, since they can be re-generate them at any time via CMake. |
Beta Was this translation helpful? Give feedback.
Try
axmol build -p ios -a arm64 -c -f
The
-c
is to just create the project files, but not actually compile/build anything. The-f
is to force it to recreate the project files, because what most likely happened is that it detected no change in the source code, so it didn't actually recreate anything; it doesn't check if resources have changed. Sorry, I should have mentioned this earlier.Once that is done, open the project up in Xcode, and check if you can see the updated resources. Also, it's fine if you keep the project open in Xcode while you recreate it via the
axmol build
command. As soon as the project files are recreated, Xcode automatically detects the change and reloads the project.