ブロックの行があるブロック ゲームを作成しようとしています。エンド ブロックを右から左にスライドさせ、他の各ブロックを右に 1 位置移動させます。次に、ブロックをもう一度スライドさせると、すべてのブロックが 1 ポジション左にスライドします。私が抱えている問題は、ゆっくりとドラッグすると正常に動作しますが、すばやく前後にドラッグすると、ブロックがすべて台無しになり、ブロックが互いに重なって移動するため、6 列ではなく 4 列になることです。 2 つのブロックが他のブロックの後ろにあるためです。アドバイスをいただければ幸いです。
これが私のScene.Mのコードです
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.selectedNode = [self nodeAtPoint:[[touches anyObject] locationInNode:self]];
[self.selectedNode.physicsBody setDynamic:YES];
self.selectedNode.zPosition = 1;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint currentPoint = CGPointMake([[touches anyObject] locationInNode:self].x , selectedNode.position.y);
CGPoint previousPoint = CGPointMake([[touches anyObject] previousLocationInNode:self].x , selectedNode.position.y);
_deltaPoint = CGPointSubtract(currentPoint, previousPoint);
}
-(void)update:(CFTimeInterval)currentTime {
CGPoint newPoint = CGPointAdd(self.selectedNode.position, _deltaPoint);
self.selectedNode.position = newPoint;
_deltaPoint = CGPointZero;
}
-(void)didBeginContact:(SKPhysicsContact *)contact{
SKNode *node = contact.bodyA.node;
if ([node isKindOfClass:[Block class]] && node != selectedNode) {
[(Block *)node collidedWith:contact.bodyB contact:contact];
}
node = contact.bodyB.node;
if ([node isKindOfClass:[Block class]] && node != selectedNode) {
[(Block *)node collidedWith:contact.bodyA contact:contact];
}
}
ここに私のBlock.Mからの私のコードがあります
-(instancetype)initWithPosition:(CGPoint)pos andType:(NSString *)blockType{
SKTextureAtlas *atlas =
[SKTextureAtlas atlasNamed: @"Blocks"];
SKTexture *texture = [atlas textureNamed:blockType];
texture.filteringMode = SKTextureFilteringNearest;
if (self = [super initWithTexture:texture]){
self.name = blockType;
self.position = pos;
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(self.size.width - 30, self.size.height - 8)];
self.physicsBody.usesPreciseCollisionDetection = YES;
self.physicsBody.categoryBitMask = 1;
self.physicsBody.collisionBitMask = 0;
self.physicsBody.contactTestBitMask = 1;
}
return self;
}
- (void)collidedWith:(SKPhysicsBody *)body contact:(SKPhysicsContact*)contact {
CGPoint localContactPoint = [self.scene convertPoint:contact.contactPoint toNode:self];
if (localContactPoint.x < 0) {
SKAction *moveLeftAction = [SKAction moveByX:-48 y:0 duration:0.0];
[self runAction:moveLeftAction];
} else {
SKAction *moveRightAction = [SKAction moveByX:48 y:0 duration:0.0];
[self runAction:moveRightAction];
}
}