//
// PhysicsJoints2.hpp
// day01
//
// Created by MAC on 16/7/14.
//
//
#ifndef PhysicsJoints2_hpp
#define PhysicsJoints2_hpp
#include <stdio.h>
#include <iostream>
using namespace std;
#include "cocos2d.h"
using namespace cocos2d;
#include "ui/CocosGUI.h"
using namespace cocos2d::ui;
const int DRAG_BODYS_TAG =1;
class PhysicsJoints2:public Layer{
public:
static Scene* createScene();
bool init();
CREATE_FUNC(PhysicsJoints2);
void onEnter();
void onExit();
PhysicsWorld* getPhysicsWorld();
Sprite* makeBall(Vec2 point, float radius, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT);
Sprite* makeBox(Vec2 point, Size size, int color=0, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT);
private:
Size visiableSize;
Vec2 center;
PhysicsBody* _touchBody;
};
#endif /* PhysicsJoints2_hpp */
//
// PhysicsJoints2.cpp
// day01
//
// Created by MAC on 16/7/14.
//
//
#include "PhysicsJoints2.hpp"
Scene* PhysicsJoints2::createScene(){
auto scene = Scene::createWithPhysics();
//set the debug
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
//设置重力(x,y)
scene->getPhysicsWorld()->setGravity(Vec2(0, 0));
auto layer = PhysicsJoints2::create();
scene->addChild(layer);
return scene;
}
bool PhysicsJoints2::init(){
if (!Layer::init()) {
return false;
}
visiableSize = Director::getInstance()->getVisibleSize();
center = Vec2(visiableSize.width/2,visiableSize.height/2);//