달력

10

« 2024/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
http://www.cocos2d-iphone.org/forum/topic/7817

I've been playing around with path finding and tilemaps along with the latest release of cocos2d-iPhone - and I posted a sample app in hopes that it saves someone else some time - or if anyone has comments to optimize/improve this code (I'm sure that won't be difficult as I wasn't shooting for optimization, just trying to learn).

I started with two great tutorials:

Ray Wenderlich's cocos2d-iphone tile map tutorial:
http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

and BravoBug's A-Star sample program:
http://bravobug.com/news/?p=118

My sample app loads a tile map that contains a start point, an end point, and walls, and detects (and graphically displays) a path between the start and end points. You can select whether or not you want to allow diagonal movements. Anyway, here's the link. I hope someone finds it useful:

http://dl.dropbox.com/u/3729313/PathFinder.zip

Cheers,
Kevin


:
Posted by netkorea

http://www.iphonedevsdk.com/forum/iphone-sdk-development/52507-user-resize-image-screen.html
Unread 07-07-2010, 10:18 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 22
Default

Quote:
Originally Posted by mitchsamuels View Post
Hello, I have an image on my view that is draggable. How can I make it so the user is able to resize the image on the screen by pinching.
Easiest way to do that is to use UIGestureRecognizer. That is new to iPhone OS 3.2 (or iOS4 for iPhones).

Basically, you make a UIPinchGestureRecognizer and add it to your view, and in UIGestureRecognizer you register for a callback. When that is done, when the user has started pinching, it will not only callback, but the UIPinchGestureRecognizer will give you a scale by how much, which you can immediately translate into a scale.

Relevant Text:

UIGestureRecognizer Documentation
:
Posted by netkorea
Mac에서 Finder나 Quick View로 png를 볼 때 가끔 제대로 표시가 안되는 경우가 있습니다.
여러 툴을 찾아봤는데 이게 가장 쓸만한거 같네요.
http://www.lynapp.com/index.html

이 툴에 대한 소개는 아래 블로그에 잘 나와있더군요.^^;
http://left.tistory.com/entry/lyn-for-mac

:
Posted by netkorea
2010. 9. 9. 11:41

iPhone Keychain Access 개발 - iPhone/개발 Tip2010. 9. 9. 11:41

GenericKeychain 1.1(http://developer.apple.com/library/ios/#samplecode/GenericKeychain/Listings/Classes_AppDelegate_h.html#//apple_ref/doc/uid/DTS40007797-Classes_AppDelegate_h-DontLinkElementID_3)
을 이용해서 KeyChain에 반영했었는데, 3.1.2에서는 문제가 없었는데 iOS 4.0이상에서 제대로 실행되지 않더군요.

검색해보니 위 링크처럼 1.2가 새로 나와서 적용했는데, 1.1이랑 코드가 거의 안바뀐거 같은데도 온갖 에러가 발생하더군요.

2-3일 고생하다가 http://useyourloaf.com/blog/tag/keychain 에서 방법을 찾았네요.
짜증~ ㅠㅠ

keychain에 등록 중 발생하는 에러코드
http://developer.apple.com/library/mac/#documentation/Security/Reference/keychainservices/Reference/reference.html

Result Codes

The most common result codes returned by Keychain Services are listed in the table below. The assigned error space for Keychain Services is discontinuous: –25240 through –25279 and –25290 through –25329. Keychain Item Services may also return noErr (0) or paramErr (–50), or CSSM result codes (see Common Security: CDSA and CSSM, version 2 (with corrigenda) from The Open Group (http://www.opengroup.org/security/cdsa.htm)).
Result Code Value Description
errSecSuccess 0 No error.

:
Posted by netkorea
http://snipplr.com/view/39706/setting-cocos2d-camera-position-using-ccfollow/

  1. -(void)setPlayerPosition:(CGPoint)position {
  2. CGPoint tileCoord = [self tileCoordForPosition:position];
  3. int tileGid = [_meta tileGIDAt:tileCoord];
  4. if (tileGid) {
  5. NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
  6. if (properties) {
  7. NSString *collision = [properties valueForKey:@"Collidable"];
  8. if (collision && [collision compare:@"True"] == NSOrderedSame) {
  9. return;
  10. }
  11. NSString *collectable = [properties valueForKey:@"Collectable"];
  12. if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
  13. [_meta removeTileAt:tileCoord];
  14. [_foreground removeTileAt:tileCoord];
  15. self.numCollected++;
  16. [_hud numCollectedChanged:_numCollected];
  17. }
  18. }
  19. }
  20.  
  21. ccTime moveDuration = 0.3;
  22. id playerMove = [CCMoveTo actionWithDuration:moveDuration position:position];
  23. id cameraMove = [CCFollow actionWithTarget:_player worldBoundary:CGRectMake(0, 0, (_tileMap.mapSize.width * _tileMap.tileSize.width), (_tileMap.mapSize.height * _tileMap.mapSize.height))];
  24. [_player runAction:playerMove];
  25.  
  26. [self runAction:cameraMove];
  27.  
  28. }

:
Posted by netkorea
2010. 8. 6. 17:18

NSZombieEnabled 개발 - iPhone/개발 Tip2010. 8. 6. 17:18

인터넷 돌아다니다가 우연히 보게되었는데 나중에 디버깅할 때 쓸모있을지 몰라서 올려둡니다.
http://www.cocoadev.com/index.pl?NSZombieEnabled

메모리 할당과 해제는 정말 어렵죠. ^^;
아 할당과 해제가 어려운게 아니라 그걸 제대로 지켜가면서 사용하는게 어렵다고 해야할려나요.
개인적 생각으론 Java나 C#처럼 그냥 알아서 해주든지 C/C++처럼 명시적으로 해주면 좀 더 명확할건데 autorelease랑 factory개념때문에 처음 입문하거나 새로운 Class를 사용하게되는 경우 더 힘들지 않나 싶네요.. 뭐든지 다 마찬가지겠지만 익숙해지면 나아지겠죠. ^^;

아 중요한 NSZombieEnabled에 대한 설명이 없이 잡설만 늘어놨네요.
위 링크에 가시면 자세한 설명이 나와있지만, 간략히 말씀드리면 이놈은 Memory 해제시 실제 해재하지 않고 단지 해제했다는 mark만 달고 해제한 오브젝트에 메시지를 보낼 경우 로그를 남기게 됩니다. 이런게 왜 필요하냐면, 메모리 해제를 한 후 그 해제한 오브젝트를 이용해서 뭔가 할 경우 이상하게(undefined라고 하죠 ^^) 작동해서 그 원인을 찾기가 매우 어렵기 때문에, 해제한 오브젝트에대한 호출을 쉽게 찾기 위해서입니다.  예전에 C++에서도 비슷한 경우에 대한 처리방법에 대한 기사를 읽었던거 같은데 너무 오래전이라 기억이 가물가물하네요. 요즘은 C#을 알게된 뒤론 C나  C++은 소스만 봐도 이상하게 보이는 듯 하네요. ㅎㅎ
:
Posted by netkorea
평생 숙원 사업(!)인 게임 개발을 그래픽 디자이너가 없다는 핑계(ㅠㅠ)로 이리저리 공부만 하다가 입에 풀칠은 해야한다고 간단한 일을 하나 받아서 앱 개발을 하게되었습니다.

개발에 앞서 그래도 신경쓴다고, ^^, 최신 xCode가 더 좋을 거란 생각에 iOs4랑 엮인 xCode를 받았더니, 예전 xCode 버전업과는 다르게 이 버전에선 3.x대 SDK를 아예 Link할 수 없네요. 3.2가 지원되는건 현재 iPad가 3.2만 지원하기 때문인 듯 하더군요.

친구 구글에게 해결책을 물어봤더니 Platform을 3.2로 하고 deploy target을 3.1.2로 지정하면 된다길래 그렇게 했습니다. 컴파일이랑 실행은 잘되는데 Instruments에서 아주 적은 양이긴 하지만 memory leak이 검출되네요. 혹시나 해서 플랫폼을 4.0으로 바꿔서 해보니 memory Leak이 없더군요. 게다가 Leak이 발생하는 곳의 Call Tree를 봐도 제가 작성한 Code를 호출하는 부분은 없더군요. 4.0에서는 Leak이 없으니 xCode가 제대로 이전 버전을 지원 못하나보다 생각하고 3.1.2용 xCode 에서 컴파일하면 되겠지라고 안일하게 생각하고 4.0용 xCode에서 계속 개발했습니다.

개발을 끝내고 AppStore에 올리려고 3.1.2에서 메모리 Leak을 테스트했더니, 역시나 4.0용 xCode랑 똑 같은 leak이 발생하네요. 허거걱... 놀라서 친구 구글에게 투덜됐더니 예전부터 이런 문제가 다른 사람에게도 많았나 보더라구요. 글 중에 Leak이 소량이고 개발 코드랑 관계없으면 OS버그이거나 Instruments의 버그나 Leak에 대한 혼동일 수 있으니 무시해도 될거라네요. 저야 언제나 이런걸 무시할 용의도 있고 의지도 있지만, 문제는 Apple이 Reject하지 않냐는 거겠죠. 글들을 더 찾아보니 Simulator의 메모리 관리 문제일 수도 있다네요. 허걱... 느린 속도때문에 Device에서 직접 메모리 Leak검사는 안해봤는데... 바로 검사를 해봤습니다.

앱 로딩 속도때문에 처음엔 문제가 발생하지 않는 줄 알고 좋아했는데 조금 시간이 지나니 문제가 발생하더군요. 그런데 Leak때문에 검색하면서 자주 봤던 3584란 숫자가 눈에 띄네요. (GeneralBlock-3584)

검색해보니 다음 글(http://stackoverflow.com/questions/478242/leak-generalblock-3584)을 찾을 수 있었습니다. 그 중 글쓴 분이 올 4월에 직접 올린 아래 답글을 볼 수 있더군요.
You have nothing to worry about, this is false positive from Instruments.
It has to do with freeing resources of the thread that has being terminated. They are just laying around until next thread is done and cleans resources after the one of the previously terminated. Instruments take this for a 'leak' but it's the feature of pthreads implementation on the iPhone OS which in perfect world would be handled differently. More on this on the Apple's dev forum here and here.
저기 here and here들에 가보면 나름 자세한 설명이 있는데 조금 보다 말았습니다. 결론은 버그라기 보다는 의도된 대로고 4.0 이전 버전에 대해 Instruments(최신에서도 3.1.2로 컴파일할때는 Leak이 발생하니 Instruments만의 문제라긴...)는 인식 못한다는 정도로 봐야겠죠.

어쨌든 앱이 갑자기 Crash하거나 하진 않으니 오늘 그냥 올려보려고 합니다. Reject당하면 다시 저글들 분석해보고 해야겠죠. 혹시 Reject당하게되면 다시 글 올리도록 하겠습니다.

자체 문제인줄도 모르고 Leak때문에 고생한걸 생각하면...후...
다른 분들에게 도움이 되었으면 하고 올리는데 이글을 볼 사람이 있을런지..ㅎㅎ
:
Posted by netkorea
소스 코드를 웹페이지에 삽입할 때 유용한 사이트
http://quickhighlighter.com/
:
Posted by netkorea
아래 이전 글에서 NSLog를 삽입하는 Automator를 소개하고 잘 사용중인데 아주 약간 불편한게 있어서 수정하고 공유합니다.
2010/07/22 - [개발 - iPhone/개발 환경 구축] - xCode에서 단축키로 현재 method의 시작과 끝에 NSLog를 삽입하는 Utility

원저작자처럼 NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);로 사용할 경우, __PRETTY_FUNCTION__가 Preprocessor의 전처리기이다보니 실제 NSLog를 호출하는 Class의 하위 Class에서는 Runtime시에 어떤 Class가 실행되는지 알 수 없더군요.

그래서 아래처럼 수정했습니다.
    NSString *entryString = @"\tNSLog(@\"##### Entering %@-[%s] [%@] [%@]\", self,__PRETTY_FUNCTION__,self,self);";
    NSString *exitString =  @"\tNSLog(@\"----- Leaving %@-[%s] [%@] [%@]\", self,__PRETTY_FUNCTION__,self,self);";
__PRETTY_FUNCTION__전의 self는 runtime Class를 알기위함이고, 이 후의 self는 실제 Log를 출력할 때 관심있는 변수를 출력하기위해 미리 공간을 마련해둔겁니다. 어짜피 이전 글대로 Project 세팅을 했으면 Release시엔 NSLog가 출력되지 않을 것이기에 디버깅하는 동안엔 좀 더 많은 내용을 간편하게 출력하고 싶더군요. ^^;

실제 효용성이 있는진 모르겠지만, 2번 입력방지하는 부분에선 아래 문자열을 이용해 검사하도록 했습니다. 그런데 소스 코드 보면서 작업할건데 2번입력할 일이 있기나한지 모르겠네요. ㅎㅎ
    NSString *entryMask = @"\tNSLog(@\"##### Entering %@-[%s] [%@] [%@]";
    NSString *exitMask =  @"\tNSLog(@\"----- Leaving %@-[%s] [%@] [%@]";

변경한 소스와 Snow Leopard에서 컴파일한걸 같이 올립니다.

:
Posted by netkorea

우연찮게 NSLog를 편하게 삽입해주는 툴을 찾아서 공유하려합니다.

먼저 NSLog에 대한 팁으로부터 시작하죠.
It's NSLog, NSLog... 를 보면 필자도 아래처럼 NSLog를 사용했었다는군요.

NSLog(@"Now entering viewDidLoad in RootViewController");
// Do stuff
NSLog(@"Now leaving viewDidLoad in RootViewController");

그러다가 this page(Logging Current Method or Function)를 알게되었다는 군요. 좋네요. 훌륭합니다. NSLog를 아래처럼 사용하면 자동으로 함수명이 출력된다고 합니다.

NSLog(@"%s", __PRETTY_FUNCTION__);
*2008-12-12 09:22:49.552 Healthcheck[79016:20b] -[HealthcheckAppDelegate applicationDidFinishLaunching:]*

 

개발용은 NSLog를 사용하더라도 배포용에는 NSLog가 필요없겠죠. 블로그에 자세한 설명이 나와있으니 간략히 정리만 하겠습니다. 자세한 내용은 위 블로그에 가보세요. ^^;

1. xcodeproject의 pch 파일에 다음 내용 입력 (DCBLOCKNSLOGSTATEMENTS은 보통 RELEASE_MODE등으로 많이쓰죠?)
#ifdef DCBLOCKNSLOGSTATEMENTS
#define NSLog(format, ...)
#else
#define NSLog(format, ...) NSLog(format, ## __VA_ARGS__)
#endif

2. Release Configuration의 GCC 4.2 - Preprocessing의 Preprocess Macros와 Preprocess Macros Not Used In Precompiled Headers에 DCBLOCKNSLOGSTATEMENTS 추가

3. 당연한 예기지만 Debug Configuration에선 DCBLOCKNSLOGSTATEMENTS 정의하면 안되겠죠? ^^;

그래서 이 글을 적은 블로거가 이렇게 NSLog를 잘 사용했는데, 그래도 코드 타이핑하기가 너무 귀찮더랍니다. 그런 이유로 NSLog를 좀 더 쉽게 입력해주는 툴을 만들었다고 합니다.

Free Utility For Adding Logs 에 가보시면 다운받을 수 있습니다. 혹시 다운 링크가 께질지 모르니 미래를 위해 여기에도 올려둡니다. ㅎㅎ Build해서 Automator에 추가한 후 Service Template이용해서 새 Workflow만들어 줍니다. 이때 Service는 <any application>에 대해 <text>를 받아들이도록 합니다. <Replaces selected text> 도 체크해서 선택해주도록 합니다.

단축키 등록은 System Preferences -> Keyboard -> Keyboard Shortcuts tab에서 좌측에서 Services를 선택하고 우측에서 Automatror에서 저장한 이름을 찾습니다. Text항목 밑에 있을 겁니다. 거기서 단축키를 지정해 주시면 됩니다.


테스트는 xcode를 실행중이었다면 닫고 다시 실행합니다. 그냥하면 단축키가 작동안하더군요. method 정의의 {나 }를 더블클릭하면 method이름을 제외한 전체 method 블록이 선택되는데, 이때 단축키를 눌러줍니다. 그럼 NSLog가 추가됩니다. method 본체뿐만 아니라 어떤 Block에서도 가능한 모양이네요. 타이핑 작업을 획기적으로 줄여주는 참 유용한 툴인것 같습니다.

만든분이 영감을 얻었고 강력 추천한다는 Accessorizer 을 보니 참 많은 기능이 있는 것 같네요. 관심있는 분은 이것도 사용해 보시면 좋을 것 같습니다. $15이라는거 같네요.

:
Posted by netkorea