Cocos2d iphone 移动整个动画精灵表
我有一些精灵表,我必须永远动画,我想添加它作为一个Cocos2d iphone 移动整个动画精灵表,cocos2d-iphone,Cocos2d Iphone,我有一些精灵表,我必须永远动画,我想添加它作为一个CCLayer 回到我的现场。 稍后,我必须在屏幕上移动整个动画精灵。 举个例子,我有一个狗狗行走的动画,从精灵的画面,这一个永远在奔跑。比我想能够在屏幕上移动这只狗,而动画 最好的方法是什么?(或正确的方法) 以下是我制作帧动画的方式: CCSprite *boom; boom = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_00000.
CCLayer
回到我的现场。
稍后,我必须在屏幕上移动整个动画精灵。
举个例子,我有一个狗狗行走的动画,从精灵的画面,这一个永远在奔跑。比我想能够在屏幕上移动这只狗,而动画
最好的方法是什么?(或正确的方法)
以下是我制作帧动画的方式:
CCSprite *boom;
boom = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_00000.png",file]];
boom.position=touch;
[self addChild:boom];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 0; i < 5; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:
@"%@_0000%i.png",file,i]];
[animFrames addObject:frame];
}
CCAnimation* boxAnimation = [CCAnimation animationWithSpriteFrames:animFrames delay:0.075f];
CCAnimate * boxAction = [CCAnimate actionWithAnimation:boxAnimation];
CCAction *call=[CCCallBlock actionWithBlock:^{[self removeFromParentAndCleanup:YES];}];
CCAction * sequence=[CCSequence actions:boxAction,[CCHide action],call,nil];
[boom runAction:sequence];
return self;
CCSprite*吊杆;
boom=[CCSprite SpriteWithPriteFrameName:[NSString stringWithFormat:@“%@00000.png”,文件]];
动臂位置=触摸;
[self-addChild:boom];
NSMutableArray*animFrames=[NSMutableArray];
对于(int i=0;i<5;i++)
{
CCSpriteFrame*frame=[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:[NSString stringWithFormat:
@“%@_0000%i.png”,文件,i]];
[动画帧添加对象:帧];
}
cAnimation*boxAnimation=[cAnimation AnimationWithPriteFrames:AnimationFrames延迟:0.075f];
cAnimate*boxAction=[cAnimate actionWithAnimation:boxAnimation];
CCAction*call=[CCCallBlock actionWithBlock:^{[self-removeFromParentAndCleanup:YES];}];
CCAction*sequence=[CCSequence actions:boxAction,[CCHide action],call,nil];
[动臂运行动作:顺序];
回归自我;
你将如何移动整个东西?有几种方法可以做到这一点。如果您不热衷于碰撞检测,那么一种方法是:
CGPoint egressPosition = ccp(0,0); // figure this out in your app
float moveDuration = 1.5f ; // whatever time you compute for desired speed and distance
id move = [CCMoveTo actionWithDuration:moveDuration position:egressPosition];
id spawn = [CCSpawn actions:sequence,move,nil];
[boom runAction:spawn];
否则,请按原样使用代码
[self schedule:@selector(moveBox:)]; // optional, you could do this in update method
[boom runAction:sequence];
-(void) moveBoom:(CCTime) dt {
CGPoint newPosition;
delta = ccp(dt*speedX,dt*speedY); // crude , just to get the idea
newPosition = ccpAdd(boom.position,delta);
// here you can figure out collisions at newPosition before the collision
// and do whatever seems appropriate
boom.position = newPosition;
}
还有一件事,如果我有很多层,其中包含精灵,并且我需要一些碰撞检测,那么从所有层收集所有精灵并检查它们之间的碰撞的正确方法是什么?@Curnelious您是在寻找精灵边界框之间的碰撞还是图像本身(例如狗的身体)之间的碰撞?