为了让雪碧(佳能)触摸并对cocos2d-android中的触摸做出反应(发射子弹),我在构造函数中设置了this.setIsTouchEnabled(true);,并在ccToouchesBegan()中添加了以下代码
@Override
public boolean ccTouchesBegan(MotionEvent event)
{
canon1 = CCSprite.sprite("android.png");
canon1.setPosition(CGPoint.ccp(10, 60));
canon1.setScale(1f);
addChild(canon1);
CGRect canon1Rect = CGRect.make(canon1.getPosition().x - (canon1.getContentSize().width/2),
canon1.getPosition().y - (canon1.getContentSize().height/2),
canon1.getContentSize().width,
canon1.getContentSize().height);
// Choose one of the touches to work with
CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(10,60));
return;
}因此,当接触到精灵(大炮)子弹必须发射,但这里的触摸是行不通的。
发布于 2013-08-04 16:35:15
我希望这能帮到你。
public boolean ccTouchesEnded(MotionEvent event) {
CGPoint location = CCDirector.sharedDirector().convertToGL(
CGPoint.ccp(event.getX(), event.getY()));
if (CGRect.containsPoint((newGame1.getBoundingBox()), location)) {
newGame();
}
return super.ccTouchesEnded(event);
}https://stackoverflow.com/questions/17377821
复制相似问题