我目前正在一个平台跳投应用程序工作,但我是一个十足的笨蛋。总之,我在网上找到了一个教程,并开始调整代码。
我现在的问题是:我创建了一个静态映像的SpriteKitNode。我想要覆盖它运行(跳跃/攻击)动画。所以我想我可以把Atlastexture坐标设置为SpriteNode坐标。它甚至可以工作(目前没有动画)。但是当我开始移动MapchildNode (静态图像)时,我自己的纹理就会移出屏幕,因为地图开始对静态节点进行居中。我试图将我的纹理设置为与每个帧的节点相同的坐标,甚至控制台显示的坐标也是相同的。但尽管如此,纹理还是会远离节点。
就像我说的,我是个十足的菜鸟。所以请容忍我,如果我现在显示错误的代码行..
@implementation GameLevelScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
[[SKTAudio sharedInstance] playBackgroundMusic:@"sim.mp3"];
self.backgroundColor = [SKColor colorWithRed:.4 green:.4 blue:.95 alpha:1.0];
self.map = [JSTileMap mapNamed:@"nun.tmx"];
[self addChild:self.map];
self.walls = [self.map layerNamed:@"walls"];
self.hazards = [self.map layerNamed:@"hazards"];
self.player = [[Player alloc] initWithImageNamed:@"koalio_stand"];
self.player.position = CGPointMake(100, 80);
self.player.zPosition = 15;
[self.map addChild:self.player];
// NOW THE ANIMATION
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"noel"];
SKTexture *f1 = [atlas textureNamed:@"noel1.png"];
SKTexture *f2 = [atlas textureNamed:@"noel2.png"];
SKTexture *f3 = [atlas textureNamed:@"noel3.png"];
SKTexture *f4 = [atlas textureNamed:@"noel4.png"];
SKTexture *f5 = [atlas textureNamed:@"noel5.png"];
SKTexture *f6 = [atlas textureNamed:@"noel6.png"];
SKTexture *f7 = [atlas textureNamed:@"noel7.png"];
self.noel = [SKSpriteNode spriteNodeWithTexture:f1];
[self addChild:self.noel];
NSArray *noelRunning = @[f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1, f2, f3, f4, f5, f6, f7, f6, f5, f4, f3, f2, f1];
// LEARN TO LOOP!?
self.running = [SKAction animateWithTextures:noelRunning timePerFrame:0.03];
// END OF ANIMATION
self.userInteractionEnabled = YES;
}
return self;
}静态图像是“koalio-站立. The”
接下来是更新方法:
- (void)update:(NSTimeInterval)currentTime
{
if (self.gameOver) return;
NSTimeInterval delta = currentTime - self.previousUpdateTime;
if (delta > 0.02) {
delta = 0.02;
}
self.previousUpdateTime = currentTime;
[self.player update:delta];
//[self.noel runAction:self.running];
[self checkForAndResolveCollisionsForPlayer:self.player forLayer:self.walls];
[self handleHazardCollisions:self.player];
[self checkForWin];
[self setViewpointCenter:self.player.position];
}还有一个大麻烦制造者..?这种方法以视图为中心,当视图居中时,静态图像和我的纹理都是分开的(静态图像位于中间,纹理移出屏幕)。但是控制台显示为具有相同的坐标。我使用了>> self.player.position = self.noel.position <<
- (void)setViewpointCenter:(CGPoint)position {
NSInteger x = MAX(position.x, self.size.width / 2);
NSInteger y = MAX(position.y, self.size.height / 2);
x = MIN(x, (self.map.mapSize.width * self.map.tileSize.width) - self.size.width / 2);
y = MIN(y, (self.map.mapSize.height * self.map.tileSize.height) - self.size.height / 2);
CGPoint actualPosition = CGPointMake(x, y);
CGPoint centerOfView = CGPointMake(self.size.width/2, self.size.height/2);
CGPoint viewPoint = CGPointSubtract(centerOfView, actualPosition);
self.map.position = viewPoint;
self.noel.position = self.player.position;}
我请求你的帮助
发布于 2014-06-18 14:39:09
我不清楚你想要表达什么,但是如果你的问题是为什么player和noel对象在分配相同的位置时会迁移到不同的位置?答案是你的变量player和noel是不同父母的孩子,player是self.map的孩子,noel是self的孩子。
节点的位置相对于他的父母框架。
https://stackoverflow.com/questions/24288177
复制相似问题