1

ここで構造体に値を入力しています:

[self createEntityWithX:20 andY:20 withType:0 withWidth:20 andLength:20 atSpeed:5];
...
...
-(void)createEntityWithX:(int)newEntityX andY:(int)newEntityY withType:(int)newEntityType withWidth:(int)newEntityWidth andLength:(int)newEntityLength atSpeed:(int)newEntitySpeed
{
  Entity tmpEntity;
  tmpEntity.entityX = newEntityX;
  tmpEntity.entityY = newEntityY;
  tmpEntity.entityLength = newEntityLength;
  tmpEntity.entityWidth = newEntityWidth;
  tmpEntity.entityType = newEntityType;
  tmpEntity.entitySpeed = newEntitySpeed;

  NSValue *tmp = [NSValue valueWithBytes:&tmpEntity objCType:@encode(struct Entity)];

  [entityArray addObject:tmp];
}


-(Entity)retreiveEntityFromValue:(NSValue *)value
{
  Entity entity1;
  [value getValue:&entity1];
  return entity1;
}

そして、私がそれを取り戻すとき、データはスクランブルされていますか?X:20 Y:20 Width:20でエンティティを作成し、x:1712736 Y:0 Width:0?Xは完全にランダムですが、残りは0のままです

どこが間違っているのですか?

4

1 に答える 1

1

整数を使用する代わりに、float(1)を使用してみてください。そうしないと、データをpoint(2)として渡すことができます。

1)http://www.techotopia.com/index.php/Objective-C_2.0_Data_Types#float_Data_Type 2)http://mobiledevelopertips.com/c/cgrect-cgsize-and-cgpoint.html

于 2012-05-05T21:23:01.103 に答える