iOS에서 OpenGL ES 2.0 + GLKit 게임을위한 클래스를 만들려고했습니다. 스크롤 속도를 높이면 스프라이트 간의 간격이 커집니다. Google에서 많은 검색을 수행했지만 저에게 도움이 된 답변을 찾지 못했습니다.iOS에서 계속되는 스프라이트 sprite 사이의 GLKit 간격
내 스크롤 스프라이트 클래스는 위치, 배율, 하위 등 (Cocos2D와 약간 비슷한) '노드'에서 상속됩니다. 클래스에는 스프라이트 (노드)의 배열이 있으며, x 축에 설정된 속도로 이동하고 화면 끝까지 도달하면 마지막 스프라이트의 오른쪽 위치로 이동합니다. 누군가가 내가 형성 격차를 중지 가겠어요 어떻게 나에게 이야기하여 도움이 될 수 있다면
-(id)initWithTexture:(GLKTextureInfo *)texture effect:(GLKBaseEffect *)effect xScrollRange:(float)range yPosition:(float)y xScrollVelocity:(float)velocity{
if (self = [super init]) {
//set globals
self.velocity = velocity;
xRange = range;
//create a first sprite, set position, add to children
JGSprite *firstSprite = [[JGSprite alloc] initWithTexture:texture effect:effect];
firstSprite.position = GLKVector2Make(range, y);
[self.children addObject:firstSprite];
//calc how many sprites are needed to cover range+1
float spritesNum = range/firstSprite.contentSize.width;
int spritesNumRound = roundf(spritesNum)+1;
//add enough sprites to cover the screen
for (int i = 1; i < spritesNumRound; i++) {
//create, set position, add to children
JGSprite *sprite = [[JGSprite alloc] initWithTexture:texture effect:effect];
sprite.position = GLKVector2Make(range - (i*sprite.contentSize.width), y);
[self.children addObject:sprite];
}
//if moving left, set last sprite as right most
if (velocity < 0)
lastReorderedSprite = 0;
else //set left most
lastReorderedSprite = self.children.count-1;
}
return self;
}
-(void)update:(float)dt
{
//loop through sprites
for (JGNode *node in self.children)
{
//update sprites position
node.position = GLKVector2Make(node.position.x + self.velocity*dt, node.position.y);
//if moving left
if (self.velocity < 0)
{
//if reached gone off screen
if (node.position.x <= -node.contentSize.width/2)
{
//get last node
JGNode *lastSprite = [self.children objectAtIndex:lastReorderedSprite];
//set the position to the right of the last node
node.position = GLKVector2Make(lastSprite.position.x+lastSprite.contentSize.width, node.position.y);
//set re-positioned node as lastreordered
lastReorderedSprite = [self.children indexOfObject:node];
}
}
else //moving right
{
//gone off screen
if (node.position.x >= xRange+node.contentSize.width/2)
{
//get last node
JGNode *lastSprite = [self.children objectAtIndex:lastReorderedSprite];
//set the position to the left of the last node
node.position = GLKVector2Make(lastSprite.position.x-node.contentSize.width, node.position.y);
//set re-positioned node as lastreordered
lastReorderedSprite = [self.children indexOfObject:node];
}
}
}
}
, 훨씬 사전에 감사합니다 :) 감사하겠습니다 :
여기 내 코드의 주요 부분입니다! 당신이 속도를 증가하면
node.position = GLKVector2Make(node.position.x + self.velocity*dt, node.position.y);
가, 양이 x
증가에 추가 :
도움 주셔서 감사합니다. 코드를 추가 했으므로 이제는 잘 작동합니다. – Jacobious
도움이 되니 기쁩니다. Game Dev는 이런 그래픽이 거의 없다. – Dustin