Jump to content

Kā izveidot lielāku lauku ap "node" metodei touch, objective c


artG
 Share

Recommended Posts

vēlos izveidot objektu kuru varētu ar pieskārienu vilkt pa noteikto trajektoriju te ir kods kuru izmantoju:

- (id)initWithName:(NSString *)name
{
    self = [super init];
    if (self) {

        self = [PaddleNode spriteNodeWithImageNamed: @"board.png"];
        self.userInteractionEnabled = YES;
        self.name = name;
        self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
        self.physicsBody.dynamic = NO;
        self.physicsBody.usesPreciseCollisionDetection = YES;
        self.physicsBody.categoryBitMask = paddleCategory;
        self.physicsBody.collisionBitMask = emptyCategory;
        self.currentTouchValue = nil;
    }
    
    return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    self.previousTouchesTimestamp = event.timestamp;

    
    for (UITouch *touch in touches) {
        self.currentTouchValue = [NSValue valueWithNonretainedObject:touch];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 
    self.currentTouchValue = nil;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        NSValue *key = [NSValue valueWithNonretainedObject:touch];
        if ([key isEqualToValue:self.currentTouchValue]) {

            CGPoint touchPoint = [touch locationInNode:self.scene];
            CGPoint movePoint = CGPointMake(self.position.x, touchPoint.y);
            if ([self withinParentFrame:movePoint])
                self.position = movePoint;
        }
    }

}

- (BOOL)withinParentFrame:(CGPoint)point
{
    CGFloat offset = self.size.height / 2;
    if (point.y >= offset && point.y <= self.scene.frame.size.height - offset)
        return YES;
    else
        return NO;
}

viss strādā, bet problēma ir tāda,ka objekts ir mazs un testējot piemēram uz iphone 5 dažreiz velkot ar pikstu tas nestrādā, jautājums,kā var uztaisīt lielāku lauku apkārt objektam, nemainot objekta lielumu, lai tas būtu atsaucīgāks.

Link to comment
Share on other sites

Neko nezinu par Apple vai kam tas ir domāts, bet varbūt uztaisīt otru neredzamu objektu? Mazākais seko lielajam.

Link to comment
Share on other sites

Iekš Unity3d es vienkārši attiecīgajam objektam pieliktu vēlamā izmēra lielāku kolaideru un norādītu, ka tas ir inputcollaider leyeris un iekš projekta fizikas propertijiem norādītu, ka tas neattiecas uz fizkas aprēķiniem.

 

un neko nezinot par Apple :)

 

Rekomendēju izrakt cauri šitajam -  

 

https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SpriteKitFramework_Ref/

un šitam

http://defuncapps.tumblr.com/post/129409909394/learning-spritekit-for-ios-using-swift-part-2

Link to comment
Share on other sites

Izveido kontu, vai pieraksties esošajā, lai komentētu

Jums ir jābūt šī foruma biedram, lai varētu komentēt tēmas

Izveidot jaunu kontu

Piereģistrējies un izveido jaunu kontu, tas būs viegli!

Reģistrēt jaunu kontu

Pierakstīties

Jums jau ir konts? Pierakstieties tajā šeit!

Pierakstīties tagad!
 Share

×
×
  • Izveidot jaunu...