码迷,mamicode.com
首页 > 其他好文 > 详细

PhysicsJoint

时间:2014-11-22 00:48:34      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   color   os   使用   sp   on   art   

1 PhysicsJoint的使用

T09Join.h

#ifndef__T09Joint_H__

#define__T09Joint_H__


#include"T32.h"


classT09Joint: publicLayer

{

public:

CREATE_FUNC(T09Joint);

voidonEnter();

PhysicsWorld*getPhysicsWorld()

{

return((Scene*)getParent())->getPhysicsWorld();

}


Sprite*_A;

Sprite*_B;

Sprite*_C;

};


#endif

T09Join.cpp

#include"T09Join.h"


voidT09Joint::onEnter()

{

Layer::onEnter();


PhysicsBody*bodyA;

PhysicsBody*bodyB;

{

PhysicsBody*body= PhysicsBody::createCircle(20);

bodyA= body;

Sprite*sprite= Sprite::create();

_A= sprite;

sprite->setContentSize(Size(40,40));

sprite->setPhysicsBody(body);

sprite->setPosition(winSize.width/ 2 - 50, winSize.height/ 2 + 100);

addChild(sprite);

}


{

//PhysicsBody*body = PhysicsBody::createEdgeBox(Size(40, 40));

PhysicsBody*body= PhysicsBody::createBox(Size(40,40));

bodyB= body;

Sprite*sprite= Sprite::create();

sprite->setContentSize(Size(40,40));

_B= sprite;

sprite->setPhysicsBody(body);

sprite->setPosition(winSize.width/ 2 + 50, winSize.height/ 2 + 100);

addChild(sprite);

}


{

PhysicsBody*body= PhysicsBody::createEdgeBox(winSize,PhysicsMaterial(1.0f,1.0f, 0.0f));

Sprite*sprite= Sprite::create();

addChild(sprite);

sprite->setPhysicsBody(body);

sprite->setPosition(winSize.width/ 2, winSize.height/ 2);

}

// PhysicsJoint*joint = PhysicsJointDistance::construct(bodyA, bodyB, Vec2(0, 0),Vec2(0, 0));

// PhysicsJoint*joint = PhysicsJointSpring::construct(bodyA, bodyB, Vec2(0, 0),Vec2(0, 0), 500.0f, 500.0f);

// PhysicsJoint*joint = PhysicsJointPin::construct(bodyA, bodyB,Vec2(winSize.width / 2, winSize.height / 2));

PhysicsJoint*joint= PhysicsJointMotor::construct(bodyA,bodyB,1.0);

{

autoev= EventListenerTouchOneByOne::create();

ev->onTouchBegan= [&](Touch*touch,Event*){

Pointpt= touch->getLocation();

if(_A->getBoundingBox().containsPoint(pt));

{

_C= _A;

returntrue;

}

if(_B->getBoundingBox().containsPoint(pt))

{

_C= _B;

returntrue;

}

returnfalse;

};


ev->onTouchEnded= [&](Touch*pTouch,Event*){

Vec2pt= pTouch->getLocation()- pTouch->getStartLocation();

_C->getPhysicsBody()->setVelocity(Vec2(pt));

};

}

}











PhysicsJoint

标签:style   io   ar   color   os   使用   sp   on   art   

原文地址:http://blog.csdn.net/tototuzuoquan/article/details/41369269

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!