简体   繁体   English

如何在cocos2d中为Android使用CCFollow?

[英]How can I use CCFollow in cocos2d for android?

I'd like to use CCFollow in my game. 我想在游戏中使用CCFollow。 but I don't know How to use it. 但我不知道如何使用。

In ZhouWeikuan-cocos2d Testbed project, CCFollow is used in this way 在ZhouWeikuan-cocos2d Testbed项目中,以这种方式使用CCFollow

CCSprite grossini;
CGSize winSize = CCDirector.sharedDirector().winSize();

grossini.setPosition(CGPoint.ccp(-200, winSize.height/2));

CCMoveBy move = CCMoveBy.action(2, CGPoint.ccp(winSize.width*3,0));
CCMoveBy move_back = move.reverse();
CCSequence seq = CCSequence.actions(move, move_back);
CCRepeatForever rep = CCRepeatForever.action(seq);

grossini.runAction(rep);

this.runAction(CCFollow.action(grossini, CGRect.make(0, 0, (winSize.width*2)-100, winSize.height)));

and here is the title of this Layer 这是该图层的标题

"The sprite should be centered, even though it is being moved" “即使移动精灵,它也应该居中”

but it's not working. 但它不起作用。 sprite is moving from side to side. 精灵从一边移动到另一边。

Can anyone solve this problem? 谁能解决这个问题?

Might be an issue with boundaries. 可能是边界问题。 Try changing the runAction method: 尝试更改runAction方法:

this.runAction(CCFollow.action(grossini));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM