Bug in PXSprite.hitArea?
  • neurofuzzyneurofuzzy September 2011
    Posts: 11

    Hi! I'm new to Pixelwave, Objective C and iOS development. I come from the Flash world, and was very pleased when I found this great framework. Thanks to SimianLogic for pointing me this way!


    Anyway, I was curious about PXSprite.hitArea. If I assign a PXRectangle to the hitArea, touch_up events no longer fire for that PXSprite. Am I doing something wrong?

    Thanks!
    Geoff
  • neurofuzzyneurofuzzy September 2011
    Posts: 11

    Oh, also, I was curious if setting a rectangle as the touch area is generally faster than using the contents of the sprite. And is it generally good to turn touchenabled to off if not needed?

  • oztuneoztune September 2011
    Posts: 177

    I will look into that issue and let you know if it's a bug or whatnot.

    Setting a rectangle is definitely faster since the hit testing is cheaper, and yeah it's always good to set touchEnabled = NO when something doesn't need to listen to touch events. Also, if you know that all the objects within a container will never need to receive touch events you can set container.touchChildren = NO (yea, the name is very unfortunate :)).

    Oz
    Pixelwave team
    // Founder
  • JohnJohn September 2011
    Posts: 52

    Neurofuzzy,


    I am having no problems with the hit area being a rectangle, try this stand-alone code and see if it works for you:

    - (void) initializeAsRoot
    {
        [PXDebug setDrawHitAreas:YES];
        [PXDebug setDrawBoundingBoxes:YES];
    
        PXSprite *sprite = [[PXSprite alloc] init];
        [self addChild:sprite];
    
        sprite.x = self.stage.stageWidth  * 0.5f;
        sprite.y = self.stage.stageHeight * 0.5f;
    
        [sprite.graphics beginFill:0x008080 alpha:1.0f];
        [sprite.graphics drawCircleWithX:0.0f y:0.0f radius:64.0f];
    
        PXRectangle *_hitArea = [[PXRectangle alloc] initWithX:-100.0f y:-100.0f width:200.0f height:200.0f];
        sprite.hitArea = _hitArea;
        [_hitArea release];
    
        [sprite addEventListenerOfType:PXTouchEvent_TouchUp listener:PXListener(onTouch:)];
    }
    
    - (void) dealloc
    {
        [super dealloc];
    }
    
    - (void) onTouch:(PXTouchEvent *)event
    {
        NSLog (@"%@ [%@] on touch\n", event.type, event.stagePosition);
    }
    


    I turn the debug draws on so you can see the hit area. This may also help you find the bug you are having; otherwise, if you can reproduce the problem see if you can make a quick sample for me and I will hunt down a solution!

    Pixelwave Team - Lead Developer
    // Clean before you build, otherwise the dust will get in.
  • JohnJohn September 2011
    Posts: 52

    Neurofuzzy,


    After looking further into this, I found the problem you were having. If you pull from the develop branch then I have just pushed a fix for it. I hope this helps!
    Pixelwave Team - Lead Developer
    // Clean before you build, otherwise the dust will get in.
  • neurofuzzyneurofuzzy September 2011
    Posts: 11

    Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with OpenID

Sign In Apply for Membership

In this Discussion

Tagged

Top Posters