我是Objective-C的新手,我對它的語義有着苛刻的時間。讓說我有存儲在一個的NSMutableDictionary一堆SKSpriteNode的指向爲每個精靈代碼中的枚舉狀態:SKSpriteNode的NSMutableDictionary
typedef enum PAWN_STATUS { OUT=0, MOVING, LANDED, IDLE } PAWN_STATUS;
然後
NSMutableDictionary* pawns = [[NSMutableDictionary alloc] init];
for(int i=0; i<10; ++i) {
SKSpriteNode *whiteButton = [SKSpriteNode spriteNodeWithImageNamed:@"white"];
[pawns setObject:[NSNumber numberWithInt:OUT] forKey:whiteButton];
}
然後我改變了某些精靈的狀態,說
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:location];
[pawns setObject:[NSNumber numberWithInt:LANDED] forKey:touchedNode];
但不改變現有SKSpriteNode的狀態,最後一行是添加一個新的SKSpriteNode。所以我的問題是爲什麼這樣?哈希沒有爲節點定義?
難道你有你的key/value對象將它們添加到字典中時將它們置於前面? – trojanfoe
對不起trojanfoe,但你是什麼意思,由前到後? –
'floatingPawnButton'從哪裏來?它不應該被'touchedNode'? – sergio