ZhouWeikuan / cocos2d

cocos2d for android, based on cocos2d-android-0.82, and now ported from cocos2d-iphone 0.99.4. The googlecode address is here: http://code.google.com/p/cocos2d-android-1/ . There are several demos to watch.
610 stars 291 forks source link

auto find files in assets folder #8

Closed tjhiggins closed 13 years ago

tjhiggins commented 13 years ago

Added zero method to CGRect to match CGSize and CGPoint.

Added auto search for filename in assets folder option to CCSprite. Although not efficient removes hassle of updating file paths when you change a folder name.

Let me know what you think of the auto find. If people like this concept I will implement into other classes. Personally when working on a big project it can be a hassle to include filepath along with filename.

ZhouWeikuan commented 13 years ago

OK to add zero method to CGRect.

For auto search, what if there are two files with the same name on different directories?

2011/4/20 tjhiggins < reply@reply.github.com>

Added zero method to CGRect to match CGSize and CGPoint.

Added auto search for filename in assets folder option to CCSprite. Although not efficient removes hassle of updating file paths when you change a folder name.

Let me know what you think of the auto find. If people like this concept I will implement into other classes. Personally when working on a big project it can be a hassle to include filepath along with filename.

Reply to this email directly or view it on GitHub: https://github.com/ZhouWeikuan/cocos2d/pull/8

tjhiggins commented 13 years ago

Yeah that is the only issue and if you search the entire assets folder it will return the first one it finds. However the start path allows you to find files of same name in different directories.

Example of problem you specified:

Solution finds two different test.png also stores path in texturecache not filename so it is not possible to have multiples of same image

However there could be an issue if you aren't specific enough on start path and you have files of same name in sub folders. I could make it search the entirety of the subfolders and if it finds duplicates it returns a warning letting the user know the file returned might not be the desired one.

ZhouWeikuan commented 13 years ago

It might add to the complexity.

How about define a final static String to memorize the path prefix, like public final static String PathForA = "aaa/bbb/"

and then use the path prefix for each image.

If we change the directory name, we can change the path prefix,once for all.

Thanks, Weikuan Zhou

2011/4/20 tjhiggins < reply@reply.github.com>

Yeah that is the only issue and if you search the entire assets folder it will return the first one it finds. However the start path allows you to find files of same name in different directories.

Example of problem you specified:

  • Search the entire assets folder for "test.png" will find first file with that name
  • addImage("", "test.png") || addImage(null, "test.png")

Solution finds two different test.png also stores path in texturecache not filename so it is not possible to have multiples of same image

  • Search the folder "Image" and sub folders in assets for file "test.png"
  • addImage("Image/", "test.png")
  • Search the folder "Test" and sub folders in assets for file "test.png"
  • addImage("Test/", "test.png")

However there could be an issue if you aren't specific enough on start path and you have files of same name in sub folders. I could make it search the entirety of the subfolders and if it finds duplicates it returns a warning letting the user know the file returned might not be the desired one.

Reply to this email directly or view it on GitHub: https://github.com/ZhouWeikuan/cocos2d/pull/8#issuecomment-1032625

tjhiggins commented 13 years ago

Yeah that is what we use currently, but I just find it cumbersome. It would make things more complex so I'll close. In any future pull requests I'll try to stay closer to ios cocos2d since this is a port.