We are about to switch to a new forum software. Until then we have removed the registration on this forum.
i m using image pixels to save the preferences of player in game. m saving the image in data folder with pref.save("data/preferences.png"); but when i deploy this to android device it show me error of not finding the data folder. when i save the image directly to the sketch folder it is not deployed with the code to the device. i write the code to create the image when nt available in skecth folder it creates the image in android but can't be able to change the pixel values of the image the code is given below
if (loadImage("preferences.png")==null)
{
pref = createImage(6, 6, RGB);
pref.loadPixels();
for (int i = 0; i<36; i++)
{
pref.pixels[i] = color(1, 0, 0);
}
pref.updatePixels();
pref.save("preferences.png");
println("null");
}
else
{
pref=loadImage("preferences.png");
// println("preferences");
}
Answers
Please, remember to use the combo box to select a categoy, Android in your cases. I moved your topics.
You coulda declared a variable to store the loaded image file once:
PImage imgTmp = loadImage("preferences.png");
As far as I can tell, the data folder is merged into the
assets
folder in the APK file, which cannot be edited by the application (although this would be theoretically possible, it would be a breach of Google Play's policies). Instead, you should create a new file in the application's private directory - most Processing functions should work out of the box.Your approach to saving preferences - using individual pixels in an image file - is somewhat original, but I'm not sure how practical it is. I won't try to stop you, but I would highly recommend an alternative, such as a simple text file - or, even better, Android's SharedPreferences API which is designed specifically for this purpose.
saving preferences in the pixel works fine in the java mode or on desktop but create problem in android.
can shared preferences directly be implemented in processing ide if yes kindly show me an example
or if no the would i implement it in ecclipse by exporting the application
The SharedPreferences API should work with Processing. The link above contains information about how to use it - the only thing you'll need that it doesn't mention is the necessary import at the top of the sketch:
If you have any trouble, I can write a quick example (but please show what you have tried first!).
Thank u calsign :) work fine for me posting my code for others.
Im using this code but im getting the errors:
The function getSharedPreferences(String, int) does not exist
The function getPreferences(int) does not exist
made it work with this code, dunno is it is the best way tho.
@Asgardinho=== yes, that is the way because you are not in an activity but in a fragment
this is good stuffs!