树叶下降动画和手指拖动

问题描述:

我是Cocos2D的新手,有谁能告诉我如何做叶子从顶部落下并落在iPad底部,当用户倾斜iPad或触摸树叶时,叶子应该做出相应的回应。应该类似于爱丽丝仙境lite应用页码13动画。 我张贴我的代码,但它不表现我想要的。每当我接近精灵时,所有的精灵都会以令人难以置信的力量移动......他们真的会走出我所接触的地方。当然,我不是唯一一个执行过此操作的人吗?任何人都能带领我走向正确的方向吗?树叶下降动画和手指拖动

static float hw = 639.0/2.0,hh = 479.0/2.0; (cpvct(pos.y/size.height,pos.x/size.width),2.0f),cpv(1.0f,1.0),cpVect(pos.y/size.height,pos.x/size.width),2.0f)1.02, F)); V = CPV(V.X * HW,V.Y * 11H); // printf的( “%S \ n” 个,cpvstr(V)); return v; }

限定GRABABLE_MASK_BIT(1 < < 31)

  • (无效)ccTouchesBegan:(NSSet中*)触摸withEvent:方法(的UIEvent *)事件{ UITouch *的myTouch = [触摸anyObject]; CGPoint位置= [的myTouch locationInView:的myTouch视图]]; location = [[CCDirector sharedDirector] convertToGL:location];

    cpVect point = mouseToSpace([myTouch locationInView:[myTouch view]],[myTouch view] .bounds.size); mousePoint = point;

    cpShape * shape = cpSpacePointQueryFirst(space,point,GRABABLE_MASK_BIT,0);

    if(shape){cpBody * body = shape-> body; mouseJoint = cpPivotJointNew2(mouseBody,身体,cpvzero,cpBodyWorld2Local(体,点)); mouseJoint-> maxForce = 50000.0f; mouseJoint-> biasCoef = 0.15f; cpSpaceAddConstraint(space,mouseJoint); } }

  • (无效)ccTouchesMoved:(NSSet中*)触摸withEvent:方法(的UIEvent *)事件{ UITouch *的myTouch = [触摸anyObject]; CGPoint位置= [的myTouch locationInView:的myTouch视图]]; location = [[CCDirector sharedDirector] convertToGL:location];

    mousePoint = mouseToSpace([myTouch locationInView:[myTouch view]],[myTouch view] .bounds。尺寸); }

  • (无效)ccTouchesEnded:(NSSet中*)触摸withEvent:方法(的UIEvent *)事件{ [自touchesCancelled:触摸withEvent:方法事件]; }

  • (无效)touchesCancelled:(NSSet中*)触摸withEvent:方法(的UIEvent *)事件{ cpSpaceRemoveConstraint(空间,mouseJoint); cpConstraintFree(mouseJoint); mouseJoint = nil; }

任何人请指导我或张贴代码,我急需它。

等待您的宝贵建议和任何代码。

在此先感谢。

湿婆。

+0

投票结束,质疑广泛回答。 – 2010-11-12 12:56:47

+0

任何时候当我读到“我急需它”时,我觉得有必要评论“美元有多紧急?” – Kheldar 2011-08-31 22:17:58

Cocos2d自带项目帮助您入门。其中之一就是“带有Box2D的Cocos2d”。这个项目开始时会出现一个场景,在场景中使用Box2D物理效果在顶部生成一堆框,并落在屏幕的底部。如果我没有记错的话,当你倾斜时它也会将它们转移。

看看这个项目,并根据您的需求进行调整。

This blog是我开始使用iPhone游戏开发时的无价资源。我建议你阅读它。

+0

感谢badgerr, – 2010-11-12 15:32:32

+0

感谢badgerr,我以前见过它,但没有找到可以帮助我的东西 – 2010-11-12 15:38:36

+0

这听起来对于我来说,演示应用程序完全按照您所描述的内容进行操作,其中一个区别在于对象不是树叶。你有哪些部分有问题? – badgerr 2010-11-12 15:59:07