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,翻轉但轉到屏幕的另一側翻轉。