달력

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
소스 코드를 웹페이지에 삽입할 때 유용한 사이트
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
UITabBarController에서 UINavigationController을 사용할 경우, 가끔 환경설정이나 하위 뷰를 표시할 때 TabBar가 표시되지 않았으면 할 때가 있습니다. 이때 하위 ViewController(ViewController)의 init에서 다음처럼 구현해주면 됩니다.

- (id)init {
   if (self = [super initWithNibName:@"MyViewController" bundle:nil]) {
      [self setHidesBottomBarWhenPushed: YES];
   }
   return self;
}
:
Posted by netkorea