我在Sprite工具包中編寫了一個遊戲,並且我遇到了CGPoint的問題,此刻如果手機是肖像,對象從屏幕右側進入並轉到左邊,我需要它從屏幕頂部進入並落到底部,我如何使它從屏幕頂部產生?同時,它也傳播權的那一刻,我想旅行向下這裏是所有相關的「導彈」的代碼..Sprite工具包CGPoint不按預期方式工作
static inline CGPoint CGPointAdd(const CGPoint a, const CGPoint b)
{
return CGPointMake(a.x + b.x, a.y + b.y);
}
static inline CGPoint CGPointMultiplyScalar(const CGPoint a, const CGFloat b)
{
return CGPointMake(a.x * b, a.y * b);
}
-(void)addMissile
{
//initalizing spaceship node
SKSpriteNode *missile;
missile = [SKSpriteNode spriteNodeWithImageNamed:@"red-missile.png"];
[missile setScale:.01];
//Adding SpriteKit physicsBody for collision detection
missile.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:missile.size];
missile.physicsBody.categoryBitMask = obstacleCategory;
missile.physicsBody.dynamic = YES;
missile.physicsBody.contactTestBitMask = shipCategory;
missile.physicsBody.collisionBitMask = 0;
missile.physicsBody.usesPreciseCollisionDetection = YES;
missile.name = @"missile";
//selecting random y position for missile
//int t = arc4random() % 300;
missile.position = CGPointMake(100, 100);
[self addChild:missile];
}
- (void)moveObstacle
{
NSArray *nodes = self.children;//1
for(SKNode * node in nodes){
if (![node.name isEqual: @"bg"] && ![node.name isEqual: @"ship"]) {
SKSpriteNode *ob = (SKSpriteNode *) node;
CGPoint obVelocity = CGPointMake(-OBJECT_VELOCITY, 0);
CGPoint amtToMove = CGPointMultiplyScalar(obVelocity,_dt);
ob.position = CGPointAdd(ob.position, amtToMove);
if(ob.position.y < 100)
{
[ob removeFromParent];
}
}
}
}
我該如何更新?我目前的方法不起作用 – user3110546
如果您從觸碰中調用shootMissileBegin,則每次觸摸屏幕時都會出現導彈,如果您在更新中調用導彈,導彈將每秒出現一次。或者更新它意味着什麼?給我更多的信息,我會幫你 –
嘿,我得到它的工作,乾杯:) – user3110546