2012-11-12 181 views
1

我正在用levelhelper和sneakyinput進行側面滾動遊戲。 我有幾個問題。 我有偷偷摸摸的輸入不同的圖層,而且我正在用levelhelper的視差滾動時遇到問題。cocos2d與levelhelper的邊界滾動邊界

我無法設法適用邊界並正確移動圖層。 我將如何修復滾動?在界限內並以角色爲中心?

我有更新方法中的2種方法

-(void) update:(ccTime)deltaTime{ 
[self applyJoystick:_leftJoystick forTimeDelta:deltaTime]; 
[self setViewpointCenter:hero.position];} 

-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)delta{ 
CGRect worldRect = [loader gameWorldSize]; 
CGPoint scaledVelocity=ccpMult(aJoystick.velocity, 90.0f); 
CGPoint newPosition =ccp(hero.position.x+scaledVelocity.x*delta, hero.position.y +scaledVelocity.y *delta); 

float posX = MIN(worldRect.origin.x + worldRect.size.width - hero.centerToSides, MAX(hero.centerToSides, newPosition.x)); 
float posY = MIN(worldRect.origin.y + worldRect.size.height - hero.centerToBottom, MAX(hero.centerToBottom, newPosition.y)); 

[hero setPosition:cpp(posX,posY)];} 

-(void)setViewpointCenter:(CGPoint) position { 

CGSize winSize = [[CCDirector sharedDirector] winSize]; 
CGRect worldRect = [loader gameWorldSize]; 
CGPoint centerOfView = ccp(winSize.width/2, winSize.height/2); 

int x = MAX(position.x, worldRect.origin.x + winSize.width/2); 
int y = MAX(position.y, worldRect.origin.y + winSize.height/2); 
x = MIN(x, (worldRect.origin.x + worldRect.size.width) - winSize.width/2); 
y = MIN(y, (worldRect.origin.y + worldRect.size.height) - winSize.height/2); 

CGPoint actualPosition = ccp(x, y); 

CGPoint viewPoint = ccpSub(centerOfView, actualPosition); 
self.position = viewPoint;} 

也是我嘗試翻轉字符(LHSprite)我使用

if (newPosition.x< hero.position.x) 
    hero.flipX=YES; 
else 
    hero.flipX = YES; 

但是,這不是工作,但我想也使用

hero.scaleX=-1 

翻轉它而不是flipX,翻轉但轉到屏幕的另一側翻轉。

回答

0

部分解決。

它似乎是

myParallax = [loader parallaxNodeWithUniqueName:@"Parallax_1"]; 

被搞亂它,所以我禁用它,

我改變第一種方法

-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)delta{ 
CGRect worldRect = [loader gameWorldSize]; 
CGSize winSize = [[CCDirector sharedDirector] winSize]; 
CGPoint scaledVelocity=ccpMult(aJoystick.velocity, 200.0f); 
CGPoint newPosition =ccp(hero.position.x+scaledVelocity.x*delta, hero.position.y +scaledVelocity.y *delta); 

float posX = MIN(worldRect.size.width - hero.centerToSides, MAX(hero.centerToSides, newPosition.x)); 
float posY = MIN(winSize.height -winSize.height/2+ hero.centerToBottom, MAX(hero.centerToBottom, newPosition.y)); 

if (scaledVelocity.x >= 0) 
    hero.scaleX = 1.0; 
else 
    hero.scaleX = -1.0; 

[hero setPosition:ccp(posX, posY)]; 
} 

似乎當滾動心不是正確的,去白色區域出來的世界和一切都是正確的,你需要找到一個關於視差比和等級和速度的方程。