저는 보통 java 또는 C++로 프로그래밍하고 최근에는 objective-c로 시작했습니다. objective-c에서 벡터를 찾고, NSMutableArray가 가장 좋은 옵션 인 것으로 나타났습니다. 나는 OpenGL 게임에서 일하고 있는데, 내 스프라이트에 텍스쳐 쿼드의 NSMutableArray를 만들려고하고있다.Objective-c : NSMutableArray에 사용자 정의 객체 추가
는 I 정의 질감 쿼드 : I 인터페이스에 배열 생성
typedef struct {
CGPoint geometryVertex;
CGPoint textureVertex;
} TexturedVertex;
typedef struct {
TexturedVertex bl;
TexturedVertex br;
TexturedVertex tl;
TexturedVertex tr;
} TexturedQuad;
: 여기 관련 코드
@interface Sprite() {
NSMutableArray *quads;
}
는 I 배열을 개시하고 난에 기초 texturedQuads를 작성 "은 폭 "및"height ", 스프라이트 시트의 전체 크기 인"self.textureInfo.width "및"self.textureInfo.height "가 있습니다.
quads = [NSMutableArray arrayWithCapacity:1];
for(int x = 0; x < self.textureInfo.width/width; x++) {
for(int y = 0; y < self.textureInfo.height/height; y++) {
TexturedQuad q;
q.bl.geometryVertex = CGPointMake(0, 0);
q.br.geometryVertex = CGPointMake(width, 0);
q.tl.geometryVertex = CGPointMake(0, height);
q.tr.geometryVertex = CGPointMake(width, height);
int x0 = (x*width)/self.textureInfo.width;
int x1 = (x*width + width)/self.textureInfo.width;
int y0 = (y*height)/self.textureInfo.height;
int y1 = (y*height + height)/self.textureInfo.height;
q.bl.textureVertex = CGPointMake(x0, y0);
q.br.textureVertex = CGPointMake(x1, y0);
q.tl.textureVertex = CGPointMake(x0, y1);
q.tr.textureVertex = CGPointMake(x1, y1);
//add q to quads
}
}
문제는 쿼드 "q"를 "쿼드"배열에 추가하는 방법을 모른다는 것입니다. 매개 변수가 TexturedQuad가 아닌 id 여야하기 때문에 간단한 쓰기 [quads addObject : q]가 작동하지 않습니다. int 등에서 id를 만드는 방법에 대한 예를 보았지만 TexturedQuad와 같은 개체를 사용하여 ID를 만드는 방법을 알지 못합니다.
고마워요! 튜토리얼은 좋아 보인다. 다른 튜토리얼을 살펴 보았지만 다른 프로그래밍 언어를 이미 알고있을 때는 느려지고 지루합니다. 이 튜토리얼은 멋지고 똑바로 보인다. –