mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of git://github.com/cocos2d/cocos2d-x into keyboard_test
Conflicts: samples/samples.xcodeproj/project.pbxproj
This commit is contained in:
commit
f403f7d683
|
@ -16,7 +16,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
|
|||
$(LOCAL_PATH)/../../cocos2dx \
|
||||
$(LOCAL_PATH)/../../cocos2dx/include \
|
||||
$(LOCAL_PATH)/../../cocos2dx/kazmath/include \
|
||||
$(LOCAL_PATH)/../../cocos2dx/platform/android
|
||||
$(LOCAL_PATH)/../../cocos2dx/platform/android
|
||||
|
||||
LOCAL_CFLAGS += -Wno-psabi
|
||||
LOCAL_EXPORT_CFLAGS += -Wno-psabi
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;..\Include;"$(ProjectDir)..\..\cocos2dx";"$(ProjectDir)..\..\cocos2dx\include";"$(ProjectDir)..\..\cocos2dx\kazmath\include";"$(ProjectDir)..\..\cocos2dx\platform\win32";"$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;..\Include;$(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
|
4
Makefile
4
Makefile
|
@ -12,7 +12,7 @@ box2d:
|
|||
box2d-clean:
|
||||
$(MAKE) -C external/Box2D/proj.$(PLATFORM) clean
|
||||
|
||||
libextensions: cocosdenshion chipmunk box2d
|
||||
libextensions: chipmunk cocosdenshion box2d
|
||||
$(MAKE) -C extensions/proj.$(PLATFORM)
|
||||
libextensions-clean:
|
||||
$(MAKE) -C extensions/proj.$(PLATFORM) clean
|
||||
|
@ -47,7 +47,7 @@ simplegame: libcocos2dx
|
|||
simplegame-clean:
|
||||
$(MAKE) -C samples/Cpp/SimpleGame/proj.$(PLATFORM) clean
|
||||
|
||||
all: box2d cocosdenshion libextensions libcocos2dx lua hellocpp testcpp simplegame
|
||||
all: chipmunk cocosdenshion libextensions libcocos2dx lua hellocpp testcpp simplegame
|
||||
clean: libcocos2dx-clean box2d-clean chipmunk-clean cocosdenshion-clean libextensions-clean lua-clean hellocpp-clean testcpp-clean simplegame-clean
|
||||
|
||||
# Haven't yet got the lua projects working with emscripten
|
||||
|
|
|
@ -1 +1 @@
|
|||
fad913317d2e64eb308c7066f450f3a351ee0aab
|
||||
29c3c2dfd8b683a800709d085839444c3a304a0d
|
|
@ -96,6 +96,21 @@ particle_nodes/CCParticleBatchNode.cpp \
|
|||
particle_nodes/CCParticleExamples.cpp \
|
||||
particle_nodes/CCParticleSystem.cpp \
|
||||
particle_nodes/CCParticleSystemQuad.cpp \
|
||||
physics/CCPhysicsBody.cpp \
|
||||
physics/CCPhysicsContact.cpp \
|
||||
physics/CCPhysicsJoint.cpp \
|
||||
physics/CCPhysicsShape.cpp \
|
||||
physics/CCPhysicsWorld.cpp \
|
||||
physics/Box2D/CCPhysicsBodyInfo.cpp \
|
||||
physics/Box2D/CCPhysicsContactInfo.cpp \
|
||||
physics/Box2D/CCPhysicsJointInfo.cpp \
|
||||
physics/Box2D/CCPhysicsShapeInfo.cpp \
|
||||
physics/Box2D/CCPhysicsWorldInfo.cpp \
|
||||
physics/chipmunk/CCPhysicsBodyInfo.cpp \
|
||||
physics/chipmunk/CCPhysicsContactInfo.cpp \
|
||||
physics/chipmunk/CCPhysicsJointInfo.cpp \
|
||||
physics/chipmunk/CCPhysicsShapeInfo.cpp \
|
||||
physics/chipmunk/CCPhysicsWorldInfo.cpp \
|
||||
platform/CCEGLViewProtocol.cpp \
|
||||
platform/CCFileUtils.cpp \
|
||||
platform/CCSAXParser.cpp \
|
||||
|
@ -149,7 +164,8 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
|||
$(LOCAL_PATH)/platform/android \
|
||||
$(LOCAL_PATH)/platform/third_party/common/etc \
|
||||
$(LOCAL_PATH)/platform/third_party/common/s3tc \
|
||||
$(LOCAL_PATH)/platform/third_party/common/atitc
|
||||
$(LOCAL_PATH)/platform/third_party/common/atitc \
|
||||
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/include \
|
||||
|
@ -157,7 +173,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
|||
$(LOCAL_PATH)/platform/android \
|
||||
$(LOCAL_PATH)/platform/third_party/common/etc \
|
||||
$(LOCAL_PATH)/platform/third_party/common/s3tc \
|
||||
$(LOCAL_PATH)/platform/third_party/common/atitc
|
||||
$(LOCAL_PATH)/platform/third_party/common/atitc \
|
||||
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk
|
||||
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv2 \
|
||||
|
@ -176,6 +193,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libxml2_static
|
|||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libtiff_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libwebp_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_freetype2_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
|
||||
|
||||
# define the macro to compile through support/zip_support/ioapi.c
|
||||
LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API
|
||||
|
@ -188,3 +206,4 @@ $(call import-module,libpng)
|
|||
$(call import-module,libtiff)
|
||||
$(call import-module,libwebp)
|
||||
$(call import-module,libfreetype2)
|
||||
$(call import-module,external/chipmunk)
|
||||
|
|
|
@ -120,6 +120,13 @@ THE SOFTWARE.
|
|||
#include "particle_nodes/CCParticleExamples.h"
|
||||
#include "particle_nodes/CCParticleSystemQuad.h"
|
||||
|
||||
// physics
|
||||
#include "physics/CCPhysicsBody.h"
|
||||
#include "physics/CCPhysicsContact.h"
|
||||
#include "physics/CCPhysicsShape.h"
|
||||
#include "physics/CCPhysicsJoint.h"
|
||||
#include "physics/CCPhysicsWorld.h"
|
||||
|
||||
// platform
|
||||
#include "platform/CCDevice.h"
|
||||
#include "platform/CCCommon.h"
|
||||
|
|
|
@ -42,6 +42,7 @@ THE SOFTWARE.
|
|||
#include "event_dispatcher/CCAccelerationEvent.h"
|
||||
#include "event_dispatcher/CCAccelerationEventListener.h"
|
||||
#include "platform/CCDevice.h"
|
||||
#include "CCScene.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -475,6 +476,30 @@ void Layer::onTouchesCancelled(const std::vector<Touch*>& pTouches, Event *pEven
|
|||
CC_UNUSED_PARAM(pEvent);
|
||||
}
|
||||
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
void Layer::addChild(Node* child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void Layer::addChild(Node* child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void Layer::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
Node::addChild(child, zOrder, tag);
|
||||
|
||||
if (this->getParent() &&
|
||||
dynamic_cast<Scene*>(this->getParent()) != nullptr)
|
||||
{
|
||||
dynamic_cast<Scene*>(this->getParent())->addChildToPhysicsWorld(child);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// LayerRGBA
|
||||
LayerRGBA::LayerRGBA()
|
||||
: _displayedOpacity(255)
|
||||
|
|
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
|||
#ifdef EMSCRIPTEN
|
||||
#include "base_nodes/CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
#include "physics/CCPhysicsSetting.h"
|
||||
|
||||
#include "event_dispatcher/CCKeyboardEvent.h"
|
||||
|
||||
|
@ -178,6 +179,12 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual void onEnterTransitionDidFinish() override;
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
virtual void addChild(Node* child) override;
|
||||
virtual void addChild(Node* child, int zOrder) override;
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
||||
protected:
|
||||
void addTouchListener();
|
||||
|
|
|
@ -26,10 +26,16 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCScene.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCLayer.h"
|
||||
#include "sprite_nodes/CCSprite.h"
|
||||
#include "physics/CCPhysicsWorld.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Scene::Scene()
|
||||
#ifdef _physicsWorld
|
||||
: _physicsWorld(nullptr)
|
||||
#endif
|
||||
{
|
||||
_ignoreAnchorPointForPosition = true;
|
||||
setAnchorPoint(Point(0.5f, 0.5f));
|
||||
|
@ -68,4 +74,95 @@ Scene *Scene::create()
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
Scene *Scene::createWithPhysics()
|
||||
{
|
||||
Scene *pRet = new Scene();
|
||||
if (pRet && pRet->initWithPhysics())
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool Scene::initWithPhysics()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
Director * pDirector;
|
||||
CC_BREAK_IF( ! (pDirector = Director::getInstance()) );
|
||||
this->setContentSize(pDirector->getWinSize());
|
||||
CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::create()));
|
||||
_physicsWorld->setScene(this);
|
||||
|
||||
this->scheduleUpdate();
|
||||
// success
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
Node::addChild(child, zOrder, tag);
|
||||
|
||||
addChildToPhysicsWorld(child);
|
||||
}
|
||||
|
||||
void Scene::addChildToPhysicsWorld(Node* child)
|
||||
{
|
||||
if (_physicsWorld)
|
||||
{
|
||||
auto addToPhysicsWorldFunc = [this](Object* node) -> void
|
||||
{
|
||||
if (dynamic_cast<Sprite*>(node) != nullptr)
|
||||
{
|
||||
Sprite* sp = dynamic_cast<Sprite*>(node);
|
||||
|
||||
if (sp->getPhysicsBody())
|
||||
{
|
||||
_physicsWorld->addChild(sp->getPhysicsBody());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(dynamic_cast<Layer*>(child) != nullptr)
|
||||
{
|
||||
Object* subChild = nullptr;
|
||||
CCARRAY_FOREACH(child->getChildren(), subChild)
|
||||
{
|
||||
addToPhysicsWorldFunc(subChild);
|
||||
}
|
||||
}else
|
||||
{
|
||||
addToPhysicsWorldFunc(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::update(float delta)
|
||||
{
|
||||
Node::update(delta);
|
||||
|
||||
_physicsWorld->update(delta);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
#define __CCSCENE_H__
|
||||
|
||||
#include "base_nodes/CCNode.h"
|
||||
#include "physics/CCPhysicsWorld.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -50,7 +51,10 @@ class CC_DLL Scene : public Node
|
|||
{
|
||||
public:
|
||||
/** creates a new Scene object */
|
||||
static Scene *create(void);
|
||||
static Scene *create();
|
||||
#ifdef CC_USE_PHYSICS
|
||||
static Scene *createWithPhysics();
|
||||
#endif
|
||||
|
||||
Scene();
|
||||
/**
|
||||
|
@ -60,7 +64,30 @@ public:
|
|||
virtual ~Scene();
|
||||
|
||||
bool init();
|
||||
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
public:
|
||||
bool initWithPhysics();
|
||||
|
||||
virtual void addChild(Node* child) override;
|
||||
virtual void addChild(Node* child, int zOrder) override;
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
|
||||
/*
|
||||
* Update method will be called automatically every frame if "scheduleUpdate" is called, and the node is "live"
|
||||
*/
|
||||
virtual void update(float delta) override;
|
||||
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
|
||||
protected:
|
||||
virtual void addChildToPhysicsWorld(Node* child);
|
||||
|
||||
protected:
|
||||
PhysicsWorld* _physicsWorld;
|
||||
#endif // CC_USE_PHYSICS
|
||||
|
||||
friend class Layer;
|
||||
};
|
||||
|
||||
// end of scene group
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsBodyInfo.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsBodyInfo::PhysicsBodyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsBodyInfo::~PhysicsBodyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_BODY_INFO_H__
|
||||
#define __CCPHYSICS_BODY_INFO_H__
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsBodyInfo
|
||||
{
|
||||
public:
|
||||
PhysicsBodyInfo();
|
||||
~PhysicsBodyInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_BODY_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsContactInfo.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContactInfo::PhysicsContactInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsContactInfo::~PhysicsContactInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_CONTACT_INFO_H__
|
||||
#define __CCPHYSICS_CONTACT_INFO_H__
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsContactInfo
|
||||
{
|
||||
public:
|
||||
PhysicsContactInfo();
|
||||
~PhysicsContactInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_CONTACT_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_HELPER_H__
|
||||
#define __CCPHYSICS_HELPER_H__
|
||||
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsHelper
|
||||
{
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_HELPER_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsJointInfo.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsJointInfo::PhysicsJointInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsJointInfo::~PhysicsJointInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_JOINT_INFO_H__
|
||||
#define __CCPHYSICS_JOINT_INFO_H__
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsJointInfo
|
||||
{
|
||||
public:
|
||||
PhysicsJointInfo();
|
||||
~PhysicsJointInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_JOINT_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsShapeInfo.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsShapeInfo::PhysicsShapeInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsShapeInfo::~PhysicsShapeInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_SHAPE_INFO_H__
|
||||
#define __CCPHYSICS_SHAPE_INFO_H__
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsShapeInfo
|
||||
{
|
||||
public:
|
||||
PhysicsShapeInfo();
|
||||
~PhysicsShapeInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_SHAPE_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsWorldInfo.h"
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsWorldInfo::PhysicsWorldInfo()
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsWorldInfo::~PhysicsWorldInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#ifndef __CCPHYSICS_WORLD_INFO_H__
|
||||
#define __CCPHYSICS_WORLD_INFO_H__
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsWorldInfo
|
||||
{
|
||||
public:
|
||||
PhysicsWorldInfo();
|
||||
~PhysicsWorldInfo();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_WORLD_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D
|
|
@ -0,0 +1,394 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "CCPhysicsBody.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsShape.h"
|
||||
#include "CCPhysicsJoint.h"
|
||||
#include "CCPhysicsWorld.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsBodyInfo.h"
|
||||
#include "Box2D/CCPhysicsBodyInfo.h"
|
||||
#include "chipmunk/CCPhysicsJointInfo.h"
|
||||
#include "Box2D/CCPhysicsJointInfo.h"
|
||||
#include "chipmunk/CCPhysicsWorldInfo.h"
|
||||
#include "Box2D/CCPhysicsWorldInfo.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsHelper.h"
|
||||
#include "Box2D/CCPhysicsHelper.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
namespace
|
||||
{
|
||||
static const float MASS_DEFAULT = 1.0;
|
||||
static const float DENSITY_DEFAULT = 1.0;
|
||||
static const float ANGULARDAMPING_DEFAULT = 200;
|
||||
}
|
||||
|
||||
PhysicsBody::PhysicsBody()
|
||||
: _owner(nullptr)
|
||||
, _world(nullptr)
|
||||
, _info(nullptr)
|
||||
, _dynamic(false)
|
||||
, _massDefault(true)
|
||||
, _angularDampingDefault(true)
|
||||
, _mass(MASS_DEFAULT)
|
||||
, _area(0.0)
|
||||
, _density(DENSITY_DEFAULT)
|
||||
, _angularDamping(ANGULARDAMPING_DEFAULT)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsBody::~PhysicsBody()
|
||||
{
|
||||
CC_SAFE_DELETE(_info);
|
||||
|
||||
for (auto it = _shapes.begin(); it != _shapes.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
for (auto it = _joints.begin(); it != _joints.end(); ++it)
|
||||
{
|
||||
PhysicsJoint* joint = *it;
|
||||
PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyA() : joint->getBodyB();
|
||||
|
||||
other->_joints.erase(std::find(other->_joints.begin(), other->_joints.end(), joint));
|
||||
delete joint;
|
||||
}
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createCircle(float radius)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->init())
|
||||
{
|
||||
body->addCircle(radius);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createBox(Size size)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->init())
|
||||
{
|
||||
body->addBox(size);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createPolygon(Point* points, int count)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->init())
|
||||
{
|
||||
body->addPolygon(points, count);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createEdgeSegment(Point a, Point b, float border/* = 1*/)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->initStatic())
|
||||
{
|
||||
body->addEdgeSegment(a, b, border);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createEdgeBox(Size size, float border/* = 1*/)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->initStatic())
|
||||
{
|
||||
body->addEdgeBox(size, border);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createEdgePolygon(Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->initStatic())
|
||||
{
|
||||
body->addEdgePolygon(points, count, border);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsBody* PhysicsBody::createEdgeChain(Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
PhysicsBody* body = new PhysicsBody();
|
||||
if (body && body->initStatic())
|
||||
{
|
||||
body->addEdgeChain(points, count);
|
||||
body->autorelease();
|
||||
return body;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(body);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsShapeCircle* PhysicsBody::addCircle(float radius, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
_area = PhysicsHelper::cpfloat2float(cpAreaForCircle(0, radius));
|
||||
setMass((_massDefault ? 0 : getMass()) + _area * _density);
|
||||
|
||||
setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping())
|
||||
+ PhysicsHelper::cpfloat2float(cpMomentForCircle(getMass(), 0, radius, PhysicsHelper::point2cpv(offset))));
|
||||
|
||||
return PhysicsShapeCircle::create(this, radius, offset);
|
||||
}
|
||||
|
||||
PhysicsShapeBox* PhysicsBody::addBox(Size size, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
cpVect cpOffset = PhysicsHelper::size2cpv(size);
|
||||
cpVect vec[4] = {};
|
||||
vec[0] = cpv(0, 0);
|
||||
vec[1] = cpv(0, cpOffset.y);
|
||||
vec[2] = cpv(cpOffset.x, cpOffset.y);
|
||||
vec[3] = cpv(cpOffset.x, 0);
|
||||
|
||||
_area = PhysicsHelper::cpfloat2float(cpAreaForPoly(4, vec));
|
||||
setMass((_massDefault ? 0 : getMass()) + _area * _density);
|
||||
|
||||
setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping())
|
||||
+ PhysicsHelper::cpfloat2float(cpMomentForBox(getMass(), PhysicsHelper::float2cpfloat(size.width), PhysicsHelper::float2cpfloat(size.height))));
|
||||
|
||||
return PhysicsShapeBox::create(this, size, offset);
|
||||
}
|
||||
|
||||
PhysicsShapePolygon* PhysicsBody::addPolygon(Point* points, int count, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
cpVect* vec = new cpVect[count];
|
||||
PhysicsHelper::points2cpvs(points, vec, count);
|
||||
_area = PhysicsHelper::cpfloat2float(cpAreaForPoly(count, vec));
|
||||
|
||||
setAngularDamping((_angularDampingDefault ? 0 : getAngularDamping())
|
||||
+ PhysicsHelper::cpfloat2float(cpMomentForPoly(getMass(), count, vec, PhysicsHelper::point2cpv(offset))));
|
||||
|
||||
delete[] vec;
|
||||
|
||||
return PhysicsShapePolygon::create(this, points, count, offset);
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeSegment* PhysicsBody::addEdgeSegment(Point a, Point b, float border/* = 1*/)
|
||||
{
|
||||
return PhysicsShapeEdgeSegment::create(this, a, b, border);
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeBox* PhysicsBody::addEdgeBox(Size size, float border/* = 1*/, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
return PhysicsShapeEdgeBox::create(this, size, border, offset);
|
||||
}
|
||||
|
||||
PhysicsShapeEdgePolygon* PhysicsBody::addEdgePolygon(Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
return PhysicsShapeEdgePolygon::create(this, points, count);
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeChain* PhysicsBody::addEdgeChain(Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
return PhysicsShapeEdgeChain::create(this, points, count, border);
|
||||
}
|
||||
|
||||
bool PhysicsBody::init()
|
||||
{
|
||||
do
|
||||
{
|
||||
_info = new PhysicsBodyInfo();
|
||||
CC_BREAK_IF(_info == nullptr);
|
||||
|
||||
_info->body = cpBodyNew(PhysicsHelper::float2cpfloat(_mass), PhysicsHelper::float2cpfloat(_angularDamping));
|
||||
CC_BREAK_IF(_info->body == nullptr);
|
||||
_dynamic = true;
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PhysicsBody::setDynamic(bool dynamic)
|
||||
{
|
||||
_dynamic = dynamic;
|
||||
if (_world != nullptr && cpBodyIsStatic(_info->body) == (cpBool)_dynamic)
|
||||
{
|
||||
if (dynamic)
|
||||
{
|
||||
cpSpaceConvertBodyToDynamic(_world->_info->space, _info->body, _mass, _angularDamping);
|
||||
}else
|
||||
{
|
||||
cpSpaceConvertBodyToStatic(_world->_info->space, _info->body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PhysicsBody::initStatic()
|
||||
{
|
||||
do
|
||||
{
|
||||
_info = new PhysicsBodyInfo();
|
||||
CC_BREAK_IF(_info == nullptr);
|
||||
|
||||
_info->body = cpBodyNewStatic();
|
||||
CC_BREAK_IF(_info->body == nullptr);
|
||||
_dynamic = false;
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PhysicsBody::setPosition(Point position)
|
||||
{
|
||||
cpBodySetPos(_info->body, PhysicsHelper::point2cpv(position));
|
||||
}
|
||||
|
||||
void PhysicsBody::setRotation(float rotation)
|
||||
{
|
||||
cpBodySetAngle(_info->body, PhysicsHelper::float2cpfloat(rotation));
|
||||
}
|
||||
|
||||
Point PhysicsBody::getPosition() const
|
||||
{
|
||||
cpVect vec = cpBodyGetPos(_info->body);
|
||||
return PhysicsHelper::cpv2point(vec);
|
||||
}
|
||||
|
||||
float PhysicsBody::getRotation() const
|
||||
{
|
||||
return -PhysicsHelper::cpfloat2float(cpBodyGetAngle(_info->body) / 3.14f * 180.0f);
|
||||
}
|
||||
|
||||
void PhysicsBody::addShape(PhysicsShape* shape)
|
||||
{
|
||||
if (shape == nullptr) return;
|
||||
|
||||
_shapes.push_back(shape);
|
||||
|
||||
if (_world != nullptr) _world->addShape(shape);
|
||||
}
|
||||
|
||||
void PhysicsBody::applyForce(Point force)
|
||||
{
|
||||
applyForce(force, Point());
|
||||
}
|
||||
|
||||
void PhysicsBody::applyForce(Point force, Point offset)
|
||||
{
|
||||
cpBodyApplyForce(_info->body, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
|
||||
}
|
||||
|
||||
void PhysicsBody::applyImpulse(Point impulse)
|
||||
{
|
||||
applyImpulse(impulse, Point());
|
||||
}
|
||||
|
||||
void PhysicsBody::applyImpulse(Point impulse, Point offset)
|
||||
{
|
||||
cpBodyApplyImpulse(_info->body, PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset));
|
||||
}
|
||||
|
||||
void PhysicsBody::applyTorque(float torque)
|
||||
{
|
||||
cpBodySetTorque(_info->body, PhysicsHelper::float2cpfloat(torque));
|
||||
}
|
||||
|
||||
void PhysicsBody::setMass(float mass)
|
||||
{
|
||||
_mass = mass;
|
||||
_massDefault = false;
|
||||
|
||||
cpBodySetMass(_info->body, PhysicsHelper::float2cpfloat(_mass));
|
||||
}
|
||||
|
||||
void PhysicsBody::setAngularDamping(float angularDamping)
|
||||
{
|
||||
_angularDamping = angularDamping;
|
||||
_angularDampingDefault = false;
|
||||
|
||||
cpBodySetMoment(_info->body, _angularDamping);
|
||||
}
|
||||
|
||||
//Clonable* PhysicsBody::clone() const
|
||||
//{
|
||||
// PhysicsBody* body = new PhysicsBody();
|
||||
//
|
||||
// body->autorelease();
|
||||
//
|
||||
// return body;
|
||||
//}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,259 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#ifndef __CCPHYSICS_BODY_H__
|
||||
#define __CCPHYSICS_BODY_H__
|
||||
|
||||
#include "cocoa/CCObject.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
#include <vector>
|
||||
|
||||
NS_CC_BEGIN
|
||||
class Sprite;
|
||||
class PhysicsWorld;
|
||||
class PhysicsJoint;
|
||||
class PhysicsShape;
|
||||
class PhysicsShapeCircle;
|
||||
class PhysicsShapeBox;
|
||||
class PhysicsShapePolygon;
|
||||
class PhysicsShapeEdgeSegment;
|
||||
class PhysicsShapeEdgeBox;
|
||||
class PhysicsShapeEdgePolygon;
|
||||
class PhysicsShapeEdgeChain;
|
||||
|
||||
class PhysicsBodyInfo;
|
||||
/**
|
||||
* A body affect by physics.
|
||||
* it can attach one or more shapes.
|
||||
*/
|
||||
class PhysicsBody : public Object//, public Clonable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Create a body contains a circle shape.
|
||||
*/
|
||||
static PhysicsBody* createCircle(float radius);
|
||||
/**
|
||||
* @brief Create a body contains a box shape.
|
||||
*/
|
||||
static PhysicsBody* createBox(Size size);
|
||||
/**
|
||||
* @brief Create a body contains a polygon shape.
|
||||
* points is an array of Point structs defining a convex hull with a clockwise winding.
|
||||
*/
|
||||
static PhysicsBody* createPolygon(Point* points, int count);
|
||||
|
||||
/**
|
||||
* @brief Create a body contains a EdgeSegment shape.
|
||||
*/
|
||||
static PhysicsBody* createEdgeSegment(Point a, Point b, float border = 1);
|
||||
/**
|
||||
* @brief Create a body contains a EdgeBox shape.
|
||||
*/
|
||||
static PhysicsBody* createEdgeBox(Size size, float border = 1);
|
||||
/**
|
||||
* @brief Create a body contains a EdgePolygon shape.
|
||||
*/
|
||||
static PhysicsBody* createEdgePolygon(Point* points, int count, float border = 1);
|
||||
/**
|
||||
* @brief Create a body contains a EdgeChain shape.
|
||||
*/
|
||||
static PhysicsBody* createEdgeChain(Point* points, int count, float border = 1);
|
||||
|
||||
/**
|
||||
* @brief Attach a circle shape with body
|
||||
*/
|
||||
virtual PhysicsShapeCircle* addCircle(float radius, Point offset = Point(0, 0));
|
||||
/**
|
||||
* @brief Attach a box shape with body
|
||||
*/
|
||||
virtual PhysicsShapeBox* addBox(Size size, Point offset = Point(0, 0));
|
||||
/**
|
||||
* @brief Attach a polygon shape with body
|
||||
*/
|
||||
virtual PhysicsShapePolygon* addPolygon(Point* points, int count, Point offset = Point(0, 0));
|
||||
|
||||
/**
|
||||
* @brief Attach a edge segment shape with body
|
||||
*/
|
||||
virtual PhysicsShapeEdgeSegment* addEdgeSegment(Point a, Point b, float border = 1);
|
||||
/**
|
||||
* @brief Attach a edge box shape with body
|
||||
*/
|
||||
virtual PhysicsShapeEdgeBox* addEdgeBox(Size size, float border = 1, Point offset = Point(0, 0));
|
||||
/**
|
||||
* @brief Attach a edge polygon shape with body
|
||||
* points is an array of Point structs defining a convex hull with a clockwise winding.
|
||||
*/
|
||||
virtual PhysicsShapeEdgePolygon* addEdgePolygon(Point* points, int count, float border = 1);
|
||||
/**
|
||||
* @brief Attach a edge chain shape with body
|
||||
* points is an array of Point structs defining a convex hull with a clockwise winding.
|
||||
*/
|
||||
virtual PhysicsShapeEdgeChain* addEdgeChain(Point* points, int count, float border = 1);
|
||||
|
||||
/**
|
||||
* @brief Applies a immediate force to body.
|
||||
*/
|
||||
virtual void applyForce(Point force);
|
||||
/**
|
||||
* @brief Applies a immediate force to body.
|
||||
*/
|
||||
virtual void applyForce(Point force, Point offset);
|
||||
/**
|
||||
* @brief Applies a continuous force to body.
|
||||
*/
|
||||
virtual void applyImpulse(Point impulse);
|
||||
/**
|
||||
* @brief Applies a continuous force to body.
|
||||
*/
|
||||
virtual void applyImpulse(Point impulse, Point offset);
|
||||
/**
|
||||
* @brief Applies a torque force to body.
|
||||
*/
|
||||
virtual void applyTorque(float torque);
|
||||
|
||||
/*
|
||||
* @brief get the body shapes.
|
||||
*/
|
||||
inline std::vector<PhysicsShape*>& getShapes() { return _shapes; }
|
||||
/*
|
||||
* @brief get the first body shapes.
|
||||
*/
|
||||
inline PhysicsShape* getShape() { return _shapes.size() >= 1 ? _shapes.front() : nullptr; }
|
||||
/*
|
||||
* @brief remove a shape from body
|
||||
*/
|
||||
void removeShape(PhysicsShape* shape);
|
||||
/*
|
||||
* @brief remove all shapes
|
||||
*/
|
||||
void removeAllShapes();
|
||||
|
||||
/*
|
||||
* @brief get the world body added to.
|
||||
*/
|
||||
inline PhysicsWorld* getWorld() const { return _world; }
|
||||
/*
|
||||
* @brief get all joints the body have
|
||||
*/
|
||||
inline const std::vector<PhysicsJoint*>* getJoints() const { return &_joints; }
|
||||
|
||||
/*
|
||||
* @brief get the sprite the body set to.
|
||||
*/
|
||||
inline Sprite* getOwner() const { return _owner; }
|
||||
|
||||
void setCategoryBitmask(int bitmask);
|
||||
inline int getCategoryBitmask() const { return _categoryBitmask; }
|
||||
void setContactTestBitmask(int bitmask);
|
||||
inline int getContactTestBitmask() const { return _contactTestBitmask; }
|
||||
void setCollisionBitmask(int bitmask);
|
||||
inline int getCollisionBitmask() const { return _collisionBitmask; }
|
||||
|
||||
/*
|
||||
* @brief get the body position.
|
||||
*/
|
||||
Point getPosition() const;
|
||||
/*
|
||||
* @brief get the body rotation.
|
||||
*/
|
||||
float getRotation() const;
|
||||
|
||||
/*
|
||||
* @brief test the body is dynamic or not.
|
||||
* a dynamic body will effect with gravity.
|
||||
*/
|
||||
inline bool isDynamic() { return _dynamic; }
|
||||
/*
|
||||
* @brief set dynamic to body.
|
||||
* a dynamic body will effect with gravity.
|
||||
*/
|
||||
void setDynamic(bool dynamic);
|
||||
|
||||
/*
|
||||
* @brief set the body mass.
|
||||
*/
|
||||
void setMass(float mass);
|
||||
/*
|
||||
* @brief get the body mass.
|
||||
*/
|
||||
inline float getMass() { return _mass; }
|
||||
|
||||
/*
|
||||
* @brief set angular damping.
|
||||
*/
|
||||
void setAngularDamping(float angularDamping);
|
||||
/*
|
||||
* @brief get angular damping.
|
||||
*/
|
||||
inline float getAngularDamping() { return _angularDamping; }
|
||||
|
||||
//virtual Clonable* clone() const override;
|
||||
|
||||
protected:
|
||||
|
||||
bool init();
|
||||
bool initStatic();
|
||||
|
||||
virtual void setPosition(Point position);
|
||||
virtual void setRotation(float rotation);
|
||||
virtual void addShape(PhysicsShape* shape);
|
||||
|
||||
protected:
|
||||
PhysicsBody();
|
||||
virtual ~PhysicsBody();
|
||||
|
||||
protected:
|
||||
Sprite* _owner;
|
||||
std::vector<PhysicsJoint*> _joints;
|
||||
std::vector<PhysicsShape*> _shapes;
|
||||
PhysicsWorld* _world;
|
||||
PhysicsBodyInfo* _info;
|
||||
bool _dynamic;
|
||||
bool _massDefault;
|
||||
bool _angularDampingDefault;
|
||||
float _mass;
|
||||
float _area;
|
||||
float _density;
|
||||
float _angularDamping;
|
||||
|
||||
int _categoryBitmask;
|
||||
int _contactTestBitmask;
|
||||
int _collisionBitmask;
|
||||
|
||||
friend class PhysicsWorld;
|
||||
friend class PhysicsShape;
|
||||
friend class PhysicsJoint;
|
||||
friend class Sprite;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __CCPHYSICS_BODY_H__
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,153 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "CCPhysicsContact.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "chipmunk/CCPhysicsContactInfo.h"
|
||||
#include "Box2D/CCPhysicsContactInfo.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContact::PhysicsContact()
|
||||
: _shapeA(nullptr)
|
||||
, _shapeB(nullptr)
|
||||
, _info(nullptr)
|
||||
, _data(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContact::~PhysicsContact()
|
||||
{
|
||||
CC_SAFE_DELETE(_info);
|
||||
}
|
||||
|
||||
PhysicsContact* PhysicsContact::create(PhysicsShape* a, PhysicsShape* b)
|
||||
{
|
||||
PhysicsContact * contact = new PhysicsContact();
|
||||
if(contact && contact->init(a, b))
|
||||
{
|
||||
return contact;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(contact);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsContact::init(PhysicsShape* a, PhysicsShape* b)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(a == nullptr || b == nullptr);
|
||||
|
||||
CC_BREAK_IF(!(_info = new PhysicsContactInfo(this)));
|
||||
|
||||
_shapeA = a;
|
||||
_shapeB = b;
|
||||
|
||||
return true;
|
||||
} while(false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsContactPreSolve implementation
|
||||
PhysicsContactPreSolve::PhysicsContactPreSolve()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContactPreSolve::~PhysicsContactPreSolve()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContactPreSolve* PhysicsContactPreSolve::create()
|
||||
{
|
||||
PhysicsContactPreSolve * solve = new PhysicsContactPreSolve();
|
||||
if(solve && solve->init())
|
||||
{
|
||||
return solve;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(solve);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsContactPreSolve::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// PhysicsContactPostSolve implementation
|
||||
PhysicsContactPostSolve::PhysicsContactPostSolve()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContactPostSolve::~PhysicsContactPostSolve()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContactPostSolve* PhysicsContactPostSolve::create()
|
||||
{
|
||||
PhysicsContactPostSolve * solve = new PhysicsContactPostSolve();
|
||||
if(solve && solve->init())
|
||||
{
|
||||
return solve;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(solve);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsContactPostSolve::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PhysicsContactListener::PhysicsContactListener()
|
||||
: onContactBegin(nullptr)
|
||||
, onContactPreSolve(nullptr)
|
||||
, onContactPostSolve(nullptr)
|
||||
, onContactEnd(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsContactListener::~PhysicsContactListener()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,143 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#ifndef __CCPHYSICS_CONTACT_H__
|
||||
#define __CCPHYSICS_CONTACT_H__
|
||||
|
||||
#include "cocoa/CCObject.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsShape;
|
||||
class PhysicsWorld;
|
||||
|
||||
class PhysicsContactInfo;
|
||||
|
||||
/**
|
||||
* @brief Contact infomation. it will created automatically when two shape contact with each other. and it will destoried automatically when two shape separated.
|
||||
*/
|
||||
class PhysicsContact
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* @brief get contact shape A.
|
||||
*/
|
||||
inline PhysicsShape* getShapeA() { return _shapeA; }
|
||||
/*
|
||||
* @brief get contact shape B.
|
||||
*/
|
||||
inline PhysicsShape* getShapeB() { return _shapeB; }
|
||||
/*
|
||||
* @brief get data.
|
||||
*/
|
||||
inline void* getData() { return _data; }
|
||||
/*
|
||||
* @brief set data to contact. you must manage the memory yourself, Generally you can set data at contact begin, and distory it at contact end.
|
||||
*/
|
||||
inline void setData(void* data) { _data = data; }
|
||||
|
||||
private:
|
||||
static PhysicsContact* create(PhysicsShape* a, PhysicsShape* b);
|
||||
bool init(PhysicsShape* a, PhysicsShape* b);
|
||||
|
||||
private:
|
||||
PhysicsContact();
|
||||
~PhysicsContact();
|
||||
|
||||
private:
|
||||
PhysicsShape* _shapeA;
|
||||
PhysicsShape* _shapeB;
|
||||
PhysicsContactInfo* _info;
|
||||
void* _data;
|
||||
|
||||
friend class PhysicsWorld;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief presolve value generated when onContactPreSolve called.
|
||||
*/
|
||||
class PhysicsContactPreSolve
|
||||
{
|
||||
private:
|
||||
PhysicsContactPreSolve();
|
||||
~PhysicsContactPreSolve();
|
||||
|
||||
static PhysicsContactPreSolve* create();
|
||||
bool init();
|
||||
|
||||
friend class PhysicsWorld;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief postsolve value generated when onContactPostSolve called.
|
||||
*/
|
||||
class PhysicsContactPostSolve
|
||||
{
|
||||
private:
|
||||
PhysicsContactPostSolve();
|
||||
~PhysicsContactPostSolve();
|
||||
|
||||
static PhysicsContactPostSolve* create();
|
||||
bool init();
|
||||
|
||||
friend class PhysicsWorld;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief contact listener.
|
||||
*/
|
||||
class PhysicsContactListener
|
||||
{
|
||||
public:
|
||||
PhysicsContactListener();
|
||||
virtual ~PhysicsContactListener();
|
||||
|
||||
public:
|
||||
/*
|
||||
* @brief it will called at two shapes start to contact, and only call it once.
|
||||
*/
|
||||
std::function<bool(const PhysicsContact& contact)> onContactBegin;
|
||||
/*
|
||||
* @brief Two shapes are touching during this step. Return false from the callback to make world ignore the collision this step or true to process it normally. Additionally, you may override collision values, elasticity, or surface velocity values.
|
||||
*/
|
||||
std::function<bool(const PhysicsContact& contact, const PhysicsContactPreSolve& solve)> onContactPreSolve;
|
||||
/*
|
||||
* @brief Two shapes are touching and their collision response has been processed. You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts. See cpArbiter for more info
|
||||
*/
|
||||
std::function<void(const PhysicsContact& contact, const PhysicsContactPostSolve& solve)> onContactPostSolve;
|
||||
/*
|
||||
* @brief it will called at two shapes separated, and only call it once.
|
||||
* onContactBegin and onContactEnd will called in pairs.
|
||||
*/
|
||||
std::function<void(const PhysicsContact& contact)> onContactEnd;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif //__CCPHYSICS_CONTACT_H__
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,255 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsJoint.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsJointInfo.h"
|
||||
#include "Box2D/CCPhysicsJointInfo.h"
|
||||
#include "chipmunk/CCPhysicsBodyInfo.h"
|
||||
#include "Box2D/CCPhysicsBodyInfo.h"
|
||||
#include "chipmunk/CCPhysicsHelper.h"
|
||||
#include "Box2D/CCPhysicsHelper.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsJoint::PhysicsJoint()
|
||||
: _bodyA(nullptr)
|
||||
, _bodyB(nullptr)
|
||||
, _info(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJoint::~PhysicsJoint()
|
||||
{
|
||||
CC_SAFE_DELETE(_info);
|
||||
|
||||
CC_SAFE_RELEASE(_bodyA);
|
||||
CC_SAFE_RELEASE(_bodyB);
|
||||
}
|
||||
|
||||
bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(a == nullptr || b == nullptr);
|
||||
|
||||
CC_BREAK_IF(!(_info = new PhysicsJointInfo()));
|
||||
|
||||
_bodyA = a;
|
||||
_bodyA->retain();
|
||||
_bodyA->_joints.push_back(this);
|
||||
_bodyB = b;
|
||||
_bodyB->retain();
|
||||
_bodyB->_joints.push_back(this);
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PhysicsJointPin::PhysicsJointPin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointPin::~PhysicsJointPin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointFixed::PhysicsJointFixed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointFixed::~PhysicsJointFixed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointSliding::PhysicsJointSliding()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointSliding::~PhysicsJointSliding()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointLimit::PhysicsJointLimit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsJointLimit::~PhysicsJointLimit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
PhysicsBodyInfo* PhysicsJoint::bodyInfo(PhysicsBody* body) const
|
||||
{
|
||||
return body->_info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PhysicsJointFixed* PhysicsJointFixed::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr)
|
||||
{
|
||||
PhysicsJointFixed* joint = new PhysicsJointFixed();
|
||||
|
||||
if (joint && joint->init(a, b, anchr))
|
||||
{
|
||||
joint->autorelease();
|
||||
return joint;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(joint);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsJoint::init(a, b));
|
||||
|
||||
_info->joint = cpPivotJointNew(bodyInfo(a)->body, bodyInfo(b)->body,
|
||||
PhysicsHelper::point2cpv(anchr));
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PhysicsJointPin* PhysicsJointPin::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2)
|
||||
{
|
||||
PhysicsJointPin* joint = new PhysicsJointPin();
|
||||
|
||||
if (joint && joint->init(a, b, anchr1, anchr2))
|
||||
{
|
||||
joint->autorelease();
|
||||
return joint;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(joint);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Point& anchr1, const Point& anchr2)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsJoint::init(a, b));
|
||||
|
||||
_info->joint = cpPinJointNew(bodyInfo(a)->body, bodyInfo(b)->body, PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr2));
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PhysicsJointSliding* PhysicsJointSliding::create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr)
|
||||
{
|
||||
PhysicsJointSliding* joint = new PhysicsJointSliding();
|
||||
|
||||
if (joint && joint->init(a, b, grooveA, grooveB, anchr))
|
||||
{
|
||||
return joint;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(joint);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsJointSliding::init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsJoint::init(a, b));
|
||||
|
||||
_info->joint = cpGrooveJointNew(bodyInfo(a)->body, bodyInfo(b)->body,
|
||||
PhysicsHelper::point2cpv(grooveA),
|
||||
PhysicsHelper::point2cpv(grooveB),
|
||||
PhysicsHelper::point2cpv(anchr));
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PhysicsJointLimit* PhysicsJointLimit::create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max)
|
||||
{
|
||||
PhysicsJointLimit* joint = new PhysicsJointLimit();
|
||||
|
||||
if (joint && joint->init(a, b, anchr1, anchr2, min, max))
|
||||
{
|
||||
return joint;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(joint);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsJoint::init(a, b));
|
||||
|
||||
_info->joint = cpSlideJointNew(bodyInfo(a)->body, bodyInfo(b)->body,
|
||||
PhysicsHelper::point2cpv(anchr1),
|
||||
PhysicsHelper::point2cpv(anchr2),
|
||||
PhysicsHelper::float2cpfloat(min),
|
||||
PhysicsHelper::float2cpfloat(max));
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,153 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#ifndef __CCPHYSICS_JOINT_H__
|
||||
#define __CCPHYSICS_JOINT_H__
|
||||
|
||||
#include "cocoa/CCObject.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsBody;
|
||||
class PhysicsJointInfo;
|
||||
class PhysicsBodyInfo;
|
||||
|
||||
/*
|
||||
* @brief An PhysicsJoint object connects two physics bodies together.
|
||||
*/
|
||||
class PhysicsJoint : public Object
|
||||
{
|
||||
protected:
|
||||
PhysicsJoint();
|
||||
virtual ~PhysicsJoint() = 0;
|
||||
|
||||
public:
|
||||
PhysicsBody* getBodyA() { return _bodyA; }
|
||||
PhysicsBody* getBodyB() { return _bodyB; }
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* a, PhysicsBody* b);
|
||||
|
||||
/**
|
||||
* PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
|
||||
*/
|
||||
PhysicsBodyInfo* bodyInfo(PhysicsBody* body) const;
|
||||
|
||||
protected:
|
||||
PhysicsBody* _bodyA;
|
||||
PhysicsBody* _bodyB;
|
||||
PhysicsJointInfo* _info;
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later.
|
||||
*/
|
||||
class PhysicsJointFixed : public PhysicsJoint
|
||||
{
|
||||
public:
|
||||
PhysicsJointFixed* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
||||
|
||||
protected:
|
||||
PhysicsJointFixed();
|
||||
virtual ~PhysicsJointFixed();
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief A sliding joint allows the two bodies to slide along a chosen axis.
|
||||
*/
|
||||
class PhysicsJointSliding : public PhysicsJoint
|
||||
{
|
||||
public:
|
||||
PhysicsJointSliding* create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
||||
|
||||
protected:
|
||||
PhysicsJointSliding();
|
||||
virtual ~PhysicsJointSliding();
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies.
|
||||
*/
|
||||
class PhysicsJointSpring : public PhysicsJoint
|
||||
{
|
||||
public:
|
||||
PhysicsJointSpring* create();
|
||||
|
||||
protected:
|
||||
bool init();
|
||||
|
||||
protected:
|
||||
PhysicsJointSpring();
|
||||
virtual ~PhysicsJointSpring();
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
|
||||
*/
|
||||
class PhysicsJointLimit : public PhysicsJoint
|
||||
{
|
||||
public:
|
||||
PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2, float min, float max);
|
||||
|
||||
protected:
|
||||
PhysicsJointLimit();
|
||||
virtual ~PhysicsJointLimit();
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together.
|
||||
*/
|
||||
class PhysicsJointPin : public PhysicsJoint
|
||||
{
|
||||
public:
|
||||
static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
||||
|
||||
protected:
|
||||
PhysicsJointPin();
|
||||
virtual ~PhysicsJointPin();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __CCPHYSICS_JOINT_H__
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,46 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCPHYSICS_SETTING_H__
|
||||
#define __CCPHYSICS_SETTING_H__
|
||||
|
||||
#define CC_PHYSICS_UNKNOWN 0
|
||||
#define CC_PHYSICS_BOX2D 1
|
||||
#define CC_PHYSICS_CHIPMUNK 2
|
||||
|
||||
#define CC_USE_CHIPMUNK
|
||||
|
||||
#ifdef CC_USE_BOX2D
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_BOX2D
|
||||
#elif defined(CC_USE_CHIPMUNK)
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_CHIPMUNK
|
||||
#else
|
||||
#define CC_PHYSICS_ENGINE CC_PHYSICS_UNKNOWN
|
||||
#endif
|
||||
|
||||
#if (CC_PHYSICS_ENGINE != CC_PHYSICS_UNKNOWN)
|
||||
#define CC_USE_PHYSICS
|
||||
#endif
|
||||
|
||||
#endif // __CCPHYSICS_SETTING_H__
|
|
@ -0,0 +1,432 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsShape.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsBodyInfo.h"
|
||||
#include "Box2D/CCPhysicsBodyInfo.h"
|
||||
#include "chipmunk/CCPhysicsShapeInfo.h"
|
||||
#include "Box2D/CCPhysicsShapeInfo.h"
|
||||
#include "chipmunk/CCPhysicsHelper.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsShape::PhysicsShape()
|
||||
: _body(nullptr)
|
||||
, _info(nullptr)
|
||||
, _type(Type::UNKNOWN)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShape::~PhysicsShape()
|
||||
{
|
||||
CC_SAFE_DELETE(_info);
|
||||
}
|
||||
|
||||
bool PhysicsShape::init(PhysicsBody* body, Type type)
|
||||
{
|
||||
if (body == nullptr) return false;
|
||||
|
||||
_body = body;
|
||||
|
||||
_info = new PhysicsShapeInfo(this);
|
||||
if (_info == nullptr) return false;
|
||||
|
||||
_type = type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhysicsShape::addToBody()
|
||||
{
|
||||
if(_body != nullptr) _body->addShape(this);
|
||||
}
|
||||
|
||||
PhysicsBodyInfo* PhysicsShape::bodyInfo() const
|
||||
{
|
||||
return _body->_info;
|
||||
}
|
||||
|
||||
PhysicsShapeCircle::PhysicsShapeCircle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeCircle::~PhysicsShapeCircle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeBox::PhysicsShapeBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeBox::~PhysicsShapeBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapePolygon::PhysicsShapePolygon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapePolygon::~PhysicsShapePolygon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeBox::PhysicsShapeEdgeBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeBox::~PhysicsShapeEdgeBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeChain::PhysicsShapeEdgeChain()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeChain::~PhysicsShapeEdgeChain()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgePolygon::PhysicsShapeEdgePolygon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgePolygon::~PhysicsShapeEdgePolygon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeSegment::PhysicsShapeEdgeSegment()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsShapeEdgeSegment::~PhysicsShapeEdgeSegment()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
// PhysicsShapeCircle
|
||||
PhysicsShapeCircle* PhysicsShapeCircle::create(PhysicsBody* body, float radius, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
PhysicsShapeCircle* shape = new PhysicsShapeCircle();
|
||||
if (shape && shape->init(body, radius, offset))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeCircle::init(PhysicsBody* body, float radius, Point offset /*= Point(0, 0)*/)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::CIRCLE));
|
||||
|
||||
cpShape* shape = cpCircleShapeNew(bodyInfo()->body, radius, PhysicsHelper::point2cpv(offset));
|
||||
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
|
||||
_info->add(shape);
|
||||
addToBody();
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeEdgeSegment
|
||||
PhysicsShapeEdgeSegment* PhysicsShapeEdgeSegment::create(PhysicsBody* body, Point a, Point b, float border/* = 1*/)
|
||||
{
|
||||
PhysicsShapeEdgeSegment* shape = new PhysicsShapeEdgeSegment();
|
||||
if (shape && shape->init(body, a, b, border))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeEdgeSegment::init(PhysicsBody* body, Point a, Point b, float border/* = 1*/)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGESEGMENT));
|
||||
|
||||
cpShape* shape = cpSegmentShapeNew(bodyInfo()->body,
|
||||
PhysicsHelper::point2cpv(a),
|
||||
PhysicsHelper::point2cpv(b),
|
||||
PhysicsHelper::float2cpfloat(border));
|
||||
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
|
||||
_info->add(shape);
|
||||
addToBody();
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeBox
|
||||
PhysicsShapeBox* PhysicsShapeBox::create(PhysicsBody* body, Size size, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
PhysicsShapeBox* shape = new PhysicsShapeBox();
|
||||
if (shape && shape->init(body, size, offset))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeBox::init(PhysicsBody* body, Size size, Point offset /*= Point(0, 0)*/)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::BOX));
|
||||
|
||||
cpShape* shape = cpBoxShapeNew(bodyInfo()->body, PhysicsHelper::float2cpfloat(size.width), PhysicsHelper::float2cpfloat(size.height));
|
||||
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
|
||||
_info->add(shape);
|
||||
addToBody();
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeCircle
|
||||
PhysicsShapePolygon* PhysicsShapePolygon::create(PhysicsBody* body, Point* points, int count, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
PhysicsShapePolygon* shape = new PhysicsShapePolygon();
|
||||
if (shape && shape->init(body, points, count, offset))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapePolygon::init(PhysicsBody* body, Point* points, int count, Point offset /*= Point(0, 0)*/)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::POLYGEN));
|
||||
|
||||
cpVect* vecs = new cpVect[count];
|
||||
PhysicsHelper::points2cpvs(points, vecs, count);
|
||||
cpShape* shape = cpPolyShapeNew(bodyInfo()->body, count, vecs, PhysicsHelper::point2cpv(offset));
|
||||
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
|
||||
_info->add(shape);
|
||||
addToBody();
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeEdgeBox
|
||||
PhysicsShapeEdgeBox* PhysicsShapeEdgeBox::create(PhysicsBody* body, Size size, float border/* = 1*/, Point offset/* = Point(0, 0)*/)
|
||||
{
|
||||
PhysicsShapeEdgeBox* shape = new PhysicsShapeEdgeBox();
|
||||
if (shape && shape->init(body, size, border, offset))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeEdgeBox::init(PhysicsBody* body, Size size, float border/* = 1*/, Point offset/*= Point(0, 0)*/)
|
||||
{
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGEBOX));
|
||||
|
||||
Point bodyPos = body->getPosition();
|
||||
|
||||
cpVect vec[4] = {};
|
||||
vec[0] = PhysicsHelper::point2cpv(Point(bodyPos.x-size.width/2+offset.x, bodyPos.y-size.height/2+offset.y));
|
||||
vec[1] = PhysicsHelper::point2cpv(Point(bodyPos.x+size.width/2+offset.x, bodyPos.y-size.height/2+offset.y));
|
||||
vec[2] = PhysicsHelper::point2cpv(Point(bodyPos.x+size.width/2+offset.x, bodyPos.y+size.height/2+offset.y));
|
||||
vec[3] = PhysicsHelper::point2cpv(Point(bodyPos.x-size.width/2+offset.x, bodyPos.y+size.height/2+offset.y));
|
||||
|
||||
int i = 0;
|
||||
for (; i < 4; ++i)
|
||||
{
|
||||
cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[(i+1)%4],
|
||||
PhysicsHelper::float2cpfloat(border));
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
cpShapeSetElasticity(shape, 1.0f);
|
||||
cpShapeSetFriction(shape, 1.0f);
|
||||
_info->add(shape);
|
||||
}
|
||||
CC_BREAK_IF(i < 4);
|
||||
|
||||
addToBody();
|
||||
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeEdgeBox
|
||||
PhysicsShapeEdgePolygon* PhysicsShapeEdgePolygon::create(PhysicsBody* body, Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
PhysicsShapeEdgePolygon* shape = new PhysicsShapeEdgePolygon();
|
||||
if (shape && shape->init(body, points, count, border))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeEdgePolygon::init(PhysicsBody* body, Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
cpVect* vec = nullptr;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGEPOLYGEN));
|
||||
|
||||
vec = new cpVect[count];
|
||||
PhysicsHelper::points2cpvs(points, vec, count);
|
||||
|
||||
int i = 0;
|
||||
for (; i < count; ++i)
|
||||
{
|
||||
cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[(i+1)%count],
|
||||
PhysicsHelper::float2cpfloat(border));
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
cpShapeSetElasticity(shape, 1.0f);
|
||||
cpShapeSetFriction(shape, 1.0f);
|
||||
_info->add(shape);
|
||||
}
|
||||
CC_BREAK_IF(i < count);
|
||||
|
||||
addToBody();
|
||||
|
||||
if (vec != nullptr) delete[] vec;
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
if (vec != nullptr) delete[] vec;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// PhysicsShapeEdgeChain
|
||||
PhysicsShapeEdgeChain* PhysicsShapeEdgeChain::create(PhysicsBody* body, Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
PhysicsShapeEdgeChain* shape = new PhysicsShapeEdgeChain();
|
||||
if (shape && shape->init(body, points, count, border))
|
||||
{
|
||||
return shape;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(shape);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PhysicsShapeEdgeChain::init(PhysicsBody* body, Point* points, int count, float border/* = 1*/)
|
||||
{
|
||||
cpVect* vec = nullptr;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(!PhysicsShape::init(body, Type::EDGECHAIN));
|
||||
|
||||
vec = new cpVect[count];
|
||||
PhysicsHelper::points2cpvs(points, vec, count);
|
||||
|
||||
int i = 0;
|
||||
for (; i < count - 1; ++i)
|
||||
{
|
||||
cpShape* shape = cpSegmentShapeNew(bodyInfo()->body, vec[i], vec[i+1],
|
||||
PhysicsHelper::float2cpfloat(border));
|
||||
CC_BREAK_IF(shape == nullptr);
|
||||
cpShapeSetElasticity(shape, 1.0f);
|
||||
cpShapeSetFriction(shape, 1.0f);
|
||||
_info->add(shape);
|
||||
}
|
||||
CC_BREAK_IF(i < count);
|
||||
|
||||
addToBody();
|
||||
|
||||
if (vec != nullptr) delete[] vec;
|
||||
return true;
|
||||
} while (false);
|
||||
|
||||
if (vec != nullptr) delete[] vec;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,192 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#ifndef __CCPHYSICS_SHAPE_H__
|
||||
#define __CCPHYSICS_SHAPE_H__
|
||||
|
||||
#include "cocoa/CCObject.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsShapeInfo;
|
||||
class PhysicsBody;
|
||||
class PhysicsBodyInfo;
|
||||
|
||||
/**
|
||||
* @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it.
|
||||
*/
|
||||
class PhysicsShape : public Object
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
UNKNOWN,
|
||||
CIRCLE,
|
||||
BOX,
|
||||
POLYGEN,
|
||||
EDGESEGMENT,
|
||||
EDGEBOX,
|
||||
EDGEPOLYGEN,
|
||||
EDGECHAIN,
|
||||
};
|
||||
|
||||
public:
|
||||
inline PhysicsBody* getBody(){ return _body; }
|
||||
inline Type getType() { return _type; }
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* body, Type type);
|
||||
|
||||
/**
|
||||
* @brief PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
|
||||
*/
|
||||
PhysicsBodyInfo* bodyInfo() const;
|
||||
|
||||
void addToBody();
|
||||
|
||||
protected:
|
||||
PhysicsShape();
|
||||
virtual ~PhysicsShape() = 0;
|
||||
|
||||
protected:
|
||||
PhysicsBody* _body;
|
||||
PhysicsShapeInfo* _info;
|
||||
Type _type;
|
||||
|
||||
friend class PhysicsWorld;
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** A circle shape */
|
||||
class PhysicsShapeCircle : public PhysicsShape
|
||||
{
|
||||
protected:
|
||||
static PhysicsShapeCircle* create(PhysicsBody* body, float radius, Point offset = Point(0, 0));
|
||||
bool init(PhysicsBody* body, float radius, Point offset = Point(0, 0));
|
||||
|
||||
protected:
|
||||
PhysicsShapeCircle();
|
||||
virtual ~PhysicsShapeCircle();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** A box shape */
|
||||
class PhysicsShapeBox : public PhysicsShape
|
||||
{
|
||||
protected:
|
||||
static PhysicsShapeBox* create(PhysicsBody* body, Size size, Point offset = Point(0, 0));
|
||||
bool init(PhysicsBody* body, Size size, Point offset = Point(0, 0));
|
||||
|
||||
protected:
|
||||
PhysicsShapeBox();
|
||||
virtual ~PhysicsShapeBox();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** A polygon shape */
|
||||
class PhysicsShapePolygon : public PhysicsShape
|
||||
{
|
||||
protected:
|
||||
static PhysicsShapePolygon* create(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));
|
||||
bool init(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));
|
||||
|
||||
protected:
|
||||
PhysicsShapePolygon();
|
||||
virtual ~PhysicsShapePolygon();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** A segment shape */
|
||||
class PhysicsShapeEdgeSegment : public PhysicsShape
|
||||
{
|
||||
protected:
|
||||
static PhysicsShapeEdgeSegment* create(PhysicsBody* body, Point a, Point b, float border = 1);
|
||||
bool init(PhysicsBody* body, Point a, Point b, float border = 1);
|
||||
|
||||
protected:
|
||||
PhysicsShapeEdgeSegment();
|
||||
virtual ~PhysicsShapeEdgeSegment();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** An edge box shape */
|
||||
class PhysicsShapeEdgeBox : public PhysicsShape
|
||||
{
|
||||
public:
|
||||
static PhysicsShapeEdgeBox* create(PhysicsBody* body, Size size, float border = 0, Point offset = Point(0, 0));
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* body, Size size, float border = 1, Point offset = Point(0, 0));
|
||||
|
||||
protected:
|
||||
PhysicsShapeEdgeBox();
|
||||
virtual ~PhysicsShapeEdgeBox();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** An edge polygon shape */
|
||||
class PhysicsShapeEdgePolygon : public PhysicsShape
|
||||
{
|
||||
public:
|
||||
static PhysicsShapeEdgePolygon* create(PhysicsBody* body, Point* points, int count, float border = 1);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* body, Point* points, int count, float border = 1);
|
||||
|
||||
protected:
|
||||
PhysicsShapeEdgePolygon();
|
||||
virtual ~PhysicsShapeEdgePolygon();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
/** a chain shape */
|
||||
class PhysicsShapeEdgeChain : public PhysicsShape
|
||||
{
|
||||
public:
|
||||
static PhysicsShapeEdgeChain* create(PhysicsBody* body, Point* points, int count, float border = 1);
|
||||
|
||||
protected:
|
||||
bool init(PhysicsBody* body, Point* points, int count, float border = 1);
|
||||
|
||||
protected:
|
||||
PhysicsShapeEdgeChain();
|
||||
virtual ~PhysicsShapeEdgeChain();
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_FIXTURE_H__
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,330 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsWorld.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include "chipmunk.h"
|
||||
#elif (CC_PHYSICS_ENGINE == CCPHYSICS_BOX2D)
|
||||
#include "Box2D.h"
|
||||
#endif
|
||||
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "CCPhysicsShape.h"
|
||||
#include "CCPhysicsContact.h"
|
||||
|
||||
#include "chipmunk/CCPhysicsWorldInfo.h"
|
||||
#include "Box2D/CCPhysicsWorldInfo.h"
|
||||
#include "chipmunk/CCPhysicsBodyInfo.h"
|
||||
#include "Box2D/CCPhysicsBodyInfo.h"
|
||||
#include "chipmunk/CCPhysicsShapeInfo.h"
|
||||
#include "Box2D/CCPhysicsShapeInfo.h"
|
||||
#include "chipmunk/CCPhysicsContactInfo.h"
|
||||
#include "Box2D/CCPhysicsContactInfo.h"
|
||||
#include "chipmunk/CCPhysicsHelper.h"
|
||||
|
||||
#include "draw_nodes/CCDrawNode.h"
|
||||
#include "cocoa/CCArray.h"
|
||||
#include "layers_scenes_transitions_nodes/CCScene.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
int PhysicsWorld::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data)
|
||||
{
|
||||
PhysicsWorld* world = static_cast<PhysicsWorld*>(data);
|
||||
|
||||
CP_ARBITER_GET_SHAPES(arb, a, b);
|
||||
|
||||
auto ita = PhysicsShapeInfo::map.find(a);
|
||||
auto itb = PhysicsShapeInfo::map.find(b);
|
||||
CC_ASSERT(ita != PhysicsShapeInfo::map.end() && itb != PhysicsShapeInfo::map.end());
|
||||
|
||||
PhysicsContact* contact = PhysicsContact::create(ita->second->shape, itb->second->shape);
|
||||
arb->data = contact;
|
||||
|
||||
return world->collisionBeginCallback(*static_cast<PhysicsContact*>(arb->data));
|
||||
}
|
||||
|
||||
int PhysicsWorld::collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
PhysicsWorld* world = static_cast<PhysicsWorld*>(data);
|
||||
return world->collisionPreSolveCallback(*static_cast<PhysicsContact*>(arb->data),
|
||||
PhysicsContactPreSolve());
|
||||
}
|
||||
|
||||
void PhysicsWorld::collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
PhysicsWorld* world = static_cast<PhysicsWorld*>(data);
|
||||
world->collisionPostSolveCallback(*static_cast<PhysicsContact*>(arb->data),
|
||||
PhysicsContactPostSolve());
|
||||
}
|
||||
|
||||
void PhysicsWorld::collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data)
|
||||
{
|
||||
PhysicsWorld* world = static_cast<PhysicsWorld*>(data);
|
||||
PhysicsContact* contact = static_cast<PhysicsContact*>(arb->data);
|
||||
|
||||
world->collisionSeparateCallback(*contact);
|
||||
|
||||
delete contact;
|
||||
}
|
||||
|
||||
bool PhysicsWorld::init()
|
||||
{
|
||||
_info = new PhysicsWorldInfo();
|
||||
|
||||
cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity));
|
||||
|
||||
cpSpaceSetDefaultCollisionHandler(_info->space,
|
||||
PhysicsWorld::collisionBeginCallbackFunc,
|
||||
PhysicsWorld::collisionPreSolveCallbackFunc,
|
||||
PhysicsWorld::collisionPostSolveCallbackFunc,
|
||||
PhysicsWorld::collisionSeparateCallbackFunc,
|
||||
this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhysicsWorld::addShape(PhysicsShape* shape)
|
||||
{
|
||||
for (auto it = shape->_info->shapes.begin(); it != shape->_info->shapes.end(); it++)
|
||||
{
|
||||
if (cpBodyIsStatic(shape->getBody()->_info->body))
|
||||
{
|
||||
cpSpaceAddStaticShape(_info->space, *it);
|
||||
}else
|
||||
{
|
||||
cpSpaceAddShape(_info->space, *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::addChild(PhysicsBody* body)
|
||||
{
|
||||
auto shapes = body->getShapes();
|
||||
|
||||
// add body to space
|
||||
if (body->isDynamic())
|
||||
{
|
||||
cpSpaceAddBody(_info->space, body->_info->body);
|
||||
}
|
||||
|
||||
// add shapes to space
|
||||
for (auto it = shapes.begin(); it != shapes.end(); it++)
|
||||
{
|
||||
addShape(*it);
|
||||
}
|
||||
|
||||
if (_bodys == nullptr)
|
||||
{
|
||||
_bodys = Array::create(body, NULL);
|
||||
_bodys->retain();
|
||||
}else
|
||||
{
|
||||
_bodys->addObject(body);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::update(float delta)
|
||||
{
|
||||
cpSpaceStep(_info->space, delta);
|
||||
|
||||
if (_drawNode)
|
||||
{
|
||||
_drawNode->removeFromParent();
|
||||
_drawNode = nullptr;
|
||||
}
|
||||
|
||||
if (_debugDraw)
|
||||
{
|
||||
debugDraw();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::debugDraw()
|
||||
{
|
||||
if (_debugDraw && _bodys != nullptr)
|
||||
{
|
||||
_drawNode= DrawNode::create();
|
||||
|
||||
Object* child = nullptr;
|
||||
CCARRAY_FOREACH(_bodys, child)
|
||||
{
|
||||
PhysicsBody* body = dynamic_cast<PhysicsBody*>(child);
|
||||
|
||||
std::vector<PhysicsShape*> shapes = body->getShapes();
|
||||
|
||||
for (auto it = shapes.begin(); it != shapes.end(); ++it)
|
||||
{
|
||||
drawWithShape(_drawNode, *it);
|
||||
}
|
||||
}
|
||||
|
||||
if (_scene)
|
||||
{
|
||||
_scene->addChild(_drawNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::setScene(Scene *scene)
|
||||
{
|
||||
_scene = scene;
|
||||
scene->retain();
|
||||
}
|
||||
|
||||
void PhysicsWorld::drawWithShape(DrawNode* node, PhysicsShape* shape)
|
||||
{
|
||||
for (auto it = shape->_info->shapes.begin(); it != shape->_info->shapes.end(); ++it)
|
||||
{
|
||||
cpShape *shape = *it;
|
||||
|
||||
switch ((*it)->klass_private->type)
|
||||
{
|
||||
case CP_CIRCLE_SHAPE:
|
||||
{
|
||||
float radius = PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(shape));
|
||||
Point centre = PhysicsHelper::cpv2point(cpBodyGetPos(cpShapeGetBody(shape)))
|
||||
+ PhysicsHelper::cpv2point(cpCircleShapeGetOffset(shape));
|
||||
|
||||
Point seg[4] = {};
|
||||
seg[0] = Point(centre.x - radius, centre.y - radius);
|
||||
seg[1] = Point(centre.x - radius, centre.y + radius);
|
||||
seg[2] = Point(centre.x + radius, centre.y + radius);
|
||||
seg[3] = Point(centre.x + radius, centre.y - radius);
|
||||
node->drawPolygon(seg, 4, Color4F(), 1, Color4F(1, 0, 0, 1));
|
||||
break;
|
||||
}
|
||||
case CP_SEGMENT_SHAPE:
|
||||
{
|
||||
cpSegmentShape *seg = (cpSegmentShape *)shape;
|
||||
node->drawSegment(PhysicsHelper::cpv2point(seg->ta),
|
||||
PhysicsHelper::cpv2point(seg->tb),
|
||||
PhysicsHelper::cpfloat2float(seg->r==0 ? 1 : seg->r), Color4F(1, 0, 0, 1));
|
||||
break;
|
||||
}
|
||||
case CP_POLY_SHAPE:
|
||||
{
|
||||
cpPolyShape* poly = (cpPolyShape*)shape;
|
||||
int num = poly->numVerts;
|
||||
Point* seg = new Point[num];
|
||||
|
||||
PhysicsHelper::cpvs2points(poly->tVerts, seg, num);
|
||||
|
||||
node->drawPolygon(seg, num, Color4F(1, 0, 0, 0.3), 1, Color4F(1, 0, 0, 1));
|
||||
|
||||
delete[] seg;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PhysicsWorld::collisionBeginCallback(const PhysicsContact& contact)
|
||||
{
|
||||
if (_listener && _listener->onContactBegin)
|
||||
{
|
||||
return _listener->onContactBegin(contact);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int PhysicsWorld::collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve)
|
||||
{
|
||||
if (_listener && _listener->onContactPreSolve)
|
||||
{
|
||||
return _listener->onContactPreSolve(contact, solve);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PhysicsWorld::collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve)
|
||||
{
|
||||
if (_listener && _listener->onContactPreSolve)
|
||||
{
|
||||
_listener->onContactPostSolve(contact, solve);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::collisionSeparateCallback(const PhysicsContact& contact)
|
||||
{
|
||||
if (_listener && _listener->onContactEnd)
|
||||
{
|
||||
_listener->onContactEnd(contact);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::setGravity(Point gravity)
|
||||
{
|
||||
_gravity = gravity;
|
||||
cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity));
|
||||
}
|
||||
|
||||
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
|
||||
|
||||
#endif
|
||||
|
||||
PhysicsWorld* PhysicsWorld::create()
|
||||
{
|
||||
PhysicsWorld * world = new PhysicsWorld();
|
||||
if(world && world->init())
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(world);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicsWorld::PhysicsWorld()
|
||||
: _gravity(Point(0.0f, -98.0f))
|
||||
, _speed(1.0f)
|
||||
, _info(nullptr)
|
||||
, _listener(nullptr)
|
||||
, _bodys(nullptr)
|
||||
, _scene(nullptr)
|
||||
, _debugDraw(false)
|
||||
, _drawNode(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PhysicsWorld::~PhysicsWorld()
|
||||
{
|
||||
CC_SAFE_DELETE(_info);
|
||||
CC_SAFE_RELEASE(_bodys);
|
||||
CC_SAFE_RELEASE(_scene);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,141 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsSetting.h"
|
||||
#ifdef CC_USE_PHYSICS
|
||||
|
||||
#ifndef __CCPHYSICS_WORLD_H__
|
||||
#define __CCPHYSICS_WORLD_H__
|
||||
|
||||
#include "cocoa/CCObject.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
typedef struct cpArbiter cpArbiter;
|
||||
typedef struct cpSpace cpSpace;
|
||||
#endif
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsBody;
|
||||
class PhysicsJoint;
|
||||
class PhysicsWorldInfo;
|
||||
class PhysicsShape;
|
||||
class PhysicsContact;
|
||||
class PhysicsContactPreSolve;
|
||||
class PhysicsContactPostSolve;
|
||||
class PhysicsContactListener;
|
||||
class Array;
|
||||
|
||||
class Sprite;
|
||||
class Scene;
|
||||
class DrawNode;
|
||||
|
||||
/**
|
||||
* @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object.
|
||||
*/
|
||||
class PhysicsWorld
|
||||
{
|
||||
public:
|
||||
/** Adds a joint to the physics world.*/
|
||||
void addJoint(PhysicsJoint* joint);
|
||||
/** Removes a joint from the physics world.*/
|
||||
void removeJoint(PhysicsJoint* joint);
|
||||
/** Remove all joints from the physics world.*/
|
||||
void removeAllJoints();
|
||||
|
||||
Array* getBodysAlongRay(Point start, Point end) const;
|
||||
Array* getBodysAtPoint(Point point) const;
|
||||
Array* getBodysInRect(Rect rect) const;
|
||||
Array* getAllBody() const;
|
||||
|
||||
/** Register a listener to receive contact callbacks*/
|
||||
inline void registerContactListener(PhysicsContactListener* delegate) { _listener = delegate; }
|
||||
/** Unregister a listener. */
|
||||
inline void unregisterContactListener() { _listener = nullptr; }
|
||||
|
||||
/** get the gravity value */
|
||||
inline Point getGravity() { return _gravity; }
|
||||
/** set the gravity value */
|
||||
void setGravity(Point gravity);
|
||||
|
||||
/** test the debug draw is enabled */
|
||||
inline bool isDebugDraw() { return _debugDraw; }
|
||||
/** set the debug draw */
|
||||
inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }
|
||||
|
||||
protected:
|
||||
static PhysicsWorld* create();
|
||||
bool init();
|
||||
|
||||
void setScene(Scene* scene);
|
||||
|
||||
virtual void addChild(PhysicsBody* body);
|
||||
virtual void addShape(PhysicsShape* shape);
|
||||
virtual void update(float delta);
|
||||
|
||||
virtual void debugDraw();
|
||||
virtual void drawWithShape(DrawNode* node, PhysicsShape* shape);
|
||||
|
||||
|
||||
virtual int collisionBeginCallback(const PhysicsContact& contact);
|
||||
virtual int collisionPreSolveCallback(const PhysicsContact& contact, const PhysicsContactPreSolve& solve);
|
||||
virtual void collisionPostSolveCallback(const PhysicsContact& contact, const PhysicsContactPostSolve& solve);
|
||||
virtual void collisionSeparateCallback(const PhysicsContact& contact);
|
||||
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
static int collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, void *data);
|
||||
static int collisionPreSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data);
|
||||
static void collisionPostSolveCallbackFunc(cpArbiter *arb, cpSpace *space, void *data);
|
||||
static void collisionSeparateCallbackFunc(cpArbiter *arb, cpSpace *space, void *data);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
Point _gravity;
|
||||
float _speed;
|
||||
PhysicsWorldInfo* _info;
|
||||
PhysicsContactListener* _listener;
|
||||
|
||||
|
||||
Array* _bodys;
|
||||
Scene* _scene;
|
||||
|
||||
bool _debugDraw;
|
||||
DrawNode* _drawNode;
|
||||
|
||||
protected:
|
||||
PhysicsWorld();
|
||||
virtual ~PhysicsWorld();
|
||||
|
||||
friend class Sprite;
|
||||
friend class Scene;
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // __CCPHYSICS_WORLD_H__
|
||||
|
||||
#endif // CC_USE_PHYSICS
|
|
@ -0,0 +1,45 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsBodyInfo.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsBodyInfo::PhysicsBodyInfo()
|
||||
: body(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsBodyInfo::~PhysicsBodyInfo()
|
||||
{
|
||||
if (body) cpBodyFree(body);
|
||||
}
|
||||
|
||||
Clonable* PhysicsBodyInfo::clone() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,53 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_BODY_INFO_H__
|
||||
#define __CCPHYSICS_BODY_INFO_H__
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "cocoa/CCObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsBodyInfo : public Clonable
|
||||
{
|
||||
public:
|
||||
cpBody* body;
|
||||
|
||||
private:
|
||||
PhysicsBodyInfo();
|
||||
~PhysicsBodyInfo();
|
||||
|
||||
Clonable* clone() const override;
|
||||
|
||||
friend class PhysicsBody;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_BODY_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsContactInfo.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact)
|
||||
: contact(contact)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsContactInfo::~PhysicsContactInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,50 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_CONTACT_INFO_H__
|
||||
#define __CCPHYSICS_CONTACT_INFO_H__
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsContact;
|
||||
class PhysicsContactInfo
|
||||
{
|
||||
public:
|
||||
PhysicsContact* contact;
|
||||
|
||||
private:
|
||||
PhysicsContactInfo(PhysicsContact* contact);
|
||||
~PhysicsContactInfo();
|
||||
|
||||
friend class PhysicsContact;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_WORLD_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,69 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_HELPER_H__
|
||||
#define __CCPHYSICS_HELPER_H__
|
||||
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "cocoa/CCGeometry.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsHelper
|
||||
{
|
||||
public:
|
||||
static Point cpv2point(const cpVect& vec) { return Point(vec.x, vec.y); }
|
||||
static cpVect point2cpv(const Point& point) { return cpv(point.x, point.y); }
|
||||
static Size cpv2size(const cpVect& vec) { return Size(vec.x, vec.y); }
|
||||
static cpVect size2cpv(const Size& size) { return cpv(size.width, size.height); }
|
||||
static float cpfloat2float(cpFloat f) { return f; }
|
||||
static cpFloat float2cpfloat(float f) { return f; }
|
||||
|
||||
static void cpvs2points(const cpVect* cpvs, Point* points, int count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
points[i] = cpv2point(cpvs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static cpVect* points2cpvs(const Point* points, cpVect* cpvs, int count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
cpvs[i] = point2cpv(points[i]);
|
||||
}
|
||||
|
||||
return cpvs;
|
||||
}
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_HELPER_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,43 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsJointInfo.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsJointInfo::PhysicsJointInfo()
|
||||
: joint(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsJointInfo::~PhysicsJointInfo()
|
||||
{
|
||||
if (joint)
|
||||
{
|
||||
cpConstraintFree(joint);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,49 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_JOINT_INFO_H__
|
||||
#define __CCPHYSICS_JOINT_INFO_H__
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsJointInfo
|
||||
{
|
||||
public:
|
||||
cpConstraint* joint;
|
||||
|
||||
private:
|
||||
PhysicsJointInfo();
|
||||
~PhysicsJointInfo();
|
||||
|
||||
friend class PhysicsJoint;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_SHAPE_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,71 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsShapeInfo.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
#include <algorithm>
|
||||
NS_CC_BEGIN
|
||||
|
||||
std::map<cpShape*, PhysicsShapeInfo*> PhysicsShapeInfo::map;
|
||||
|
||||
PhysicsShapeInfo::PhysicsShapeInfo(PhysicsShape* shape)
|
||||
: shape(shape)
|
||||
{
|
||||
}
|
||||
|
||||
PhysicsShapeInfo::~PhysicsShapeInfo()
|
||||
{
|
||||
for (auto it = shapes.begin(); it != shapes.end(); it++)
|
||||
{
|
||||
cpShapeFree(*it);
|
||||
|
||||
auto mit = map.find(*it);
|
||||
if (mit != map.end()) map.erase(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsShapeInfo::add(cpShape* shape)
|
||||
{
|
||||
if (shape == nullptr) return;
|
||||
|
||||
shapes.push_back(shape);
|
||||
map.insert(std::pair<cpShape*, PhysicsShapeInfo*>(shape, this));
|
||||
}
|
||||
|
||||
void PhysicsShapeInfo::remove(cpShape* shape)
|
||||
{
|
||||
if (shape == nullptr) return;
|
||||
|
||||
auto it = std::find(shapes.begin(), shapes.end(), shape);
|
||||
if (it != shapes.end())
|
||||
{
|
||||
shapes.erase(it);
|
||||
|
||||
auto mit = map.find(shape);
|
||||
if (mit != map.end()) map.erase(mit);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,62 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_SHAPE_INFO_H__
|
||||
#define __CCPHYSICS_SHAPE_INFO_H__
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsShape;
|
||||
|
||||
class PhysicsShapeInfo
|
||||
{
|
||||
public:
|
||||
void add(cpShape* shape);
|
||||
void remove(cpShape* shape);
|
||||
void removeall();
|
||||
|
||||
public:
|
||||
std::vector<cpShape*> shapes;
|
||||
static std::map<cpShape*, PhysicsShapeInfo*> map;
|
||||
PhysicsShape* shape;
|
||||
|
||||
private:
|
||||
PhysicsShapeInfo(PhysicsShape* shape);
|
||||
~PhysicsShapeInfo();
|
||||
|
||||
friend class PhysicsShape;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_SHAPE_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,40 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCPhysicsWorldInfo.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsWorldInfo::PhysicsWorldInfo()
|
||||
{
|
||||
space = cpSpaceNew();
|
||||
}
|
||||
|
||||
PhysicsWorldInfo::~PhysicsWorldInfo()
|
||||
{
|
||||
cpSpaceFree(space);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -0,0 +1,49 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "../CCPhysicsSetting.h"
|
||||
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
|
||||
|
||||
#ifndef __CCPHYSICS_WORLD_INFO_H__
|
||||
#define __CCPHYSICS_WORLD_INFO_H__
|
||||
#include "chipmunk.h"
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
class PhysicsWorldInfo
|
||||
{
|
||||
public:
|
||||
cpSpace* space;
|
||||
|
||||
private:
|
||||
PhysicsWorldInfo();
|
||||
~PhysicsWorldInfo();
|
||||
|
||||
friend class PhysicsWorld;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
#endif // __CCPHYSICS_WORLD_INFO_H__
|
||||
|
||||
#endif // CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK
|
|
@ -1,17 +1,17 @@
|
|||
TARGET = libcocos2d.so
|
||||
|
||||
INCLUDES += \
|
||||
-I../platform/third_party/linux/libfreetype2 \
|
||||
-I../platform/third_party/common/etc \
|
||||
-I../platform/third_party/common/s3tc \
|
||||
-I../platform/third_party/common/atitc \
|
||||
-I../../extensions \
|
||||
-I../../extensions/CCBReader \
|
||||
-I../../extensions/GUI/CCControlExtension \
|
||||
-I../../extensions/GUI/CCControlExtension \
|
||||
-I../../external/chipmunk/include/chipmunk \
|
||||
-I../../extensions/network \
|
||||
-I../../extensions/Components \
|
||||
-I../platform/third_party/linux/libfreetype2 \
|
||||
-I../platform/third_party/common/etc \
|
||||
-I../platform/third_party/common/s3tc \
|
||||
-I../platform/third_party/common/atitc \
|
||||
-I../../extensions \
|
||||
-I../../extensions/CCBReader \
|
||||
-I../../extensions/GUI/CCControlExtension \
|
||||
-I../../extensions/GUI/CCControlExtension \
|
||||
-I../../external/chipmunk/include/chipmunk \
|
||||
-I../../extensions/network \
|
||||
-I../../extensions/Components
|
||||
|
||||
SOURCES = ../actions/CCAction.cpp \
|
||||
../actions/CCActionCamera.cpp \
|
||||
|
@ -81,6 +81,21 @@ SOURCES = ../actions/CCAction.cpp \
|
|||
../particle_nodes/CCParticleSystem.cpp \
|
||||
../particle_nodes/CCParticleSystemQuad.cpp \
|
||||
../particle_nodes/CCParticleBatchNode.cpp \
|
||||
../physics/Box2D/CCPhysicsContactInfo.cpp \
|
||||
../physics/Box2D/CCPhysicsJointInfo.cpp \
|
||||
../physics/Box2D/CCPhysicsShapeInfo.cpp \
|
||||
../physics/Box2D/CCPhysicsBodyInfo.cpp \
|
||||
../physics/Box2D/CCPhysicsWorldInfo.cpp \
|
||||
../physics/chipmunk/CCPhysicsContactInfo.cpp \
|
||||
../physics/chipmunk/CCPhysicsJointInfo.cpp \
|
||||
../physics/chipmunk/CCPhysicsShapeInfo.cpp \
|
||||
../physics/chipmunk/CCPhysicsBodyInfo.cpp \
|
||||
../physics/chipmunk/CCPhysicsWorldInfo.cpp \
|
||||
../physics/CCPhysicsBody.cpp \
|
||||
../physics/CCPhysicsContact.cpp \
|
||||
../physics/CCPhysicsShape.cpp \
|
||||
../physics/CCPhysicsJoint.cpp \
|
||||
../physics/CCPhysicsWorld.cpp \
|
||||
../platform/CCSAXParser.cpp \
|
||||
../platform/CCThread.cpp \
|
||||
../platform/CCEGLViewProtocol.cpp \
|
||||
|
@ -162,6 +177,8 @@ include cocos2dx.mk
|
|||
CXXFLAGS += -Wno-sequence-point
|
||||
CCFLAGS += -Wno-sequence-point
|
||||
|
||||
STATICLIBS += $(LIB_DIR)/libchipmunk.a
|
||||
|
||||
TARGET := $(LIB_DIR)/$(TARGET)
|
||||
|
||||
all: $(TARGET)
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\libfreetype2;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;$(ProjectDir)..\platform\third_party\common\etc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\libfreetype2;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;$(ProjectDir)..\platform\third_party\common\etc;$(ProjectDir)..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -211,6 +211,21 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
|||
<ClCompile Include="..\particle_nodes\CCParticleExamples.cpp" />
|
||||
<ClCompile Include="..\particle_nodes\CCParticleSystem.cpp" />
|
||||
<ClCompile Include="..\particle_nodes\CCParticleSystemQuad.cpp" />
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsBodyInfo.cpp" />
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsContactInfo.cpp" />
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsJointInfo.cpp" />
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsShapeInfo.cpp" />
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsWorldInfo.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsBody.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsContact.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsShape.cpp" />
|
||||
<ClCompile Include="..\physics\CCPhysicsWorld.cpp" />
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo.cpp" />
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo.cpp" />
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo.cpp" />
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo.cpp" />
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo.cpp" />
|
||||
<ClCompile Include="..\platform\CCEGLViewProtocol.cpp" />
|
||||
<ClCompile Include="..\platform\CCFileUtils.cpp" />
|
||||
<ClCompile Include="..\platform\CCSAXParser.cpp" />
|
||||
|
@ -365,6 +380,24 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
|
|||
<ClInclude Include="..\particle_nodes\CCParticleExamples.h" />
|
||||
<ClInclude Include="..\particle_nodes\CCParticleSystem.h" />
|
||||
<ClInclude Include="..\particle_nodes\CCParticleSystemQuad.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsBodyInfo.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsContactInfo.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsHelper.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsJointInfo.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsShapeInfo.h" />
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsWorldInfo.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsContact.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsJoint.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsSetting.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsShape.h" />
|
||||
<ClInclude Include="..\physics\CCPhysicsWorld.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo.h" />
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo.h" />
|
||||
<ClInclude Include="..\platform\CCApplicationProtocol.h" />
|
||||
<ClInclude Include="..\platform\CCCommon.h" />
|
||||
<ClInclude Include="..\platform\CCDevice.h" />
|
||||
|
|
|
@ -103,6 +103,15 @@
|
|||
<Filter Include="event_dispatcher">
|
||||
<UniqueIdentifier>{3ff2746c-a91b-4b86-93b7-43a9ec14825b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="physics">
|
||||
<UniqueIdentifier>{08593631-5bf5-46aa-9436-62595c4f7bf6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="physics\chipmunk">
|
||||
<UniqueIdentifier>{aeadfa95-9c89-4212-98ae-89ad57db596a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="physics\Box2D">
|
||||
<UniqueIdentifier>{b9880458-36e5-4f28-a34b-d01d9512a395}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\base_nodes\CCAtlasNode.cpp">
|
||||
|
@ -512,6 +521,51 @@
|
|||
<ClCompile Include="..\event_dispatcher\CCTouchEventListener.cpp">
|
||||
<Filter>event_dispatcher</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\CCPhysicsBody.cpp">
|
||||
<Filter>physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\CCPhysicsContact.cpp">
|
||||
<Filter>physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\CCPhysicsJoint.cpp">
|
||||
<Filter>physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\CCPhysicsShape.cpp">
|
||||
<Filter>physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\CCPhysicsWorld.cpp">
|
||||
<Filter>physics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo.cpp">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsBodyInfo.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsContactInfo.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsJointInfo.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsShapeInfo.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\physics\Box2D\CCPhysicsWorldInfo.cpp">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\base_nodes\CCAtlasNode.h">
|
||||
|
@ -1035,5 +1089,59 @@
|
|||
<ClInclude Include="..\event_dispatcher\CCTouchEventListener.h">
|
||||
<Filter>event_dispatcher</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsContact.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsJoint.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsSetting.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsShape.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\CCPhysicsWorld.h">
|
||||
<Filter>physics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo.h">
|
||||
<Filter>physics\chipmunk</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsBodyInfo.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsContactInfo.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsHelper.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsJointInfo.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsShapeInfo.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\physics\Box2D\CCPhysicsWorldInfo.h">
|
||||
<Filter>physics\Box2D</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -295,13 +295,19 @@ Sprite* Sprite::initWithCGImage(CGImageRef pImage, const char *pszKey)
|
|||
|
||||
Sprite::Sprite(void)
|
||||
: _shouldBeHidden(false)
|
||||
, _texture(NULL)
|
||||
, _texture(nullptr)
|
||||
#ifdef CC_USE_PHYSICS
|
||||
, _physicsBody(nullptr)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
Sprite::~Sprite(void)
|
||||
{
|
||||
CC_SAFE_RELEASE(_texture);
|
||||
#ifdef CC_USE_PHYSICS
|
||||
CC_SAFE_RELEASE(_physicsBody);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Sprite::setTextureRect(const Rect& rect)
|
||||
|
@ -784,12 +790,27 @@ void Sprite::setPosition(const Point& pos)
|
|||
{
|
||||
Node::setPosition(pos);
|
||||
SET_DIRTY_RECURSIVELY();
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
if (_physicsBody)
|
||||
{
|
||||
_physicsBody->setPosition(pos);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Sprite::setRotation(float fRotation)
|
||||
void Sprite::setRotation(float rotation)
|
||||
{
|
||||
Node::setRotation(fRotation);
|
||||
Node::setRotation(rotation);
|
||||
|
||||
SET_DIRTY_RECURSIVELY();
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
if (_physicsBody)
|
||||
{
|
||||
_physicsBody->setRotation(rotation);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Sprite::setRotationX(float fRotationX)
|
||||
|
@ -886,6 +907,33 @@ bool Sprite::isFlippedY(void) const
|
|||
return _flippedY;
|
||||
}
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
void Sprite::setPhysicsBody(PhysicsBody* body)
|
||||
{
|
||||
_physicsBody = body;
|
||||
_physicsBody->retain();
|
||||
_physicsBody->setPosition(getPosition());
|
||||
_physicsBody->setRotation(getRotation());
|
||||
}
|
||||
|
||||
PhysicsBody* Sprite::getPhysicsBody() const
|
||||
{
|
||||
return _physicsBody;
|
||||
}
|
||||
|
||||
void Sprite::visit()
|
||||
{
|
||||
if (_physicsBody)
|
||||
{
|
||||
Node::setPosition(_physicsBody->getPosition());
|
||||
Node::setRotation(_physicsBody->getRotation());
|
||||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
Node::visit();
|
||||
}
|
||||
#endif //CC_USE_PHYSICS
|
||||
|
||||
//
|
||||
// RGBA protocol
|
||||
//
|
||||
|
|
|
@ -36,6 +36,7 @@ THE SOFTWARE.
|
|||
#ifdef EMSCRIPTEN
|
||||
#include "base_nodes/CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
#include "physics/CCPhysicsBody.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -460,6 +461,20 @@ public:
|
|||
*/
|
||||
void setFlippedY(bool flippedY);
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
/**
|
||||
* set the PhysicsBody that let the sprite effect with physics
|
||||
*/
|
||||
virtual void setPhysicsBody(PhysicsBody* body);
|
||||
|
||||
/**
|
||||
* get the PhysicsBody the sprite have
|
||||
*/
|
||||
PhysicsBody* getPhysicsBody() const;
|
||||
|
||||
virtual void visit() override;
|
||||
#endif
|
||||
|
||||
/// @} End of Sprite properties getter/setters
|
||||
|
||||
/** @deprecated Use isFlippedY() instead */
|
||||
|
@ -575,6 +590,10 @@ protected:
|
|||
// image is flipped
|
||||
bool _flippedX; /// Whether the sprite is flipped horizaontally or not.
|
||||
bool _flippedY; /// Whether the sprite is flipped vertically or not.
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
PhysicsBody* _physicsBody; ///< the physicsBody the node have
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -56,4 +56,9 @@ bool UIRootWidget::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
const char* UIRootWidget::getDescription() const
|
||||
{
|
||||
return "RootWidget";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -46,6 +46,11 @@ public:
|
|||
* Allocates and initializes a widget.
|
||||
*/
|
||||
static UIRootWidget* create();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
//initializes state of widget.
|
||||
virtual bool init();
|
||||
|
|
|
@ -1158,6 +1158,11 @@ LayoutParameter* UIWidget::getLayoutParameter()
|
|||
return _layoutParameter;
|
||||
}
|
||||
|
||||
const char* UIWidget::getDescription() const
|
||||
{
|
||||
return "Widget";
|
||||
}
|
||||
|
||||
/*temp action*/
|
||||
void UIWidget::setActionTag(int tag)
|
||||
{
|
||||
|
|
|
@ -875,6 +875,11 @@ public:
|
|||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
|
||||
/*temp action*/
|
||||
void setActionTag(int tag);
|
||||
int getActionTag();
|
||||
|
|
|
@ -425,6 +425,11 @@ const Size& Layout::getContentSize() const
|
|||
return _renderer->getContentSize();
|
||||
}
|
||||
|
||||
const char* Layout::getDescription() const
|
||||
{
|
||||
return "Layout";
|
||||
}
|
||||
|
||||
RectClippingNode::RectClippingNode():
|
||||
m_pInnerStencil(NULL),
|
||||
_enabled(true),
|
||||
|
|
|
@ -179,6 +179,10 @@ public:
|
|||
*/
|
||||
virtual const Size& getContentSize() const;
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
//override "init" method of widget.
|
||||
virtual bool init();
|
||||
|
|
|
@ -45,7 +45,6 @@ _rootWidget(NULL)
|
|||
|
||||
UIInputManager::~UIInputManager()
|
||||
{
|
||||
CCLOG("~UIInputManager");
|
||||
_manageredWidget->removeAllObjects();
|
||||
CC_SAFE_RELEASE_NULL(_manageredWidget);
|
||||
_checkedDoubleClickWidget->removeAllObjects();
|
||||
|
@ -177,9 +176,7 @@ void UIInputManager::onTouchEnd(Touch* touch)
|
|||
{
|
||||
UIWidget* hitWidget = (UIWidget*)(selectedWidgetArray->arr[i]);
|
||||
hitWidget->onTouchEnded(_touchEndedPoint);
|
||||
CCLOG("widget touch end");
|
||||
}
|
||||
CCLOG("_selectedWidgets remove widgets");
|
||||
_selectedWidgets->removeAllObjects();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -72,47 +72,31 @@ enum DRAGPANEL_BOUNCE_DIR
|
|||
DRAGPANEL_BOUNCE_DIR_BOTTOM,
|
||||
};
|
||||
|
||||
/**
|
||||
* dragpanel berth event
|
||||
*/
|
||||
typedef void (Object::*SEL_DragPanelBerthToLeftBottomEvent)(Object*);
|
||||
#define coco_DragPane_BerthToLeftBottom_selector(_SELECTOR) (SEL_DragPanelBerthToLeftBottomEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToLeftTopEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToLeftTop_selector(_SELECTOR) (SEL_DragPanelBerthToLeftTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToRightBottomEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToRightBottom_selector(_SELECTOR) (SEL_DragPanelBerthToRightBottomEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToRightTopEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToRightTop_selector(_SELECTOR) (SEL_DragPanelBerthToRightTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToLeftEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToLeft_selector(_SELECTOR) (SEL_DragPanelBerthToLeftEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToRightEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToRight_selector(_SELECTOR) (SEL_DragPanelBerthToRightEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToTopEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToTop_selector(_SELECTOR) (SEL_DragPanelBerthToTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBerthToBottomEvent)(Object*);
|
||||
#define coco_DragPanel_BerthToBottom_selector(_SELECTOR) (SEL_DragPanelBerthToBottomEvent)(&_SELECTOR)
|
||||
typedef enum
|
||||
{
|
||||
DRAGPANEL_EVENT_BERTH_LEFTBOTTOM,
|
||||
DRAGPANEL_EVENT_BERTH_LFETTOP,
|
||||
DRAGPANEL_EVENT_BERTH_RIGHTBOTTOM,
|
||||
DRAGPANEL_EVENT_BERTH_RIGHTTOP,
|
||||
DRAGPANEL_EVENT_BERTH_LEFT,
|
||||
DRAGPANEL_EVENT_BERTH_TOP,
|
||||
DRAGPANEL_EVENT_BERTH_RIGHT,
|
||||
DRAGPANEL_EVENT_BERTH_BOTTOM,
|
||||
DRAGPANEL_EVENT_BOUNCE_LEFTBOTTOM,
|
||||
DRAGPANEL_EVENT_BOUNCE_LEFTTOP,
|
||||
DRAGPANEL_EVENT_BOUNCE_RIGHTBOTTOM,
|
||||
DRAGPANEL_EVENT_BOUNCE_RIGHTTOP,
|
||||
DRAGPANEL_EVENT_BOUNCE_LEFT,
|
||||
DRAGPANEL_EVENT_BOUNCE_TOP,
|
||||
DRAGPANEL_EVENT_BOUNCE_RIGHT,
|
||||
DRAGPANEL_EVENT_BOUNCE_BOTTOM,
|
||||
}DragPanelEventType;
|
||||
|
||||
/**
|
||||
* dragpanel bounce event
|
||||
* dragpanel event
|
||||
*/
|
||||
typedef void (Object::*SEL_DragPanelBounceOverEvent)(Object*);
|
||||
#define coco_DragPanel_BounceOver_selector(_SELECTOR) (SEL_DragPanelBounceOverEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToLeftBottomEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToLeftBottom_selector(_SELECTOR) (SEL_DragPanelBounceToLeftBottomEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToLeftTopEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToLeftTop_selector(_SELECTOR) (SEL_DragPanelBounceToLeftTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToRightBottomEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToRightBottom_selector(_SELECTOR) (SEL_DragPanelBounceToRightBottomEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToRightTopEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToRightTop_selector(_SELECTOR) (SEL_DragPanelBounceToRightTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToLeftEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToLeft_selector(_SELECTOR) (SEL_DragPanelBounceToLeftEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToTopEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToTop_selector(_SELECTOR) (SEL_DragPanelBounceToTopEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToRightEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToRight_selector(_SELECTOR) (SEL_DragPanelBounceToRightEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelBounceToBottomEvent)(Object*);
|
||||
#define coco_DragPanel_BounceToBottom_selector(_SELECTOR) (SEL_DragPanelBounceToBottomEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_DragPanelEvent)(Object*, DragPanelEventType);
|
||||
#define dragpaneleventselector(_SELECTOR)(SEL_DragPanelEvent)(&_SELECTOR)
|
||||
|
||||
class UIDragPanel : public Layout, public UIScrollInterface
|
||||
{
|
||||
|
@ -180,17 +164,10 @@ public:
|
|||
bool isBerth();
|
||||
|
||||
/**
|
||||
* berth event by direction
|
||||
* event
|
||||
*/
|
||||
void addBerthToLeftBottomEvent(Object* target, SEL_DragPanelBerthToLeftBottomEvent selector);
|
||||
void addBerthToLeftTopEvent(Object* target, SEL_DragPanelBerthToLeftTopEvent selector);
|
||||
void addBerthToRightBottomEvent(Object* target, SEL_DragPanelBerthToRightBottomEvent selector);
|
||||
void addBerthToRightTopEvent(Object* target, SEL_DragPanelBerthToRightTopEvent selector);
|
||||
void addBerthToLeftEvent(Object* target, SEL_DragPanelBerthToLeftEvent selector);
|
||||
void addBerthToTopEvent(Object* target, SEL_DragPanelBerthToTopEvent selector);
|
||||
void addBerthToRightEvent(Object* target, SEL_DragPanelBerthToRightEvent selector);
|
||||
void addBerthToBottomEvent(Object* target, SEL_DragPanelBerthToBottomEvent selector);
|
||||
|
||||
void addEventListener(Object* target, SEL_DragPanelEvent selector);
|
||||
|
||||
/**
|
||||
* get and set bounce enable
|
||||
*/
|
||||
|
@ -204,18 +181,6 @@ public:
|
|||
* set bounce ease rate
|
||||
*/
|
||||
void setBounceEaseRate(float rate);
|
||||
/**
|
||||
* bounce event by dircetion
|
||||
*/
|
||||
void addBounceOverEvent(Object* target, SEL_DragPanelBounceOverEvent selector);
|
||||
void addBounceToLeftBottomEvent(Object* target, SEL_DragPanelBounceToLeftBottomEvent selector);
|
||||
void addBounceToLeftTopEvent(Object* target, SEL_DragPanelBounceToLeftTopEvent selector);
|
||||
void addBounceToRightBottomEvent(Object* target, SEL_DragPanelBounceToRightBottomEvent selector);
|
||||
void addBounceToRightTopEvent(Object* target, SEL_DragPanelBounceToRightTopEvent selector);
|
||||
void addBounceToLeftEvent(Object* target, SEL_DragPanelBounceToLeftEvent selector);
|
||||
void addBounceToTopEvent(Object* target, SEL_DragPanelBounceToTopEvent selector);
|
||||
void addBounceToRightEvent(Object* target, SEL_DragPanelBounceToRightEvent selector);
|
||||
void addBounceToBottomEvent(Object* target, SEL_DragPanelBounceToBottomEvent selector);
|
||||
|
||||
/**
|
||||
* Gets inner container of dragpanel.
|
||||
|
@ -226,6 +191,11 @@ public:
|
|||
*/
|
||||
Layout* getInnerContainer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
|
||||
protected:
|
||||
virtual bool init();
|
||||
virtual void initRenderer();
|
||||
|
@ -286,7 +256,6 @@ protected:
|
|||
void bounceToCorner();
|
||||
void bounceOver();
|
||||
// bounce event
|
||||
void bounceOverEvent();
|
||||
void bounceToLeftBottomEvent();
|
||||
void bounceToRightBottomEvent();
|
||||
void bounceToLeftTopEvent();
|
||||
|
@ -318,94 +287,59 @@ protected:
|
|||
/************/
|
||||
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
|
||||
protected:
|
||||
Layout* m_pInnerContainer;
|
||||
Layout* _innerContainer;
|
||||
|
||||
/*
|
||||
DRAGPANEL_DIR m_eDirection;
|
||||
DRAGPANEL_MOVE_DIR m_eMoveDirection;
|
||||
*/
|
||||
|
||||
bool m_bTouchPressed;
|
||||
bool m_bTouchMoved;
|
||||
bool m_bTouchReleased;
|
||||
bool m_bTouchCanceld; // check touch out of drag panel boundary
|
||||
bool _touchPressed;
|
||||
bool _touchMoved;
|
||||
bool _touchReleased;
|
||||
bool _touchCanceld; // check touch out of drag panel boundary
|
||||
|
||||
Point m_touchStartNodeSpace;
|
||||
Point m_touchStartWorldSpace;
|
||||
Point m_touchEndWorldSpace;
|
||||
Point _touchStartNodeSpace;
|
||||
Point _touchStartWorldSpace;
|
||||
Point _touchEndWorldSpace;
|
||||
|
||||
float m_fSlidTime;
|
||||
float _slidTime;
|
||||
|
||||
// move type
|
||||
DRAGPANEL_MOVE_TYPE m_eMoveType;
|
||||
DRAGPANEL_MOVE_TYPE _moveType;
|
||||
|
||||
// auto move
|
||||
float m_fAutoMoveDuration;
|
||||
float m_fAutoMoveEaseRate;
|
||||
float _autoMoveDuration;
|
||||
float _autoMoveEaseRate;
|
||||
|
||||
// event
|
||||
Object* _eventLister;
|
||||
SEL_DragPanelEvent _eventSelector;
|
||||
|
||||
// berth
|
||||
DRAGPANEL_BERTH_DIR m_eBerthDirection;
|
||||
|
||||
// berth event
|
||||
Object* m_pBerthToLeftListener;
|
||||
SEL_DragPanelBerthToLeftEvent m_pfnBerthToLeftSelector;
|
||||
Object* m_pBerthToRightListener;
|
||||
SEL_DragPanelBerthToRightEvent m_pfnBerthToRightSelector;
|
||||
Object* m_pBerthToTopListener;
|
||||
SEL_DragPanelBerthToTopEvent m_pfnBerthToTopSelector;
|
||||
Object* m_pBerthToBottomListener;
|
||||
SEL_DragPanelBerthToBottomEvent m_pfnBerthToBottomSelector;
|
||||
Object* m_pBerthToLeftBottomListener;
|
||||
SEL_DragPanelBerthToLeftBottomEvent m_pfnBerthToLeftBottomSelector;
|
||||
Object* m_pBerthToLeftTopListener;
|
||||
SEL_DragPanelBerthToLeftTopEvent m_pfnBerthToLeftTopSelector;
|
||||
Object* m_pBerthToRightBottomListener;
|
||||
SEL_DragPanelBerthToRightBottomEvent m_pfnBerthToRightBottomSelector;
|
||||
Object* m_pBerthToRightTopListener;
|
||||
SEL_DragPanelBerthToRightTopEvent m_pfnBerthToRightTopSelector;
|
||||
|
||||
DRAGPANEL_BERTH_DIR _berthDirection;
|
||||
|
||||
// bounce
|
||||
bool m_bBounceEnable;
|
||||
DRAGPANEL_BOUNCE_DIR m_eBounceDirection;
|
||||
float m_fBounceDuration;
|
||||
float m_fBounceEaseRate;
|
||||
|
||||
// bounce event
|
||||
Object* m_pBounceOverListener;
|
||||
SEL_DragPanelBounceOverEvent m_pfnBounceOverSelector;
|
||||
Object* m_pBounceToLeftBottomListener;
|
||||
SEL_DragPanelBounceToLeftBottomEvent m_pfnBounceToLeftBottomSelector;
|
||||
Object* m_pBounceToLeftTopListener;
|
||||
SEL_DragPanelBounceToLeftTopEvent m_pfnBounceToLeftTopSelector;
|
||||
Object* m_pBounceToRightBottomListener;
|
||||
SEL_DragPanelBounceToRightBottomEvent m_pfnBounceToRightBottomSelector;
|
||||
Object* m_pBounceToRightTopListener;
|
||||
SEL_DragPanelBounceToRightTopEvent m_pfnBounceToRightTopSelector;
|
||||
Object* m_pBounceToLeftListener;
|
||||
SEL_DragPanelBounceToLeftEvent m_pfnBounceToLeftSelector;
|
||||
Object* m_pBounceToTopListener;
|
||||
SEL_DragPanelBounceToTopEvent m_pfnBounceToTopSelector;
|
||||
Object* m_pBounceToRightListener;
|
||||
SEL_DragPanelBounceToRightEvent m_pfnBounceToRightSelector;
|
||||
Object* m_pBounceToBottomListener;
|
||||
SEL_DragPanelBounceToBottomEvent m_pfnBounceToBottomSelector;
|
||||
bool _bounceEnable;
|
||||
DRAGPANEL_BOUNCE_DIR _bounceDirection;
|
||||
float _bounceDuration;
|
||||
float _bounceEaseRate;
|
||||
|
||||
|
||||
float _runningAction;
|
||||
int _actionType;
|
||||
|
||||
float m_bRunningAction;
|
||||
int m_nActionType;
|
||||
UIWidget* _actionWidget;
|
||||
|
||||
UIWidget* m_pActionWidget;
|
||||
float _duration;
|
||||
float _elapsed;
|
||||
bool _firstTick;
|
||||
|
||||
float m_fDuration;
|
||||
float m_elapsed;
|
||||
bool m_bFirstTick;
|
||||
Point _positionDelta;
|
||||
Point _startPosition;
|
||||
Point _previousPosition;
|
||||
|
||||
Point m_positionDelta;
|
||||
Point m_startPosition;
|
||||
Point m_previousPosition;
|
||||
|
||||
Point m_endPosition;
|
||||
Point _endPosition;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -42,10 +42,8 @@ UIListView::UIListView()
|
|||
, _bePressed(false)
|
||||
, _slidTime(0.0f)
|
||||
, _childFocusCancelOffset(5.0f)
|
||||
, _initChildListener(NULL)
|
||||
, _initChildSelector(NULL)
|
||||
, _updateChildListener(NULL)
|
||||
, _updateChildSelector(NULL)
|
||||
, _eventListener(NULL)
|
||||
, _eventSelector(NULL)
|
||||
, _childPool(NULL)
|
||||
, _updatePool(NULL)
|
||||
, _dataLength(0)
|
||||
|
@ -1431,30 +1429,30 @@ void UIListView::updateChild()
|
|||
|
||||
void UIListView::initChildEvent()
|
||||
{
|
||||
if (_initChildListener && _initChildSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_initChildListener->*_initChildSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, LISTVIEW_EVENT_INIT_CHILD);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListView::updateChildEvent()
|
||||
{
|
||||
if (_updateChildListener && _updateChildSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_updateChildListener->*_updateChildSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, LISTVIEW_EVENT_UPDATE_CHILD);
|
||||
}
|
||||
}
|
||||
|
||||
void UIListView::addInitChildEvent(Object *target, SEL_ListViewInitChildEvent seletor)
|
||||
void UIListView::addEventListenter(Object *target, SEL_ListViewEvent selector)
|
||||
{
|
||||
_initChildListener = target;
|
||||
_initChildSelector = seletor;
|
||||
_eventListener = target;
|
||||
_eventSelector = selector;
|
||||
}
|
||||
|
||||
void UIListView::addUpdateChildEvent(Object *target, SEL_ListViewUpdateChildEvent selector)
|
||||
const char* UIListView::getDescription() const
|
||||
{
|
||||
_updateChildListener = target;
|
||||
_updateChildSelector = selector;
|
||||
return "ListView";
|
||||
}
|
||||
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -53,13 +53,17 @@ typedef enum LISTVIEW_MOVE_DIR
|
|||
LISTVIEW_MOVE_DIR_RIGHT,
|
||||
}ListViewMoveDirection;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LISTVIEW_EVENT_INIT_CHILD,
|
||||
LISTVIEW_EVENT_UPDATE_CHILD,
|
||||
}ListViewEventType;
|
||||
|
||||
/**
|
||||
* list view event
|
||||
*/
|
||||
typedef void (cocos2d::Object::*SEL_ListViewInitChildEvent)(cocos2d::Object*);
|
||||
typedef void (cocos2d::Object::*SEL_ListViewUpdateChildEvent)(cocos2d::Object*);
|
||||
#define coco_ListView_InitChild_selector(_SELECTOR) (SEL_ListViewInitChildEvent)(&_SELECTOR)
|
||||
#define coco_ListView_UpdateChild_selector(_SELECTOR) (SEL_ListViewUpdateChildEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_ListViewEvent)(Object*, ListViewEventType);
|
||||
#define listvieweventselector(_SELECTOR)(SEL_ListViewEvent)(&_SELECTOR)
|
||||
|
||||
class UIListView : public Layout
|
||||
{
|
||||
|
@ -124,13 +128,9 @@ public:
|
|||
* add event call-back function
|
||||
*/
|
||||
/**
|
||||
* add init child event
|
||||
* add event
|
||||
*/
|
||||
void addInitChildEvent(cocos2d::Object* target, SEL_ListViewInitChildEvent seletor);
|
||||
/**
|
||||
* add udpate child event
|
||||
*/
|
||||
void addUpdateChildEvent(cocos2d::Object* target, SEL_ListViewUpdateChildEvent selector);
|
||||
void addEventListenter(cocos2d::Object* target, SEL_ListViewEvent selector);
|
||||
|
||||
/* gui mark */
|
||||
/**
|
||||
|
@ -139,6 +139,10 @@ public:
|
|||
/**/
|
||||
virtual void update(float dt);
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual bool init();
|
||||
|
||||
|
@ -209,10 +213,8 @@ protected:
|
|||
Point _moveChildPoint;
|
||||
float _childFocusCancelOffset;
|
||||
|
||||
cocos2d::Object* _initChildListener;
|
||||
SEL_ListViewInitChildEvent _initChildSelector;
|
||||
cocos2d::Object* _updateChildListener;
|
||||
SEL_ListViewUpdateChildEvent _updateChildSelector;
|
||||
Object* _eventListener;
|
||||
SEL_ListViewEvent _eventSelector;
|
||||
|
||||
Array* _childPool;
|
||||
Array* _updatePool;
|
||||
|
|
|
@ -43,8 +43,8 @@ _autoScrollDistance(0.0f),
|
|||
_autoScrollSpeed(0.0f),
|
||||
_autoScrollDir(0),
|
||||
_childFocusCancelOffset(5.0f),
|
||||
_pageTurningListener(NULL),
|
||||
_pageTurningSelector(NULL)
|
||||
_eventListener(NULL),
|
||||
_eventSelector(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -548,16 +548,16 @@ void UIPageView::interceptTouchEvent(int handleState, UIWidget *sender, const Po
|
|||
|
||||
void UIPageView::pageTurningEvent()
|
||||
{
|
||||
if (_pageTurningListener && _pageTurningSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_pageTurningListener->*_pageTurningSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, PAGEVIEW_EVENT_TURNING);
|
||||
}
|
||||
}
|
||||
|
||||
void UIPageView::addPageTurningEvent(Object *target, SEL_PageViewPageTurningEvent selector)
|
||||
void UIPageView::addEventListener(Object *target, SEL_PageViewEvent selector)
|
||||
{
|
||||
_pageTurningListener = target;
|
||||
_pageTurningSelector = selector;
|
||||
_eventListener = target;
|
||||
_eventSelector = selector;
|
||||
}
|
||||
|
||||
int UIPageView::getCurPageIndex() const
|
||||
|
@ -565,4 +565,9 @@ int UIPageView::getCurPageIndex() const
|
|||
return _curPageIdx;
|
||||
}
|
||||
|
||||
const char* UIPageView::getDescription() const
|
||||
{
|
||||
return "PageView";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -30,8 +30,13 @@
|
|||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
typedef void (Object::*SEL_PageViewPageTurningEvent)(Object*);
|
||||
#define coco_PageView_PageTurning_selector(_SELECTOR) (SEL_PageViewPageTurningEvent)(&_SELECTOR)
|
||||
typedef enum
|
||||
{
|
||||
PAGEVIEW_EVENT_TURNING,
|
||||
}PageViewEventType;
|
||||
|
||||
typedef void (Object::*SEL_PageViewEvent)(Object*, PageViewEventType);
|
||||
#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR)
|
||||
|
||||
typedef enum {
|
||||
PAGEVIEW_TOUCHLEFT,
|
||||
|
@ -110,8 +115,8 @@ public:
|
|||
*/
|
||||
int getCurPageIndex() const;
|
||||
|
||||
//Add call back function called when page turning.
|
||||
void addPageTurningEvent(Object *target, SEL_PageViewPageTurningEvent selector);
|
||||
// event
|
||||
void addEventListener(Object *target, SEL_PageViewEvent selector);
|
||||
|
||||
//override "removeChild" method of widget.
|
||||
virtual bool removeChild(UIWidget* widget);
|
||||
|
@ -134,6 +139,10 @@ public:
|
|||
//override "update" method of widget.
|
||||
virtual void update(float dt);
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual bool addChild(UIWidget* widget);
|
||||
virtual bool init();
|
||||
|
@ -170,8 +179,8 @@ protected:
|
|||
float _autoScrollSpeed;
|
||||
int _autoScrollDir;
|
||||
float _childFocusCancelOffset;
|
||||
Object* _pageTurningListener;
|
||||
SEL_PageViewPageTurningEvent _pageTurningSelector;
|
||||
Object* _eventListener;
|
||||
SEL_PageViewEvent _eventSelector;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
NS_CC_EXT_BEGIN
|
||||
|
||||
UIScrollView::UIScrollView():
|
||||
_innerContainer(NULL),
|
||||
_direction(SCROLLVIEW_DIR_VERTICAL),
|
||||
_moveDirection(SCROLLVIEW_MOVE_DIR_NONE),
|
||||
_touchStartLocation(0.0f),
|
||||
|
@ -48,15 +49,8 @@ _bePressed(false),
|
|||
_slidTime(0.0f),
|
||||
_moveChildPoint(Point::ZERO),
|
||||
_childFocusCancelOffset(5.0f),
|
||||
_scrollToTopListener(NULL),
|
||||
_scrollToTopSelector(NULL),
|
||||
_scrollToBottomListener(NULL),
|
||||
_scrollToBottomSelector(NULL),
|
||||
_scrollToLeftListener(NULL),
|
||||
_scrollToLeftSelector(NULL),
|
||||
_scrollToRightListener(NULL),
|
||||
_scrollToRightSelector(NULL),
|
||||
_innerContainer(NULL)
|
||||
_eventListener(NULL),
|
||||
_eventSelector(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -609,58 +603,40 @@ void UIScrollView::checkChildInfo(int handleState,UIWidget* sender,const Point &
|
|||
|
||||
void UIScrollView::scrollToTopEvent()
|
||||
{
|
||||
if (_scrollToTopListener && _scrollToTopSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_scrollToTopListener->*_scrollToTopSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP);
|
||||
}
|
||||
}
|
||||
|
||||
void UIScrollView::scrollToBottomEvent()
|
||||
{
|
||||
if (_scrollToBottomListener && _scrollToBottomSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_scrollToBottomListener->*_scrollToBottomSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM);
|
||||
}
|
||||
}
|
||||
|
||||
void UIScrollView::scrollToLeftEvent()
|
||||
{
|
||||
if (_scrollToLeftListener && _scrollToLeftSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_scrollToLeftListener->*_scrollToLeftSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
void UIScrollView::scrollToRightEvent()
|
||||
{
|
||||
if (_scrollToRightListener && _scrollToRightSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_scrollToRightListener->*_scrollToRightSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
void UIScrollView::addScrollToTopEvent(Object *target, SEL_ScrollToTopEvent selector)
|
||||
void UIScrollView::addEventListener(Object *target, SEL_ScrollViewEvent selector)
|
||||
{
|
||||
_scrollToTopListener = target;
|
||||
_scrollToTopSelector = selector;
|
||||
}
|
||||
|
||||
void UIScrollView::addScrollToBottomEvent(Object *target, SEL_ScrollToBottomEvent selector)
|
||||
{
|
||||
_scrollToBottomListener = target;
|
||||
_scrollToBottomSelector = selector;
|
||||
}
|
||||
|
||||
void UIScrollView::addScrollToLeftEvent(Object *target, SEL_ScrollToLeftEvent selector)
|
||||
{
|
||||
_scrollToLeftListener = target;
|
||||
_scrollToLeftSelector = selector;
|
||||
}
|
||||
|
||||
void UIScrollView::addScrollToRightEvent(Object *target, SEL_ScrollToRightEvent selector)
|
||||
{
|
||||
_scrollToRightListener = target;
|
||||
_scrollToRightSelector = selector;
|
||||
_eventListener = target;
|
||||
_eventSelector = selector;
|
||||
}
|
||||
|
||||
void UIScrollView::setDirection(SCROLLVIEW_DIR dir)
|
||||
|
@ -698,4 +674,9 @@ LayoutExecutant* UIScrollView::getLayoutExecutant() const
|
|||
return _innerContainer->getLayoutExecutant();
|
||||
}
|
||||
|
||||
const char* UIScrollView::getDescription() const
|
||||
{
|
||||
return "ScrollView";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -46,14 +46,16 @@ enum SCROLLVIEW_MOVE_DIR
|
|||
SCROLLVIEW_MOVE_DIR_RIGHT,
|
||||
};
|
||||
|
||||
typedef void (Object::*SEL_ScrollToTopEvent)(Object*);
|
||||
typedef void (Object::*SEL_ScrollToBottomEvent)(Object*);
|
||||
typedef void (Object::*SEL_ScrollToLeftEvent)(Object*);
|
||||
typedef void (Object::*SEL_ScrollToRightEvent)(Object*);
|
||||
#define coco_ScrollToTopSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToTopEvent)(&_SELECTOR)
|
||||
#define coco_ScrollToBottomSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToBottomEvent)(&_SELECTOR)
|
||||
#define coco_ScrollToLeftSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToLeftEvent)(&_SELECTOR)
|
||||
#define coco_ScrollToRightSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToRightEvent)(&_SELECTOR)
|
||||
typedef enum
|
||||
{
|
||||
SCROLLVIEW_EVENT_SCROLL_TO_TOP,
|
||||
SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM,
|
||||
SCROLLVIEW_EVENT_SCROLL_TO_LEFT,
|
||||
SCROLLVIEW_EVENT_SCROLL_TO_RIGHT,
|
||||
}ScrollviewEventType;
|
||||
|
||||
typedef void (Object::*SEL_ScrollViewEvent)(Object*, ScrollviewEventType);
|
||||
#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR)
|
||||
|
||||
|
||||
class UIScrollView : public Layout , public UIScrollInterface
|
||||
|
@ -130,24 +132,9 @@ public:
|
|||
const Size& getInnerContainerSize() const;
|
||||
|
||||
/**
|
||||
* Add call back function called when scrollview scrolled to top.
|
||||
* Add call back function called scrollview event triggered
|
||||
*/
|
||||
void addScrollToTopEvent(Object* target, SEL_ScrollToTopEvent selector);
|
||||
|
||||
/**
|
||||
* Add call back function called when scrollview scrolled to bottom.
|
||||
*/
|
||||
void addScrollToBottomEvent(Object* target, SEL_ScrollToBottomEvent selector);
|
||||
|
||||
/**
|
||||
* Add call back function called when scrollview scrolled to left.
|
||||
*/
|
||||
void addScrollToLeftEvent(Object* target, SEL_ScrollToLeftEvent selector);
|
||||
|
||||
/**
|
||||
* Add call back function called when scrollview scrolled to right.
|
||||
*/
|
||||
void addScrollToRightEvent(Object* target, SEL_ScrollToRightEvent selector);
|
||||
void addEventListener(Object* target, SEL_ScrollViewEvent selector);
|
||||
|
||||
//override "setLayoutExecutant" method of widget.
|
||||
virtual void setLayoutExecutant(LayoutExecutant* exe);
|
||||
|
@ -183,6 +170,11 @@ public:
|
|||
virtual void onTouchLongClicked(const Point &touchPoint);
|
||||
|
||||
virtual void update(float dt);
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual bool init();
|
||||
virtual void initRenderer();
|
||||
|
@ -212,6 +204,8 @@ protected:
|
|||
virtual void onSizeChanged();
|
||||
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
|
||||
protected:
|
||||
Layout* _innerContainer;
|
||||
|
||||
SCROLLVIEW_DIR _direction;
|
||||
SCROLLVIEW_MOVE_DIR _moveDirection;
|
||||
float _touchStartLocation;
|
||||
|
@ -237,16 +231,9 @@ protected:
|
|||
Point _moveChildPoint;
|
||||
float _childFocusCancelOffset;
|
||||
|
||||
Object* _scrollToTopListener;
|
||||
SEL_ScrollToTopEvent _scrollToTopSelector;
|
||||
Object* _scrollToBottomListener;
|
||||
SEL_ScrollToBottomEvent _scrollToBottomSelector;
|
||||
Object* _scrollToLeftListener;
|
||||
SEL_ScrollToLeftEvent _scrollToLeftSelector;
|
||||
Object* _scrollToRightListener;
|
||||
SEL_ScrollToRightEvent _scrollToRightSelector;
|
||||
Object* _eventListener;
|
||||
SEL_ScrollViewEvent _eventSelector;
|
||||
|
||||
Layout* _innerContainer;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -431,54 +431,6 @@ void UIButton::setAnchorPoint(const Point &pt)
|
|||
_titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y)));
|
||||
}
|
||||
|
||||
void UIButton::setNormalSpriteFrame(SpriteFrame *frame)
|
||||
{
|
||||
if (!frame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
dynamic_cast<Scale9Sprite*>(_buttonNormalRenderer)->setSpriteFrame(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_cast<Sprite*>(_buttonNormalRenderer)->setDisplayFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void UIButton::setPressedSpriteFrame(SpriteFrame *frame)
|
||||
{
|
||||
if (!frame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
dynamic_cast<Scale9Sprite*>(_buttonClickedRenderer)->setSpriteFrame(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_cast<Sprite*>(_buttonClickedRenderer)->setDisplayFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void UIButton::setDisabledSpriteFrame(SpriteFrame *frame)
|
||||
{
|
||||
if (!frame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
dynamic_cast<Scale9Sprite*>(_buttonDisableRenderer)->setSpriteFrame(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_cast<Sprite*>(_buttonDisableRenderer)->setDisplayFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void UIButton::onSizeChanged()
|
||||
{
|
||||
normalTextureScaleChangedWithSize();
|
||||
|
@ -657,4 +609,9 @@ void UIButton::setColor(const Color3B &color)
|
|||
setTitleColor(_titleColor);
|
||||
}
|
||||
|
||||
const char* UIButton::getDescription() const
|
||||
{
|
||||
return "Button";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -171,9 +171,10 @@ public:
|
|||
void setTitleFontName(const char* fontName);
|
||||
const char* getTitleFontName() const;
|
||||
|
||||
virtual void setNormalSpriteFrame(SpriteFrame* frame);
|
||||
virtual void setPressedSpriteFrame(SpriteFrame* frame);
|
||||
virtual void setDisabledSpriteFrame(SpriteFrame* frame);
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual bool init();
|
||||
virtual void initRenderer();
|
||||
|
|
|
@ -287,7 +287,7 @@ void UICheckBox::unSelectedEvent()
|
|||
}
|
||||
}
|
||||
|
||||
void UICheckBox::addSelectedStateEvent(Object *target, SEL_SelectedStateEvent selector)
|
||||
void UICheckBox::addEventListener(Object *target, SEL_SelectedStateEvent selector)
|
||||
{
|
||||
_selectedStateEventListener = target;
|
||||
_selectedStateEventSelector = selector;
|
||||
|
@ -456,4 +456,9 @@ void UICheckBox::frontCrossDisabledTextureScaleChangedWithSize()
|
|||
}
|
||||
}
|
||||
|
||||
const char* UICheckBox::getDescription() const
|
||||
{
|
||||
return "CheckBox";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -134,7 +134,7 @@ public:
|
|||
virtual void setAnchorPoint(const Point &pt);
|
||||
|
||||
//add a call back function would called when checkbox is selected or unselected.
|
||||
void addSelectedStateEvent(Object* target,SEL_SelectedStateEvent selector);
|
||||
void addEventListener(Object* target,SEL_SelectedStateEvent selector);
|
||||
|
||||
//override "setFlipX" method of widget.
|
||||
virtual void setFlipX(bool flipX);
|
||||
|
@ -157,6 +157,10 @@ public:
|
|||
//override "getVirtualRenderer" method of widget.
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual bool init();
|
||||
virtual void initRenderer();
|
||||
|
|
|
@ -368,4 +368,9 @@ void UIImageView::imageTextureScaleChangedWithSize()
|
|||
}
|
||||
}
|
||||
|
||||
const char* UIImageView::getDescription() const
|
||||
{
|
||||
return "ImageView";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -107,6 +107,11 @@ public:
|
|||
void checkDoubleClick(float dt);
|
||||
virtual const Size& getContentSize() const;
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual void initRenderer();
|
||||
virtual void onSizeChanged();
|
||||
|
|
|
@ -221,7 +221,11 @@ void UILabel::labelScaleChangedWithSize()
|
|||
_labelRenderer->setScaleX(scaleX);
|
||||
_labelRenderer->setScaleY(scaleY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char* UILabel::getDescription() const
|
||||
{
|
||||
return "Label";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -117,6 +117,11 @@ public:
|
|||
//override "getVirtualRenderer" method of widget.
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
|
||||
void setTextAreaSize(const Size &size);
|
||||
void setTextHorizontalAlignment(TextHAlignment alignment);
|
||||
void setTextVerticalAlignment(TextVAlignment alignment);
|
||||
|
|
|
@ -167,4 +167,9 @@ void UILabelAtlas::labelAtlasScaleChangedWithSize()
|
|||
}
|
||||
}
|
||||
|
||||
const char* UILabelAtlas::getDescription() const
|
||||
{
|
||||
return "LabelAtlase";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -87,6 +87,11 @@ public:
|
|||
|
||||
//override "getVirtualRenderer" method of widget.
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual void initRenderer();
|
||||
virtual void onSizeChanged();
|
||||
|
|
|
@ -126,4 +126,10 @@ void UILabelBMFont::labelBMFontScaleChangedWithSize()
|
|||
}
|
||||
}
|
||||
|
||||
const char* UILabelBMFont::getDescription() const
|
||||
{
|
||||
return "LabelBMFont";
|
||||
}
|
||||
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -58,6 +58,11 @@ public:
|
|||
virtual void setAnchorPoint(const Point &pt);
|
||||
virtual const Size& getContentSize() const;
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual void initRenderer();
|
||||
virtual void onSizeChanged();
|
||||
|
|
|
@ -331,4 +331,9 @@ void UILoadingBar::setScale9Scale()
|
|||
dynamic_cast<Scale9Sprite*>(_barRenderer)->setPreferredSize(Size(width, _barRendererTextureSize.height));
|
||||
}
|
||||
|
||||
const char* UILoadingBar::getDescription() const
|
||||
{
|
||||
return "LoadingBar";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -117,6 +117,10 @@ public:
|
|||
//override "getVirtualRenderer" method of widget.
|
||||
virtual Node* getVirtualRenderer();
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual void initRenderer();
|
||||
virtual void onSizeChanged();
|
||||
|
|
|
@ -410,7 +410,7 @@ float UISlider::getPercentWithBallPos(float px)
|
|||
return (((px-(-_barLength/2.0f))/_barLength)*100.0f);
|
||||
}
|
||||
|
||||
void UISlider::addPercentEvent(Object *target, SEL_SlidPercentChangedEvent selector)
|
||||
void UISlider::addEventListener(Object *target, SEL_SlidPercentChangedEvent selector)
|
||||
{
|
||||
_slidPercentListener = target;
|
||||
_slidPercentSelector = selector;
|
||||
|
@ -535,4 +535,10 @@ void UISlider::onPressStateChangedToDisabled()
|
|||
_slidBallPressedRenderer->setVisible(false);
|
||||
_slidBallDisabledRenderer->setVisible(true);
|
||||
}
|
||||
|
||||
const char* UISlider::getDescription() const
|
||||
{
|
||||
return "Slider";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -158,7 +158,7 @@ public:
|
|||
/**
|
||||
* Add call back function called when slider's percent has changed to slider.
|
||||
*/
|
||||
void addPercentEvent(Object* target,SEL_SlidPercentChangedEvent selector);
|
||||
void addEventListener(Object* target,SEL_SlidPercentChangedEvent selector);
|
||||
|
||||
//override "onTouchBegan" method of widget.
|
||||
virtual bool onTouchBegan(const Point &touchPoint);
|
||||
|
@ -180,6 +180,11 @@ public:
|
|||
|
||||
//override "ignoreContentAdaptWithSize" method of widget.
|
||||
virtual void ignoreContentAdaptWithSize(bool ignore);
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
protected:
|
||||
virtual void initRenderer();
|
||||
float getPercentWithBallPos(float location);
|
||||
|
|
|
@ -271,18 +271,12 @@ bool UICCTextField::getDeleteBackward()
|
|||
|
||||
|
||||
UITextField::UITextField():
|
||||
_textFieldRenderer(NULL),
|
||||
_touchWidth(0.0f),
|
||||
_touchHeight(0.0f),
|
||||
_useTouchArea(false),
|
||||
_attachWithIMEListener(NULL),
|
||||
_detachWithIMEListener(NULL),
|
||||
_insertTextListener(NULL),
|
||||
_deleteBackwardListener(NULL),
|
||||
_attachWithIMESelector(NULL),
|
||||
_detachWithIMESelector(NULL),
|
||||
_insertTextSelector(NULL),
|
||||
_deleteBackwardSelector(NULL),
|
||||
_textFieldRenderer(NULL)
|
||||
_eventListener(NULL),
|
||||
_eventSelector(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -475,58 +469,40 @@ void UITextField::setDeleteBackward(bool deleteBackward)
|
|||
|
||||
void UITextField::attachWithIMEEvent()
|
||||
{
|
||||
if (_attachWithIMEListener && _attachWithIMESelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_attachWithIMEListener->*_attachWithIMESelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_ATTACH_WITH_IME);
|
||||
}
|
||||
}
|
||||
|
||||
void UITextField::detachWithIMEEvent()
|
||||
{
|
||||
if (_detachWithIMEListener && _detachWithIMESelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_detachWithIMEListener->*_detachWithIMESelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_DETACH_WITH_IME);
|
||||
}
|
||||
}
|
||||
|
||||
void UITextField::insertTextEvent()
|
||||
{
|
||||
if (_insertTextListener && _insertTextSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_insertTextListener->*_insertTextSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_INDERT_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
void UITextField::deleteBackwardEvent()
|
||||
{
|
||||
if (_deleteBackwardListener && _deleteBackwardSelector)
|
||||
if (_eventListener && _eventSelector)
|
||||
{
|
||||
(_deleteBackwardListener->*_deleteBackwardSelector)(this);
|
||||
(_eventListener->*_eventSelector)(this, TEXTFIELD_EVENT_DELETE_BACKWARD);
|
||||
}
|
||||
}
|
||||
|
||||
void UITextField::addAttachWithIMEEvent(Object *target, SEL_TextFieldAttachWithIMEEvent selecor)
|
||||
void UITextField::addEventListener(Object *target, SEL_TextFieldEvent selecor)
|
||||
{
|
||||
_attachWithIMEListener = target;
|
||||
_attachWithIMESelector = selecor;
|
||||
}
|
||||
|
||||
void UITextField::addDetachWithIMEEvent(Object *target, SEL_TextFieldDetachWithIMEEvent selecor)
|
||||
{
|
||||
_detachWithIMEListener = target;
|
||||
_detachWithIMESelector = selecor;
|
||||
}
|
||||
|
||||
void UITextField::addInsertTextEvent(Object *target, SEL_TextFieldInsertTextEvent selecor)
|
||||
{
|
||||
_insertTextListener = target;
|
||||
_insertTextSelector = selecor;
|
||||
}
|
||||
|
||||
void UITextField::addDeleteBackwardEvent(Object *target, SEL_TextFieldDeleteBackwardEvent selecor)
|
||||
{
|
||||
_deleteBackwardListener = target;
|
||||
_deleteBackwardSelector = selecor;
|
||||
_eventListener = target;
|
||||
_eventSelector = selecor;
|
||||
}
|
||||
|
||||
void UITextField::setAnchorPoint(const Point &pt)
|
||||
|
@ -584,4 +560,9 @@ Node* UITextField::getVirtualRenderer()
|
|||
return _textFieldRenderer;
|
||||
}
|
||||
|
||||
const char* UITextField::getDescription() const
|
||||
{
|
||||
return "TextField";
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -70,6 +70,8 @@ public:
|
|||
bool getInsertText();
|
||||
void setDeleteBackward(bool deleteBackward);
|
||||
bool getDeleteBackward();
|
||||
|
||||
|
||||
protected:
|
||||
bool m_bMaxLengthEnabled;
|
||||
int m_nMaxLength;
|
||||
|
@ -82,14 +84,16 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
typedef void (Object::*SEL_TextFieldAttachWithIMEEvent)(Object*);
|
||||
#define coco_TextField_AttachWithIME_selector(_SELECTOR) (SEL_TextFieldAttachWithIMEEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_TextFieldDetachWithIMEEvent)(Object*);
|
||||
#define coco_TextField_DetachWithIME_selector(_SELECTOR) (SEL_TextFieldDetachWithIMEEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_TextFieldInsertTextEvent)(Object*);
|
||||
#define coco_TextField_InsertText_selector(_SELECTOR) (SEL_TextFieldInsertTextEvent)(&_SELECTOR)
|
||||
typedef void (Object::*SEL_TextFieldDeleteBackwardEvent)(Object*);
|
||||
#define coco_TextField_DeleteBackward_selector(_SELECTOR) (SEL_TextFieldDeleteBackwardEvent)(&_SELECTOR)
|
||||
typedef enum
|
||||
{
|
||||
TEXTFIELD_EVENT_ATTACH_WITH_IME,
|
||||
TEXTFIELD_EVENT_DETACH_WITH_IME,
|
||||
TEXTFIELD_EVENT_INDERT_TEXT,
|
||||
TEXTFIELD_EVENT_DELETE_BACKWARD,
|
||||
}TextFiledEventType;
|
||||
|
||||
typedef void (Object::*SEL_TextFieldEvent)(Object*, TextFiledEventType);
|
||||
#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR)
|
||||
|
||||
//class UITextField : public UIWidget
|
||||
class UITextField : public UIWidget
|
||||
|
@ -124,14 +128,14 @@ public:
|
|||
void setInsertText(bool insertText);
|
||||
bool getDeleteBackward();
|
||||
void setDeleteBackward(bool deleteBackward);
|
||||
void addAttachWithIMEEvent(Object* target, SEL_TextFieldAttachWithIMEEvent selecor);
|
||||
void addDetachWithIMEEvent(Object* target, SEL_TextFieldDetachWithIMEEvent selecor);
|
||||
void addInsertTextEvent(Object* target, SEL_TextFieldInsertTextEvent selecor);
|
||||
void addDeleteBackwardEvent(Object* target, SEL_TextFieldDeleteBackwardEvent selecor);
|
||||
void addEventListener(Object* target, SEL_TextFieldEvent selecor);
|
||||
virtual void setAnchorPoint(const Point &pt);
|
||||
virtual void setColor(const Color3B &color);
|
||||
virtual void setOpacity(int opacity);
|
||||
|
||||
/**
|
||||
* Returns the "class name" of widget.
|
||||
*/
|
||||
virtual const char* getDescription() const;
|
||||
/*compatibel*/
|
||||
/**
|
||||
* These methods will be removed
|
||||
|
@ -150,21 +154,15 @@ protected:
|
|||
virtual void onSizeChanged();
|
||||
void textfieldRendererScaleChangedWithSize();
|
||||
protected:
|
||||
UICCTextField* _textFieldRenderer;
|
||||
|
||||
float _touchWidth;
|
||||
float _touchHeight;
|
||||
bool _useTouchArea;
|
||||
|
||||
Object* _attachWithIMEListener;
|
||||
Object* _detachWithIMEListener;
|
||||
Object* _insertTextListener;
|
||||
Object* _deleteBackwardListener;
|
||||
Object* _eventListener;
|
||||
SEL_TextFieldEvent _eventSelector;
|
||||
|
||||
SEL_TextFieldAttachWithIMEEvent _attachWithIMESelector;
|
||||
SEL_TextFieldDetachWithIMEEvent _detachWithIMESelector;
|
||||
SEL_TextFieldInsertTextEvent _insertTextSelector;
|
||||
SEL_TextFieldDeleteBackwardEvent _deleteBackwardSelector;
|
||||
|
||||
UICCTextField* _textFieldRenderer;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -13,7 +13,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
|
|||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += spidermonkey_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += scriptingcore-spidermonkey
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static
|
||||
|
@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY)
|
|||
|
||||
$(call import-module,cocos2dx)
|
||||
$(call import-module,CocosDenshion/android)
|
||||
$(call import-module,external/chipmunk)
|
||||
$(call import-module,scripting/javascript/spidermonkey-android)
|
||||
$(call import-module,scripting/javascript/bindings)
|
||||
$(call import-module,cocos2dx/platform/android)
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\cocos2dx;$(ProjectDir)..\..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;$(ProjectDir)..\..\..\..\external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -84,7 +84,7 @@
|
|||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<AdditionalDependencies>libcocos2d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libcocos2d.lib;libchipmunk.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
|
|
|
@ -118,6 +118,7 @@ Classes/PerformanceTest/PerformanceSpriteTest.cpp \
|
|||
Classes/PerformanceTest/PerformanceTest.cpp \
|
||||
Classes/PerformanceTest/PerformanceTextureTest.cpp \
|
||||
Classes/PerformanceTest/PerformanceTouchesTest.cpp \
|
||||
Classes/PhysicsTest/PhysicsTest.cpp \
|
||||
Classes/RenderTextureTest/RenderTextureTest.cpp \
|
||||
Classes/RotateWorldTest/RotateWorldTest.cpp \
|
||||
Classes/SceneTest/SceneTest.cpp \
|
||||
|
|
|
@ -54,7 +54,7 @@ bool UICheckBoxTest::init()
|
|||
"cocosgui/check_box_active_disable.png");
|
||||
checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||
|
||||
checkBox->addSelectedStateEvent(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));
|
||||
checkBox->addEventListener(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));
|
||||
|
||||
// checkBox->addSelectEvent(this, coco_selectselector(UICheckBoxTest::selectedEvent));
|
||||
m_pUiLayer->addWidget(checkBox);
|
||||
|
|
|
@ -57,14 +57,7 @@ bool UIDragPanelTest::init()
|
|||
(backgroundSize.width - dragPanel->getSize().width) / 2,
|
||||
(widgetSize.height - backgroundSize.height) / 2 +
|
||||
(backgroundSize.height - dragPanel->getSize().height) / 2));
|
||||
dragPanel->addBerthToLeftBottomEvent(this, coco_DragPane_BerthToLeftBottom_selector(UIDragPanelTest::berthToLeftBottomEvent));
|
||||
dragPanel->addBerthToLeftTopEvent(this, coco_DragPanel_BerthToLeftTop_selector(UIDragPanelTest::berthToLeftTopEvent));
|
||||
dragPanel->addBerthToRightBottomEvent(this, coco_DragPanel_BerthToRightBottom_selector(UIDragPanelTest::berthToRightBottomEvent));
|
||||
dragPanel->addBerthToRightTopEvent(this, coco_DragPanel_BerthToRightTop_selector(UIDragPanelTest::berthToRightTopEvent));
|
||||
dragPanel->addBerthToLeftEvent(this, coco_DragPanel_BerthToLeft_selector(UIDragPanelTest::berthToLeftEvent));
|
||||
dragPanel->addBerthToTopEvent(this, coco_DragPanel_BerthToTop_selector(UIDragPanelTest::berthToTopEvent));
|
||||
dragPanel->addBerthToRightEvent(this, coco_DragPanel_BerthToRight_selector(UIDragPanelTest::berthToRightEvent));
|
||||
dragPanel->addBerthToBottomEvent(this, coco_DragPanel_BerthToBottom_selector(UIDragPanelTest::berthToBottomEvent));
|
||||
dragPanel->addEventListener(this, dragpaneleventselector(UIDragPanelTest::dragPanelEvent));
|
||||
|
||||
UIImageView* imageView = UIImageView::create();
|
||||
imageView->setTouchEnabled(true);
|
||||
|
@ -82,44 +75,45 @@ bool UIDragPanelTest::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToLeftBottomEvent(Object *pSender)
|
||||
void UIDragPanelTest::dragPanelEvent(Object *pSender, DragPanelEventType type)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Bottom")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToLeftTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToRightBottomEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Bottom")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToRightTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToLeftEvent(Object* pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToRightEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest::berthToBottomEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Bottom")->getCString());
|
||||
switch (type)
|
||||
{
|
||||
case DRAGPANEL_EVENT_BERTH_LEFTBOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Bottom")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_LFETTOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_RIGHTBOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Bottom")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_RIGHTTOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_LEFT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Left")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_TOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_RIGHT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Right")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BERTH_BOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Berth To Bottom")->getCString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// UIDragPanelTest_Bounce
|
||||
|
@ -171,14 +165,7 @@ bool UIDragPanelTest_Bounce::init()
|
|||
(backgroundSize.width - dragPanel->getSize().width) / 2,
|
||||
(widgetSize.height - backgroundSize.height) / 2 +
|
||||
(backgroundSize.height - dragPanel->getSize().height) / 2));
|
||||
dragPanel->addBounceToLeftBottomEvent(this, coco_DragPanel_BounceToLeftBottom_selector(UIDragPanelTest_Bounce::bounceToLeftBottomEvent));
|
||||
dragPanel->addBounceToLeftTopEvent(this, coco_DragPanel_BounceToLeftTop_selector(UIDragPanelTest_Bounce::bounceToLeftTopEvent));
|
||||
dragPanel->addBounceToRightBottomEvent(this, coco_DragPanel_BounceToRightBottom_selector(UIDragPanelTest_Bounce::bounceToRightBottomEvent));
|
||||
dragPanel->addBounceToRightTopEvent(this, coco_DragPanel_BounceToRightTop_selector(UIDragPanelTest_Bounce::bounceToRightTopEvent));
|
||||
dragPanel->addBounceToLeftEvent(this, coco_DragPanel_BounceToLeft_selector(UIDragPanelTest_Bounce::bounceToLeftEvent));
|
||||
dragPanel->addBounceToTopEvent(this, coco_DragPanel_BounceToTop_selector(UIDragPanelTest_Bounce::bounceToTopEvent));
|
||||
dragPanel->addBounceToRightEvent(this, coco_DragPanel_BounceToRight_selector(UIDragPanelTest_Bounce::bounceToRightEvent));
|
||||
dragPanel->addBounceToBottomEvent(this, coco_DragPanel_BounceToBottom_selector(UIDragPanelTest_Bounce::bounceToBottomEvent));
|
||||
dragPanel->addEventListener(this, dragpaneleventselector(UIDragPanelTest_Bounce::dragPanelEvent));
|
||||
|
||||
UIImageView* imageView = UIImageView::create();
|
||||
imageView->setTouchEnabled(true);
|
||||
|
@ -197,42 +184,43 @@ bool UIDragPanelTest_Bounce::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToLeftBottomEvent(Object *pSender)
|
||||
void UIDragPanelTest_Bounce::dragPanelEvent(Object *pSender, DragPanelEventType type)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Bottom")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToLeftTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToRightBottomEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Bottom")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToRightTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToLeftEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToTopEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Top")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToRightEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right")->getCString());
|
||||
}
|
||||
|
||||
void UIDragPanelTest_Bounce::bounceToBottomEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Bottom")->getCString());
|
||||
switch (type)
|
||||
{
|
||||
case DRAGPANEL_EVENT_BOUNCE_LEFTBOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Bottom")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_LEFTTOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_RIGHTBOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Bottom")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_RIGHTTOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_LEFT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Left")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_TOP:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Top")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_RIGHT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Right")->getCString());
|
||||
break;
|
||||
|
||||
case DRAGPANEL_EVENT_BOUNCE_BOTTOM:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("Bounce To Bottom")->getCString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,7 @@ public:
|
|||
UIDragPanelTest();
|
||||
~UIDragPanelTest();
|
||||
bool init();
|
||||
void berthToLeftBottomEvent(Object* pSender);
|
||||
void berthToLeftTopEvent(Object* pSender);
|
||||
void berthToRightBottomEvent(Object* pSender);
|
||||
void berthToRightTopEvent(Object* pSender);
|
||||
void berthToLeftEvent(Object* pSender);
|
||||
void berthToTopEvent(Object* pSender);
|
||||
void berthToRightEvent(Object* pSender);
|
||||
void berthToBottomEvent(Object* pSender);
|
||||
void dragPanelEvent(Object* pSender, DragPanelEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIDragPanelTest)
|
||||
|
@ -53,14 +46,7 @@ public:
|
|||
UIDragPanelTest_Bounce();
|
||||
~UIDragPanelTest_Bounce();
|
||||
bool init();
|
||||
void bounceToLeftBottomEvent(Object* pSender);
|
||||
void bounceToRightBottomEvent(Object* pSender);
|
||||
void bounceToLeftTopEvent(Object* pSender);
|
||||
void bounceToRightTopEvent(Object* pSender);
|
||||
void bounceToLeftEvent(Object* pSender);
|
||||
void bounceToTopEvent(Object* pSender);
|
||||
void bounceToRightEvent(Object* pSender);
|
||||
void bounceToBottomEvent(Object* pSender);
|
||||
void dragPanelEvent(Object* pSender, DragPanelEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIDragPanelTest_Bounce)
|
||||
|
|
|
@ -90,8 +90,7 @@ bool UIListViewTest_Vertical::init()
|
|||
|
||||
listView->addChild(layout);
|
||||
}
|
||||
listView->addInitChildEvent(this, coco_ListView_InitChild_selector(UIListViewTest_Vertical::initChildEvent));
|
||||
listView->addUpdateChildEvent(this, coco_ListView_UpdateChild_selector(UIListViewTest_Vertical::updateChildEvent));
|
||||
listView->addEventListenter(this, listvieweventselector(UIListViewTest_Vertical::listViewEvent));
|
||||
listView->initChildWithDataLength(m_array->count());
|
||||
m_pUiLayer->addWidget(listView);
|
||||
|
||||
|
@ -101,33 +100,44 @@ bool UIListViewTest_Vertical::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UIListViewTest_Vertical::initChildEvent(Object *pSender)
|
||||
void UIListViewTest_Vertical::listViewEvent(Object *pSender, ListViewEventType type)
|
||||
{
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
|
||||
m_nCount++;
|
||||
}
|
||||
|
||||
void UIListViewTest_Vertical::updateChildEvent(Object *pSender)
|
||||
{
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
int index = list->getUpdateDataIndex();
|
||||
|
||||
if (index < 0 || index >= list->getDataLength())
|
||||
switch (type)
|
||||
{
|
||||
list->setUpdateSuccess(false);
|
||||
case LISTVIEW_EVENT_INIT_CHILD:
|
||||
{
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
|
||||
m_nCount++;
|
||||
}
|
||||
break;
|
||||
|
||||
case LISTVIEW_EVENT_UPDATE_CHILD:
|
||||
{
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
int index = list->getUpdateDataIndex();
|
||||
|
||||
if (index < 0 || index >= list->getDataLength())
|
||||
{
|
||||
list->setUpdateSuccess(false);
|
||||
}
|
||||
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
list->setUpdateSuccess(true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
list->setUpdateSuccess(true);
|
||||
}
|
||||
|
||||
// UIListViewTest_Horizontal
|
||||
|
@ -211,8 +221,7 @@ bool UIListViewTest_Horizontal::init()
|
|||
|
||||
listView->addChild(layout);
|
||||
}
|
||||
listView->addInitChildEvent(this, coco_ListView_InitChild_selector(UIListViewTest_Horizontal::initChildEvent));
|
||||
listView->addUpdateChildEvent(this, coco_ListView_UpdateChild_selector(UIListViewTest_Horizontal::updateChildEvent));
|
||||
listView->addEventListenter(this, listvieweventselector(UIListViewTest_Horizontal::listViewEvent));
|
||||
listView->initChildWithDataLength(m_array->count());
|
||||
m_pUiLayer->addWidget(listView);
|
||||
|
||||
|
@ -222,31 +231,42 @@ bool UIListViewTest_Horizontal::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UIListViewTest_Horizontal::initChildEvent(Object *pSender)
|
||||
void UIListViewTest_Horizontal::listViewEvent(Object *pSender, ListViewEventType type)
|
||||
{
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
|
||||
m_nCount++;
|
||||
}
|
||||
|
||||
void UIListViewTest_Horizontal::updateChildEvent(Object *pSender)
|
||||
{
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
int index = list->getUpdateDataIndex();
|
||||
|
||||
if (index < 0 || index >= list->getDataLength())
|
||||
switch (type)
|
||||
{
|
||||
list->setUpdateSuccess(false);
|
||||
case LISTVIEW_EVENT_INIT_CHILD:
|
||||
{
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(m_nCount));
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
|
||||
m_nCount++;
|
||||
}
|
||||
break;
|
||||
|
||||
case LISTVIEW_EVENT_UPDATE_CHILD:
|
||||
{
|
||||
UIListView* list = dynamic_cast<UIListView*>(pSender);
|
||||
int index = list->getUpdateDataIndex();
|
||||
|
||||
if (index < 0 || index >= list->getDataLength())
|
||||
{
|
||||
list->setUpdateSuccess(false);
|
||||
}
|
||||
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
list->setUpdateSuccess(true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
String* ccstr = static_cast<String*>(m_array->getObjectAtIndex(index));
|
||||
Layout* layout = dynamic_cast<Layout*>(list->getUpdateChild());
|
||||
UIButton* textButton = dynamic_cast<UIButton*>(layout->getChildByName("TextButton"));
|
||||
textButton->setTitleText(ccstr->getCString());
|
||||
list->setUpdateSuccess(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,8 @@ class UIListViewTest_Vertical : public UIScene
|
|||
public:
|
||||
UIListViewTest_Vertical();
|
||||
~UIListViewTest_Vertical();
|
||||
bool init();
|
||||
void initChildEvent(Object* pSender);
|
||||
void updateChildEvent(Object* pSender);
|
||||
bool init();
|
||||
void listViewEvent(Object* pSender, ListViewEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
|
||||
|
@ -50,8 +49,7 @@ public:
|
|||
UIListViewTest_Horizontal();
|
||||
~UIListViewTest_Horizontal();
|
||||
bool init();
|
||||
void initChildEvent(Object* pSender);
|
||||
void updateChildEvent(Object* pSender);
|
||||
void listViewEvent(Object* pSender, ListViewEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)
|
||||
|
|
|
@ -79,8 +79,7 @@ bool UIPageViewTest::init()
|
|||
|
||||
pageView->addPage(layout);
|
||||
}
|
||||
|
||||
pageView->addPageTurningEvent(this, coco_PageView_PageTurning_selector(UIPageViewTest::pageTurningEvent));
|
||||
pageView->addEventListener(this, pagevieweventselector(UIPageViewTest::pageViewEvent));
|
||||
|
||||
m_pUiLayer->addWidget(pageView);
|
||||
|
||||
|
@ -89,10 +88,19 @@ bool UIPageViewTest::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UIPageViewTest::pageTurningEvent(Object *pSender)
|
||||
void UIPageViewTest::pageViewEvent(Object *pSender, PageViewEventType type)
|
||||
{
|
||||
UIPageView* pageView = dynamic_cast<UIPageView*>(pSender);
|
||||
CCLOG("page = %d", pageView->getCurPageIndex());
|
||||
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("page = %d", pageView->getCurPageIndex() + 1)->getCString());
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case PAGEVIEW_EVENT_TURNING:
|
||||
{
|
||||
UIPageView* pageView = dynamic_cast<UIPageView*>(pSender);
|
||||
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("page = %d", pageView->getCurPageIndex() + 1)->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
~UIPageViewTest();
|
||||
bool init();
|
||||
|
||||
void pageTurningEvent(Object* pSender);
|
||||
void pageViewEvent(Object* pSender, PageViewEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIPageViewTest)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "cocos-ext.h"
|
||||
#include "UIScene.h"
|
||||
#include "UISceneManager.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
|
||||
UIScene::UIScene()
|
||||
: m_pSceneTitle(NULL)
|
||||
|
@ -40,13 +41,16 @@ bool UIScene::init()
|
|||
UIButton *right_button = dynamic_cast<UIButton*>(m_pUiLayer->getWidgetByName("right_Button"));
|
||||
right_button->addTouchEventListener(this, toucheventselector(UIScene::nextCallback));
|
||||
|
||||
// exit button
|
||||
UIButton* exit_button = UIButton::create();
|
||||
exit_button->setTouchEnabled(true);
|
||||
exit_button->loadTextures("CloseNormal.png", "CloseSelected.png", "");
|
||||
exit_button->setPosition(Point(m_pUiLayer->getContentSize().width - exit_button->getContentSize().width, exit_button->getContentSize().height));
|
||||
exit_button->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback));
|
||||
m_pUiLayer->addWidget(exit_button);
|
||||
|
||||
UILabel* mainMenuLabel = UILabel::create();
|
||||
mainMenuLabel->setText("MainMenu");
|
||||
mainMenuLabel->setFontSize(20);
|
||||
mainMenuLabel->setTouchScaleChangeEnabled(true);
|
||||
mainMenuLabel->setPosition(Point(430,30));
|
||||
mainMenuLabel->setTouchEnabled(true);
|
||||
mainMenuLabel->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback));
|
||||
m_pUiLayer->addWidget(mainMenuLabel);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -57,12 +61,10 @@ void UIScene::menuCloseCallback(Object* pSender, TouchEventType type)
|
|||
{
|
||||
if (type == TOUCH_EVENT_ENDED)
|
||||
{
|
||||
CCDirector::getInstance()->end();
|
||||
auto scene = new ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void UIScene::previousCallback(Object* sender, TouchEventType type)
|
||||
|
|
|
@ -52,7 +52,7 @@ bool UISliderTest::init()
|
|||
slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", "");
|
||||
slider->loadProgressBarTexture("cocosgui/sliderProgress.png");
|
||||
slider->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||
slider->addPercentEvent(this, sliderpercentchangedselector(UISliderTest::percentChangedEvent));
|
||||
slider->addEventListener(this, sliderpercentchangedselector(UISliderTest::percentChangedEvent));
|
||||
m_pUiLayer->addWidget(slider);
|
||||
|
||||
return true;
|
||||
|
@ -116,7 +116,7 @@ bool UISliderTest_Scale9::init()
|
|||
slider->setCapInsets(Rect(0, 0, 0, 0));
|
||||
slider->setSize(Size(250, 10));
|
||||
slider->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||
slider->addPercentEvent(this, sliderpercentchangedselector(UISliderTest_Scale9::percentChangedEvent));
|
||||
slider->addEventListener(this, sliderpercentchangedselector(UISliderTest_Scale9::percentChangedEvent));
|
||||
m_pUiLayer->addWidget(slider);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -51,10 +51,7 @@ bool UITextFieldTest::init()
|
|||
textField->setFontSize(30);
|
||||
textField->setPlaceHolder("input words here");
|
||||
textField->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||
textField->addAttachWithIMEEvent(this, coco_TextField_AttachWithIME_selector(UITextFieldTest::attachWithIMEEvent));
|
||||
textField->addDetachWithIMEEvent(this, coco_TextField_DetachWithIME_selector(UITextFieldTest::detachWithIMEEvent));
|
||||
textField->addInsertTextEvent(this, coco_TextField_InsertText_selector(UITextFieldTest::insertTextEvent));
|
||||
textField->addDeleteBackwardEvent(this, coco_TextField_DeleteBackward_selector(UITextFieldTest::deleteBackwardEvent));
|
||||
textField->addEventListener(this, textfieldeventselector(UITextFieldTest::textFieldEvent));
|
||||
m_pUiLayer->addWidget(textField);
|
||||
|
||||
return true;
|
||||
|
@ -62,31 +59,40 @@ bool UITextFieldTest::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UITextFieldTest::attachWithIMEEvent(Object *pSender)
|
||||
void UITextFieldTest::textFieldEvent(Object *pSender, TextFiledEventType type)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest::detachWithIMEEvent(Object* pSender)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest::insertTextEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest::deleteBackwardEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word")->getCString());
|
||||
switch (type)
|
||||
{
|
||||
case TEXTFIELD_EVENT_ATTACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME")->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DETACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME")->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_INDERT_TEXT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words")->getCString());
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DELETE_BACKWARD:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word")->getCString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// UITextFieldTest_MaxLength
|
||||
|
@ -133,10 +139,7 @@ bool UITextFieldTest_MaxLength::init()
|
|||
textField->setFontSize(30);
|
||||
textField->setPlaceHolder("input words here");
|
||||
textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f));
|
||||
textField->addAttachWithIMEEvent(this, coco_TextField_AttachWithIME_selector(UITextFieldTest_MaxLength::attachWithIMEEvent));
|
||||
textField->addDetachWithIMEEvent(this, coco_TextField_DetachWithIME_selector(UITextFieldTest_MaxLength::detachWithIMEEvent));
|
||||
textField->addInsertTextEvent(this, coco_TextField_InsertText_selector(UITextFieldTest_MaxLength::insertTextEvent));
|
||||
textField->addDeleteBackwardEvent(this, coco_TextField_DeleteBackward_selector(UITextFieldTest_MaxLength::deleteBackwardEvent));
|
||||
textField->addEventListener(this, textfieldeventselector(UITextFieldTest_MaxLength::textFieldEvent));
|
||||
m_pUiLayer->addWidget(textField);
|
||||
|
||||
return true;
|
||||
|
@ -144,33 +147,46 @@ bool UITextFieldTest_MaxLength::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UITextFieldTest_MaxLength::attachWithIMEEvent(Object *pSender)
|
||||
void UITextFieldTest_MaxLength::textFieldEvent(Object *pSender, TextFiledEventType type)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_MaxLength::detachWithIMEEvent(Object* pSender)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_MaxLength::insertTextEvent(Object *pSender)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_MaxLength::deleteBackwardEvent(Object *pSender)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word max length %d", textField->getMaxLength())->getCString());
|
||||
switch (type)
|
||||
{
|
||||
case TEXTFIELD_EVENT_ATTACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DETACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_INDERT_TEXT:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DELETE_BACKWARD:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word max length %d", textField->getMaxLength())->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// UITextFieldTest_Password
|
||||
|
@ -217,10 +233,7 @@ bool UITextFieldTest_Password::init()
|
|||
textField->setFontSize(30);
|
||||
textField->setPlaceHolder("input password here");
|
||||
textField->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f));
|
||||
textField->addAttachWithIMEEvent(this, coco_TextField_AttachWithIME_selector(UITextFieldTest_Password::attachWithIMEEvent));
|
||||
textField->addDetachWithIMEEvent(this, coco_TextField_DetachWithIME_selector(UITextFieldTest_Password::detachWithIMEEvent));
|
||||
textField->addInsertTextEvent(this, coco_TextField_InsertText_selector(UITextFieldTest_Password::insertTextEvent));
|
||||
textField->addDeleteBackwardEvent(this, coco_TextField_DeleteBackward_selector(UITextFieldTest_Password::deleteBackwardEvent));
|
||||
textField->addEventListener(this, textfieldeventselector(UITextFieldTest_Password::textFieldEvent));
|
||||
m_pUiLayer->addWidget(textField);
|
||||
|
||||
return true;
|
||||
|
@ -228,29 +241,38 @@ bool UITextFieldTest_Password::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
void UITextFieldTest_Password::attachWithIMEEvent(Object *pSender)
|
||||
void UITextFieldTest_Password::textFieldEvent(Object *pSender, TextFiledEventType type)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME password")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_Password::detachWithIMEEvent(Object* pSender)
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME password")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_Password::insertTextEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words password")->getCString());
|
||||
}
|
||||
|
||||
void UITextFieldTest_Password::deleteBackwardEvent(Object *pSender)
|
||||
{
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word password")->getCString());
|
||||
switch (type)
|
||||
{
|
||||
case TEXTFIELD_EVENT_ATTACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.225,
|
||||
Point(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("attach with IME password")->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DETACH_WITH_IME:
|
||||
{
|
||||
UITextField* textField = dynamic_cast<UITextField*>(pSender);
|
||||
Size screenSize = CCDirector::getInstance()->getWinSize();
|
||||
textField->runAction(CCMoveTo::create(0.175, Point(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("detach with IME password")->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_INDERT_TEXT:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("insert words password")->getCString());
|
||||
break;
|
||||
|
||||
case TEXTFIELD_EVENT_DELETE_BACKWARD:
|
||||
m_pDisplayValueLabel->setText(CCString::createWithFormat("delete word password")->getCString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,7 @@ public:
|
|||
UITextFieldTest();
|
||||
~UITextFieldTest();
|
||||
bool init();
|
||||
void attachWithIMEEvent(Object* pSender);
|
||||
void detachWithIMEEvent(Object* pSender);
|
||||
void insertTextEvent(Object* pSender);
|
||||
void deleteBackwardEvent(Object* pSender);
|
||||
void textFieldEvent(Object* pSender, TextFiledEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UITextFieldTest)
|
||||
|
@ -49,10 +46,7 @@ public:
|
|||
UITextFieldTest_MaxLength();
|
||||
~UITextFieldTest_MaxLength();
|
||||
bool init();
|
||||
void attachWithIMEEvent(Object* pSender);
|
||||
void detachWithIMEEvent(Object* pSender);
|
||||
void insertTextEvent(Object* pSender);
|
||||
void deleteBackwardEvent(Object* pSender);
|
||||
void textFieldEvent(Object* pSender, TextFiledEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UITextFieldTest_MaxLength)
|
||||
|
@ -65,10 +59,7 @@ public:
|
|||
UITextFieldTest_Password();
|
||||
~UITextFieldTest_Password();
|
||||
bool init();
|
||||
void attachWithIMEEvent(Object* pSender);
|
||||
void detachWithIMEEvent(Object* pSender);
|
||||
void insertTextEvent(Object* pSender);
|
||||
void deleteBackwardEvent(Object* pSender);
|
||||
void textFieldEvent(Object* pSender, TextFiledEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UITextFieldTest_Password)
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
#include "PhysicsTest.h"
|
||||
#include "../testResource.h"
|
||||
USING_NS_CC;
|
||||
|
||||
PhysicsTestLayer::PhysicsTestLayer()
|
||||
: _spriteTexture(nullptr)
|
||||
, _scene(nullptr)
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
setTouchEnabled(true);
|
||||
setAccelerometerEnabled(true);
|
||||
|
||||
// title
|
||||
auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
|
||||
label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30));
|
||||
this->addChild(label, -1);
|
||||
|
||||
// menu for debug layer
|
||||
MenuItemFont::setFontSize(18);
|
||||
auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(PhysicsTestLayer::toggleDebugCallback, this));
|
||||
|
||||
auto menu = Menu::create(item, NULL);
|
||||
this->addChild(menu);
|
||||
menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60));
|
||||
|
||||
auto sp = Sprite::create();
|
||||
auto body = PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size);
|
||||
sp->setPhysicsBody(body);
|
||||
this->addChild(sp);
|
||||
sp->setPosition(VisibleRect::center());
|
||||
|
||||
auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
||||
_spriteTexture = parent->getTexture();
|
||||
|
||||
addNewSpriteAtPosition(VisibleRect::center());
|
||||
|
||||
createResetButton();
|
||||
|
||||
#else
|
||||
auto label = LabelTTF::create("Should define CC_USE_BOX2D or CC_USE_CHIPMUNK\n to run this test case",
|
||||
"Arial",
|
||||
18);
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
label->setPosition(Point(size.width/2, size.height/2));
|
||||
|
||||
addChild(label);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PhysicsTestLayer::toggleDebugCallback(Object* sender)
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
if (_scene != nullptr)
|
||||
{
|
||||
_scene->getPhysicsWorld()->setDebugDraw(!_scene->getPhysicsWorld()->isDebugDraw());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PhysicsTestLayer::~PhysicsTestLayer()
|
||||
{
|
||||
}
|
||||
|
||||
void PhysicsTestLayer::createResetButton()
|
||||
{
|
||||
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [](Object *sender) {
|
||||
auto s = new PhysicsTestScene();
|
||||
s->initTest();
|
||||
auto child = new PhysicsTestLayer();
|
||||
child->setScene(s);
|
||||
s->addChild(child);
|
||||
child->release();
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
});
|
||||
|
||||
auto menu = Menu::create(reset, NULL);
|
||||
|
||||
menu->setPosition(Point(VisibleRect::bottom().x, VisibleRect::bottom().y + 30));
|
||||
this->addChild(menu, -1);
|
||||
|
||||
}
|
||||
|
||||
void PhysicsTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
|
||||
for( auto &touch: touches)
|
||||
{
|
||||
auto location = touch->getLocation();
|
||||
|
||||
addNewSpriteAtPosition( location );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PhysicsTestLayer::onAcceleration(Acceleration* acc, Event* event)
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
static float prevX=0, prevY=0;
|
||||
|
||||
#define kFilterFactor 0.05f
|
||||
|
||||
float accelX = (float) acc->x * kFilterFactor + (1- kFilterFactor)*prevX;
|
||||
float accelY = (float) acc->y * kFilterFactor + (1- kFilterFactor)*prevY;
|
||||
|
||||
prevX = accelX;
|
||||
prevY = accelY;
|
||||
|
||||
auto v = Point( accelX, accelY);
|
||||
v = v * 200;
|
||||
|
||||
if(_scene != nullptr)
|
||||
{
|
||||
_scene->getPhysicsWorld()->setGravity(v);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PhysicsTestLayer::addNewSpriteAtPosition(Point p)
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
|
||||
int posx, posy;
|
||||
|
||||
posx = CCRANDOM_0_1() * 200.0f;
|
||||
posy = CCRANDOM_0_1() * 200.0f;
|
||||
|
||||
posx = (posx % 4) * 85;
|
||||
posy = (posy % 3) * 121;
|
||||
|
||||
auto sp = Sprite::createWithTexture(_spriteTexture, Rect(posx, posy, 85, 121));
|
||||
auto body = PhysicsBody::createBox(Size(48, 108));
|
||||
sp->setPhysicsBody(body);
|
||||
sp->setPosition(p);
|
||||
this->addChild(sp);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PhysicsTestScene::initTest()
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
if (TestScene::initWithPhysics())
|
||||
{
|
||||
this->getPhysicsWorld()->setDebugDraw(true);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
return TestScene::init();
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PhysicsTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new PhysicsTestLayer();
|
||||
layer->setScene(this);
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef _PHYSICS_TEST_H_
|
||||
#define _PHYSICS_TEST_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
|
||||
class PhysicsTestLayer : public Layer
|
||||
{
|
||||
Texture2D* _spriteTexture; // weak ref
|
||||
Scene* _scene;
|
||||
|
||||
public:
|
||||
PhysicsTestLayer();
|
||||
~PhysicsTestLayer();
|
||||
|
||||
void createResetButton();
|
||||
|
||||
inline void setScene(Scene* scene) { _scene = scene; }
|
||||
void toggleDebugCallback(Object* sender);
|
||||
void addNewSpriteAtPosition(Point p);
|
||||
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event) override;
|
||||
} ;
|
||||
|
||||
class PhysicsTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual bool initTest() override;
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -64,6 +64,7 @@ struct {
|
|||
{ "ParallaxTest", [](){return new ParallaxTestScene(); } },
|
||||
{ "ParticleTest", [](){return new ParticleTestScene(); } },
|
||||
{ "PerformanceTest", []() { return new PerformanceTestScene(); } },
|
||||
{ "PhysicsTest", []() { return new PhysicsTestScene(); } },
|
||||
{ "RenderTextureTest", [](){return new RenderTextureScene(); } },
|
||||
{ "RotateWorldTest", [](){return new RotateWorldTestScene(); } },
|
||||
{ "SceneTest", [](){return new SceneTestScene();} },
|
||||
|
@ -150,7 +151,7 @@ void TestController::menuCallback(Object * sender)
|
|||
// create the test scene and run it
|
||||
auto scene = g_aTestNames[idx].callback();
|
||||
|
||||
if (scene)
|
||||
if (scene && scene->initTest())
|
||||
{
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
TestScene::TestScene(bool bPortrait)
|
||||
{
|
||||
|
||||
Scene::init();
|
||||
}
|
||||
|
||||
bool TestScene::initTest()
|
||||
{
|
||||
return Scene::init();
|
||||
}
|
||||
|
||||
void TestScene::onEnter()
|
||||
|
|
|
@ -12,6 +12,7 @@ class TestScene : public Scene
|
|||
{
|
||||
public:
|
||||
TestScene(bool bPortrait = false);
|
||||
virtual bool initTest();
|
||||
virtual void onEnter();
|
||||
|
||||
virtual void runThisTest() = 0;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue