开发者

How do I change the characters position as if I were only changing the camera?

So I am working on a game in Cocos2d for iPhone. I am using Sneaky Input to handle controls for moving the character. Since I want the character to stay in the center of the screen the whole time, to get the appearance of movement I am moving everything else in the scene but the character.

But here is my pr开发者_高级运维oblem. My game needs enemies that move. I was thinking about doing something like:

id myAction = [CCMoveTo actionWithDuration:1.0f position:ccp(170, 0)];
[boss runAction:myAction];

And I would put this in a timer. Ok, so I did that, and at first did not mess around with the joystick that moves everything and the "boss" moved where I thought it would. But, then I messed with the joystick. Ok, so basically that messed everything up, nothing moved to the spot I wanted and so on. I suspected this would happen, but tried it anyway. Now I have no idea what to do. To make things a little clearer here is my timer function:

-(void)tick:(float)delta {

    // pressed
    if (rightButton.active == YES){ //This is unrelated... its for something else in my game
        [character stopAction:character_attack];
        [character runAction:character_attack];
    } //end unrelatedness

        id bossMov = [CCMoveTo actionWithDuration:1.0f position:ccp(-170, 0)];
        [boss runAction:bossMov];

    [self applyJoystick:leftJoystick toNode:boss forTimeDelta:delta];
    [self applyJoystick:leftJoystick toNode:background forTimeDelta:delta];

}

And my method timer is being called in init like so:

    [self schedule:@selector(tick:)];

If you need anymore information just ask.


Can't you just move the layer that all your map elements and enemys are a child of, in the opposite direction of your character?

e.g. if your character moves +1 on the x, move the layer -1 on the x

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜