Sprite3DHitTest use AABB testing

This commit is contained in:
songchengjiang 2014-09-09 17:05:33 +08:00
parent c4fe5728ee
commit 117c38f806
1 changed files with 4 additions and 8 deletions

View File

@ -241,7 +241,6 @@ Sprite3DHitTest::Sprite3DHitTest()
sprite1->setScale(4.f);
sprite1->setTexture("Sprite3DTest/boss.png");
sprite1->setPosition( Vec2(s.width/2, s.height/2) );
sprite1->setContentSize(Size(20, 20));
//add to scene
addChild( sprite1 );
@ -266,14 +265,11 @@ Sprite3DHitTest::Sprite3DHitTest()
listener1->onTouchBegan = [](Touch* touch, Event* event){
auto target = static_cast<Sprite3D*>(event->getCurrentTarget());
Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(-s.width/2, -s.height/2, s.width, s.height);
if (rect.containsPoint(locationInNode))
Rect rect = target->getBoundingBox();
if (rect.containsPoint(touch->getLocation()))
{
log("sprite3d began... x = %f, y = %f", locationInNode.x, locationInNode.y);
log("sprite3d began... x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);
target->setOpacity(100);
return true;
}