我是新來的Cocos2D,我想知道我怎麼用Java編寫代碼檢查,看看如果我碰到一個精靈我已經嘗試過這樣的事情..的cocos2d的Android觸摸精靈
@Override
public boolean ccTouchesEnded(MotionEvent event)
{
CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));
if ((location.x == zom.getPosition().x) && (location.y == zom.getPosition().y))
{
CCSprite projectile = CCSprite.sprite("bullet.png");
projectile.setPosition(CGPoint.ccp(player.getPosition().x,player.getPosition().y));
addChild(projectile);
float length = (float)Math.sqrt((100 * 100) + (100 * 100));
float velocity = 100.0f/1.0f;
float realMoveDuration = length/velocity;
projectile.runAction(CCSequence.actions(
CCMoveTo.action(realMoveDuration, CGPoint.ccp(location.x, location.y)),
CCCallFuncN.action(this, "spriteMoveFinished")));
if ((projectile.getPosition().x == location.x) && (projectile.getPosition().y == location.y))
{
removeChild(projectile, true);
}
}
只是好奇,你的函數不返回一個布爾值,按要求。 – Raptor