开发者

Boolean question in Cocos2d

I am making a game in Cocos2d. I have enemies in the game. I want them to shoot at the character. Currently, I have a boolean that says

buffDude.shoot = YES

when it is done moving. And in the Enemy class, I want it to detect if the boolean is YES or NO, and shoot if it is YES. And, while we're on that note, if I declare

buffDude.shoot = YES

in the

开发者_运维技巧
+(id)enemy

method, it will create a bullet at the bottom of the enemy sprite, but the bullet will not move. I know that it is because it didn't add the bullet to the Layer, it added it to the Enemy, but I don't know how to add it to the layer. Please Help! This is really driving me crazy, and help would be appreciated.

EDIT:

Okay, to get it to work, I just created a different layer and added the enemies and their bullets to that. Thanks for the help!


I am not really sure what you are trying to do. But I can only assume that you are adding a bullet sprite. And if you are adding a bullet sprite in you Enemy Class like: [self addChild:bulletSprite];, the Enemy class will own that bullet. Instead, if you would like the bullet to be visible in your game scene, you can add the same code in HelloWorldLayer.m instead.

But as I said, I'm not really sure what your problem is.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜