mirror of https://github.com/axmolengine/axmol.git
Add new API Node::hitTest
This commit is contained in:
parent
1699dcc93d
commit
36042fdb55
|
@ -635,6 +635,12 @@ void Node::setContentSize(const Size & size)
|
|||
}
|
||||
}
|
||||
|
||||
bool Node::hitTest(const Vec2& worldPoint) const {
|
||||
auto p = this->convertToNodeSpace(worldPoint);
|
||||
auto& s = this->getContentSize();
|
||||
return Rect{0.f, 0.f, s.width, s.height}.containsPoint(p);
|
||||
}
|
||||
|
||||
// isRunning getter
|
||||
bool Node::isRunning() const
|
||||
{
|
||||
|
|
|
@ -562,6 +562,18 @@ public:
|
|||
virtual const Size& getContentSize() const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the untransformed size of the node.
|
||||
*
|
||||
* @param worldPoint The coord in GL world space.
|
||||
*
|
||||
* @return Whether the worldPoint is inside this node
|
||||
*
|
||||
* @remark since adxe-1.0
|
||||
*/
|
||||
virtual bool hitTest(const Vec2& worldPoint) const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether the node is visible.
|
||||
*
|
||||
|
|
|
@ -64,6 +64,10 @@ THE SOFTWARE.
|
|||
|
||||
#include "base/ccRandom.h"
|
||||
|
||||
#define CC_HALF_PI (M_PI * 0.5f)
|
||||
|
||||
#define CC_DOUBLE_PI (M_PI * 2)
|
||||
|
||||
/** @def CCRANDOM_MINUS1_1
|
||||
returns a random float between -1 and 1
|
||||
*/
|
||||
|
|
|
@ -26,7 +26,6 @@ THE SOFTWARE.
|
|||
#include "CCArmature.h"
|
||||
#include "CCBone.h"
|
||||
#include "CCArmatureDefine.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCDatas.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
|
|
@ -24,7 +24,6 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCBone.h"
|
||||
#include "CCArmature.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCArmatureDataManager.h"
|
||||
#include "CCTransformHelp.h"
|
||||
#include "CCDisplayManager.h"
|
||||
|
|
|
@ -32,7 +32,6 @@ THE SOFTWARE.
|
|||
#include "CCDataReaderHelper.h"
|
||||
#include "CCArmatureDataManager.h"
|
||||
#include "CCTransformHelp.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCArmatureDefine.h"
|
||||
#include "CCDatas.h"
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCDatas.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCTransformHelp.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
|
|
@ -25,7 +25,6 @@ THE SOFTWARE.
|
|||
#include "CCDisplayManager.h"
|
||||
#include "CCBone.h"
|
||||
#include "CCArmature.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCSkin.h"
|
||||
|
||||
#include "2d/CCParticleSystemQuad.h"
|
||||
|
@ -379,16 +378,13 @@ bool DisplayManager::containPoint(Vec2 &point)
|
|||
* the contour point. If this step is also false, then we can say the bone not contain this point.
|
||||
*
|
||||
*/
|
||||
|
||||
Vec2 outPoint;
|
||||
|
||||
Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay();
|
||||
Sprite *child = (Sprite *)sprite->getChildByTag(0);
|
||||
if(nullptr != child)
|
||||
sprite = child;
|
||||
|
||||
if (nullptr != sprite)
|
||||
ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint);
|
||||
ret = sprite->hitTest(point);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCProcessBase.h"
|
||||
#include "CCUtilMath.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCTransformHelp.h"
|
||||
#include "CCUtilMath.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ THE SOFTWARE.
|
|||
#include "CCArmatureAnimation.h"
|
||||
#include "CCBone.h"
|
||||
#include "CCArmature.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCTransformHelp.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
||||
|
||||
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 "CCUtilMath.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
||||
namespace cocostudio {
|
||||
|
||||
bool isSpriteContainPoint(Sprite *sprite, Vec2 point, Vec2 &outPoint)
|
||||
{
|
||||
outPoint = sprite->convertToNodeSpace(point);
|
||||
|
||||
Size s = sprite->getContentSize();
|
||||
Rect r(0, 0, s.width, s.height);
|
||||
|
||||
return r.containsPoint(outPoint);
|
||||
}
|
||||
|
||||
bool isSpriteContainPoint(Sprite *sprite, Vec2 point)
|
||||
{
|
||||
Vec2 p;
|
||||
return isSpriteContainPoint(sprite, point, p);
|
||||
}
|
||||
|
||||
|
||||
Vec2 bezierTo(float t, Vec2 &point1, Vec2 &point2, Vec2 &point3)
|
||||
{
|
||||
|
||||
Vec2 p;
|
||||
|
||||
p.x = pow((1 - t), 2) * point1.x + 2 * t * (1 - t) * point2.x + pow(t, 2) * point3.x;
|
||||
p.y = pow((1 - t), 2) * point1.y + 2 * t * (1 - t) * point2.y + pow(t, 2) * point3.y;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Vec2 bezierTo(float t, Vec2 &point1, Vec2 &point2, Vec2 &point3, Vec2 &point4)
|
||||
{
|
||||
Vec2 p;
|
||||
|
||||
p.x = point1.x * pow((1 - t), 3) + 3 * t * point2.x * pow((1 - t), 2) + 3 * point3.x * pow(t, 2) * (1 - t) + point4.x * pow(t, 3);
|
||||
p.y = point1.y * pow((1 - t), 3) + 3 * t * point2.y * pow((1 - t), 2) + 3 * point3.y * pow(t, 2) * (1 - t) + point4.y * pow(t, 3);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Vec2 circleTo(float t, Vec2 ¢er, float radius, float fromRadian, float radianDif)
|
||||
{
|
||||
Vec2 p;
|
||||
|
||||
p.x = center.x + radius * cos(fromRadian + radianDif * t);
|
||||
p.y = center.y + radius * sin(fromRadian + radianDif * t);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
||||
|
||||
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 __CCUTILMATH_H__
|
||||
#define __CCUTILMATH_H__
|
||||
|
||||
#include "2d/CCSprite.h"
|
||||
#include "CCArmatureDefine.h"
|
||||
#include "CocosStudioExport.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace cocostudio {
|
||||
|
||||
#define CC_DOUBLE_PI (M_PI*2)
|
||||
|
||||
#define CC_HALF_PI (M_PI * 0.5f)
|
||||
|
||||
|
||||
//! hit test function
|
||||
bool CCS_DLL isSpriteContainPoint(cocos2d::Sprite *sprite, cocos2d::Vec2 point);
|
||||
bool CCS_DLL isSpriteContainPoint(cocos2d::Sprite *sprite, cocos2d::Vec2 point, cocos2d::Vec2 &outPoint);
|
||||
|
||||
#define CC_SPRITE_CONTAIN_POINT(sprite, point) isSpriteContainPoint((sprite), (point))
|
||||
#define CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint) isSpriteContainPoint((sprite), (point), outPoint)
|
||||
|
||||
|
||||
//! motion curve function
|
||||
cocos2d::Vec2 CCS_DLL bezierTo(float t, cocos2d::Vec2 &point1, cocos2d::Vec2 &point2, cocos2d::Vec2 &point3);
|
||||
cocos2d::Vec2 CCS_DLL bezierTo(float t, cocos2d::Vec2 &point1, cocos2d::Vec2 &point2, cocos2d::Vec2 &point3, cocos2d::Vec2 &point4);
|
||||
|
||||
cocos2d::Vec2 CCS_DLL circleTo(float t, cocos2d::Vec2 ¢er, float radius, float fromRadian, float radianDif);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /*__CCUTILMATH_H__*/
|
|
@ -21,7 +21,6 @@
|
|||
#include "CCArmatureDefine.h"
|
||||
#include "CCDataReaderHelper.h"
|
||||
#include "CCTransformHelp.h"
|
||||
#include "CCUtilMath.h"
|
||||
#include "CCComBase.h"
|
||||
#include "CCComAttribute.h"
|
||||
#include "CCComAudio.h"
|
||||
|
|
Loading…
Reference in New Issue