Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode无法识别已定义的精灵? 我正在制作一个简单的iOS游戏,目标是让屏幕中间的天使向来自四面八方的怪物射箭。但是当我试图计算射出的箭的方向时,Xcode说“天使”精灵并不存在,尽管我已经使用过它。这是我的密码: #import "MyScene.h" static inline CGPoint rwAdd(CGPoint a, CGPoint b) { return CGPointMake(a.x + b.x, a.y + b.y); } static inline CGPoint rwSub(CGPoint a, CGPoint b) { return CGPointMake(a.x - b.x, a.y - b.y); } static inline CGPoint rwMult(CGPoint a, float b) { return CGPointMake(a.x * b, a.y * b); } static inline float rwLength(CGPoint a) { return sqrtf(a.x * a.x + a.y * a.y); } static inline CGPoint rwNormalize(CGPoint a) { float length = rwLength(a); return CGPointMake(a.x / length, a.y / length); } @implementation MyScene - (id) initWithSize: (CGSize) size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor colorWithRed: 1.0 green: 1.0 blue: 1.0 alpha: 1.0]; SKSpriteNode *angel = [SKSpriteNode spriteNodeWithImageNamed: @"Angel"]; angel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); angel.xScale = 0.25; angel.yScale = 0.25; [self addChild: angel]; } return self; } - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { UITouch * touch = [touches anyObject]; CGPoint location = [touch locationInNode: self]; SKSpriteNode *arrow = [SKSpriteNode spriteNodeWithImageNamed:@"Arrow"]; projectile.position = self.angel.position; CGPoint offset = rwSub(location, arrow.position); [self addChild: arrow]; CGPoint direction = rwNormalize(offset); CGPoint shootAmount = rwMult(direction, 500); CGPoint realDest = rwAdd(shootAmount, arrow.position); float velocity = 480.0/1.0; float realMoveDuration = self.size.width / velocity; SKAction *actionMove = [SKAction moveTo: realDest duration: realMoveDuration]; SKAction *actionMoveDone = [SKAction removeFromParent]; [arrow runAction: [SKAction sequence: @[actionMove, actionMoveDone]]]; } @end_Ios_Xcode_Sprite Kit - Fatal编程技术网

Xcode无法识别已定义的精灵? 我正在制作一个简单的iOS游戏,目标是让屏幕中间的天使向来自四面八方的怪物射箭。但是当我试图计算射出的箭的方向时,Xcode说“天使”精灵并不存在,尽管我已经使用过它。这是我的密码: #import "MyScene.h" static inline CGPoint rwAdd(CGPoint a, CGPoint b) { return CGPointMake(a.x + b.x, a.y + b.y); } static inline CGPoint rwSub(CGPoint a, CGPoint b) { return CGPointMake(a.x - b.x, a.y - b.y); } static inline CGPoint rwMult(CGPoint a, float b) { return CGPointMake(a.x * b, a.y * b); } static inline float rwLength(CGPoint a) { return sqrtf(a.x * a.x + a.y * a.y); } static inline CGPoint rwNormalize(CGPoint a) { float length = rwLength(a); return CGPointMake(a.x / length, a.y / length); } @implementation MyScene - (id) initWithSize: (CGSize) size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor colorWithRed: 1.0 green: 1.0 blue: 1.0 alpha: 1.0]; SKSpriteNode *angel = [SKSpriteNode spriteNodeWithImageNamed: @"Angel"]; angel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); angel.xScale = 0.25; angel.yScale = 0.25; [self addChild: angel]; } return self; } - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { UITouch * touch = [touches anyObject]; CGPoint location = [touch locationInNode: self]; SKSpriteNode *arrow = [SKSpriteNode spriteNodeWithImageNamed:@"Arrow"]; projectile.position = self.angel.position; CGPoint offset = rwSub(location, arrow.position); [self addChild: arrow]; CGPoint direction = rwNormalize(offset); CGPoint shootAmount = rwMult(direction, 500); CGPoint realDest = rwAdd(shootAmount, arrow.position); float velocity = 480.0/1.0; float realMoveDuration = self.size.width / velocity; SKAction *actionMove = [SKAction moveTo: realDest duration: realMoveDuration]; SKAction *actionMoveDone = [SKAction removeFromParent]; [arrow runAction: [SKAction sequence: @[actionMove, actionMoveDone]]]; } @end

Xcode无法识别已定义的精灵? 我正在制作一个简单的iOS游戏,目标是让屏幕中间的天使向来自四面八方的怪物射箭。但是当我试图计算射出的箭的方向时,Xcode说“天使”精灵并不存在,尽管我已经使用过它。这是我的密码: #import "MyScene.h" static inline CGPoint rwAdd(CGPoint a, CGPoint b) { return CGPointMake(a.x + b.x, a.y + b.y); } static inline CGPoint rwSub(CGPoint a, CGPoint b) { return CGPointMake(a.x - b.x, a.y - b.y); } static inline CGPoint rwMult(CGPoint a, float b) { return CGPointMake(a.x * b, a.y * b); } static inline float rwLength(CGPoint a) { return sqrtf(a.x * a.x + a.y * a.y); } static inline CGPoint rwNormalize(CGPoint a) { float length = rwLength(a); return CGPointMake(a.x / length, a.y / length); } @implementation MyScene - (id) initWithSize: (CGSize) size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor colorWithRed: 1.0 green: 1.0 blue: 1.0 alpha: 1.0]; SKSpriteNode *angel = [SKSpriteNode spriteNodeWithImageNamed: @"Angel"]; angel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); angel.xScale = 0.25; angel.yScale = 0.25; [self addChild: angel]; } return self; } - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { UITouch * touch = [touches anyObject]; CGPoint location = [touch locationInNode: self]; SKSpriteNode *arrow = [SKSpriteNode spriteNodeWithImageNamed:@"Arrow"]; projectile.position = self.angel.position; CGPoint offset = rwSub(location, arrow.position); [self addChild: arrow]; CGPoint direction = rwNormalize(offset); CGPoint shootAmount = rwMult(direction, 500); CGPoint realDest = rwAdd(shootAmount, arrow.position); float velocity = 480.0/1.0; float realMoveDuration = self.size.width / velocity; SKAction *actionMove = [SKAction moveTo: realDest duration: realMoveDuration]; SKAction *actionMoveDone = [SKAction removeFromParent]; [arrow runAction: [SKAction sequence: @[actionMove, actionMoveDone]]]; } @end,ios,xcode,sprite-kit,Ios,Xcode,Sprite Kit,当我定义“arrow.position=self.angle.position”时,Xcode不会将“angle”识别为精灵。非常感谢您的帮助。变量超出范围。您正在将其设置为子对象,因此必须在其他touchesEnded:方法中检索它,您将需要执行以下操作: SKSpriteNode*angle=[self childNodeWithName:@“angle”]

当我定义“arrow.position=self.angle.position”时,Xcode不会将“angle”识别为精灵。非常感谢您的帮助。

变量超出范围。您正在将其设置为子对象,因此必须在其他touchesEnded:方法中检索它,您将需要执行以下操作:

SKSpriteNode*angle=[self childNodeWithName:@“angle”]