Cocos2dX, Assets getting deleted on Build or Run (Eclipse Juno, Android C++ project)
Asked Answered
B

3

6

Could someone please advise where and how to add assets to an Android Cocos2D-X project. I've tried both just linking the assets to the 'assets folder' in Eclipse as well as physically placing a copy of the assets in the assets folder via file system where the project is located. But when I build or run the project in Eclipse the assets are deleted. I've also tried tried running the 'build_native.sh' then running the projectt in Eclipse as other posts on the this site have suggested but in all cases the assets get deleted.

IS there another location that I need to place my assets. Also do I need to manually add them in a config file within the project (e.g.: the manifest file).

My System: Mac OS Lion Eclipse Juno Cocos2D-X v2.1 Beta 3

Please advise.

Blais answered 18/1, 2013 at 18:49 Comment(0)
T
4

You have Resources folder in your folder structure as you can see in HelloCpp or any example project. Thats where you have to put your images etc..

And regarding assets you do not need to do anythng just run build_native.sh, Assets folder will get generated by its own in the proj.android folder.

to know more just open build_native.sh in that there are three lines which says copy resources to assets folder

I hope you got your answer Good Luck : If further queries please feel free to ask.

Tamasha answered 19/1, 2013 at 5:9 Comment(1)
I am not getting images in asset folder. in build_native.sh file, there is code for copy from resources to assets. Can you please tell me where I am wrong here?Chibouk
A
2

The DETAILED explanation. You need to put the image file you want to use into the "Resources" folder of the Cocos2DX project you are running. Then you need to run ./build_native.sh from the Cygwin program.

EXAMPLE: You are building a game called cppgame. You create a project called cppgame with Create-android-project.bat file in the Cocos2DX folder. Now you have a cppgame project folder on the c: drive (c:/cocos2dx/cppgame/). In that folder, you have a "Resource folder" that was created as well (c:/cocos2dx/cppgame/Resources/).

  1. Place all the image files (sprite.png, *.png) you want to use inside the "Resource folder".
  2. Open Cygwin as administrator and navigate to the c:/cocos2dx/cppgame/proj.android/ folder.
  3. Type "./build_native.sh" into the Cgywin prompt ("$").

This should put all of your image files into the assets folder of your project and now you can use them to create sprites!

EXPLANATION: The build_native.sh file copies the image files to the assets folder and sets some special permission so they don't get deleted when you run the program. If someone with a better understanding of cygwin coding can explain it better, I'd be grateful.

Antonomasia answered 1/8, 2013 at 5:21 Comment(1)
It's not an answer... Please do not post any question on the answer's place.Shiner
S
0

It’s simple batch script (batch_native.py) that copies the resources from the multiplatform “Resource” folder (used in cocos2d-x templates) to the assets folder used on Android.

One step Solution: Just copy all your imageName-sd.png,imageName-hd.png etc to the resources folder.

Happy programming :)

batch_native.py which copy the files to android assets folder.

# copy resources
for file in "$APP_ROOT"/Resources/*
do
if [ -d "$file" ]; then
cp -rf "$file" "$APP_ANDROID_ROOT"/assets 
fi
if [ -f "$file" ]; then cp "$file" "$APP_ANDROID_ROOT"/assets
fi
done
Scissel answered 22/3, 2014 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.