-
废话不多说,直接看效果。做的不是很好,但是应付考试足够了。
动画.gif
下面是源代码
@interface GameScene()
@property (nonatomic, strong) SKSpriteNode *sprite;
@property (nonatomic, strong) SKSpriteNode *sprite1;
@end
//创建背景
SKSpriteNode *bjNode = [SKSpriteNode spriteNodeWithImageNamed:@"背景"];
bjNode.position = CGPointZero;
bjNode.anchorPoint = CGPointZero;
bjNode.size = self.size;
bjNode.zPosition = 0;
[self addChild:bjNode];
//创建地板
SKSpriteNode *dbNode = [SKSpriteNode spriteNodeWithImageNamed:@"地板"];
dbNode.size = CGSizeMake(800.0, 30.0);
//dbNode.anchorPoint = CGPointZero;
dbNode.position = CGPointMake(0,CGRectGetMidY(self.frame)-95);
//dbNode.size = CGSizeMake(50, CGRectGetMaxY(self.frame));
dbNode.zPosition = 14;
[self addChild: dbNode];
//创建云
SKSpriteNode *yunNode1 = [SKSpriteNode spriteNodeWithImageNamed:@"云"];
yunNode1.size = CGSizeMake(50, 40);
yunNode1.position = CGPointMake(100, CGRectGetMidY(self.frame)+80);
yunNode1.zPosition = 2;
[self addChild:yunNode1];
SKSpriteNode *yunNode2 = [SKSpriteNode spriteNodeWithImageNamed:@"云"];
yunNode2.size = CGSizeMake(50, 40);
yunNode2.position = CGPointMake(200, CGRectGetMidY(self.frame)+60);
yunNode2.zPosition = 2;
[self addChild:yunNode2];
SKSpriteNode *yunNode3 = [SKSpriteNode spriteNodeWithImageNamed:@"云"];
yunNode3.size = CGSizeMake(50, 40);
yunNode3.position = CGPointMake(215, CGRectGetMidY(self.frame)+60);
yunNode3.zPosition = 3;
[self addChild:yunNode3];
SKSpriteNode *yunNode4 = [SKSpriteNode spriteNodeWithImageNamed:@"云"];
yunNode4.size = CGSizeMake(50, 40);
yunNode4.position = CGPointMake(230, CGRectGetMidY(self.frame)+60);
yunNode4.zPosition = 4;
[self addChild:yunNode4];
SKSpriteNode *yunNode5 = [SKSpriteNode spriteNodeWithImageNamed:@"云"];
yunNode5.size = CGSizeMake(50, 40);
yunNode5.position = CGPointMake(350, CGRectGetMidY(self.frame)+55);
yunNode5.zPosition = 5;
[self addChild:yunNode5];
//创建墙
SKSpriteNode *qNode1 = [SKSpriteNode spriteNodeWithImageNamed:@"墙"];
qNode1.size = CGSizeMake(20, 20);
qNode1.position = CGPointMake(50, CGRectGetMidY(self.frame)-20);
qNode1.zPosition = 6;
[self addChild:qNode1];
SKSpriteNode *qNode2 = [SKSpriteNode spriteNodeWithImageNamed:@"墙"];
qNode2.size = CGSizeMake(20, 20);
qNode2.position = CGPointMake(120, CGRectGetMidY(self.frame)-20);
qNode2.zPosition = 7;
[self addChild:qNode2];
SKSpriteNode *qNode3 = [SKSpriteNode spriteNodeWithImageNamed:@"问号"];
qNode3.size = CGSizeMake(20, 20);
qNode3.position = CGPointMake(140, CGRectGetMidY(self.frame)-20);
qNode3.zPosition = 8;
[self addChild:qNode3];
SKSpriteNode *qNode4 = [SKSpriteNode spriteNodeWithImageNamed:@"墙"];
qNode4.size = CGSizeMake(20, 20);
qNode4.position = CGPointMake(160, CGRectGetMidY(self.frame)-20);
qNode4.zPosition = 9;
[self addChild:qNode4];
SKSpriteNode *qNode5 = [SKSpriteNode spriteNodeWithImageNamed:@"问号"];
qNode5.size = CGSizeMake(20, 20);
qNode5.position = CGPointMake(180, CGRectGetMidY(self.frame)-20);
qNode3.zPosition = 10;
[self addChild:qNode5];
SKSpriteNode *qNode6 = [SKSpriteNode spriteNodeWithImageNamed:@"问号"];
qNode6.size = CGSizeMake(20, 20);
qNode6.position = CGPointMake(150, CGRectGetMidY(self.frame)+30);
qNode6.zPosition = 11;
[self addChild:qNode6];
SKSpriteNode *qNode7 = [SKSpriteNode spriteNodeWithImageNamed:@"墙"];
qNode7.size = CGSizeMake(20, 20);
qNode7.position = CGPointMake(240, CGRectGetMidY(self.frame)+10);
qNode7.zPosition = 12;
[self addChild:qNode7];
//创建蘑菇
SKSpriteNode *mgNode1 = [SKSpriteNode spriteNodeWithImageNamed:@"蘑菇1"];
mgNode1.size = CGSizeMake(17, 17);
mgNode1.position = CGPointMake(240, CGRectGetMidY(self.frame)+28);
mgNode1.zPosition = 13;
[self addChild:mgNode1];
//下水道
SKSpriteNode *xsdNode = [SKSpriteNode spriteNodeWithImageNamed:@"下水道"];
xsdNode.size = CGSizeMake(50, 50);
xsdNode.position = CGPointMake(340, CGRectGetMidY(self.frame)-65);
xsdNode.zPosition = 1;
[self addChild:xsdNode];
//树
SKSpriteNode *sNode = [SKSpriteNode spriteNodeWithImageNamed:@"树1"];
sNode.size = CGSizeMake(190,120);
sNode.position = CGPointMake(50, CGRectGetMidY(self.frame)-110);
sNode.zPosition = 1;
[self addChild:sNode];
SKSpriteNode *sNode1 = [SKSpriteNode spriteNodeWithImageNamed:@"树2"];
sNode1.size = CGSizeMake(40,100);
sNode1.position = CGPointMake(200, CGRectGetMidY(self.frame)-110);
sNode1.zPosition = 1;
[self addChild:sNode1];
//玛丽
SKSpriteNode *mlNode = [SKSpriteNode spriteNodeWithImageNamed:@"马力"];
mlNode.size = CGSizeMake(25, 25);
mlNode.position = CGPointMake(20, CGRectGetMidY(self.frame)-68);
mlNode.zPosition = 20;
[self addChild:mlNode];
self.sprite = mlNode;
//乌龟
SKSpriteNode *wgNode = [SKSpriteNode spriteNodeWithImageNamed:@"ww"];
wgNode.size = CGSizeMake(25, 25);
wgNode.position = CGPointMake(300, CGRectGetMidY(self.frame)-75);
wgNode.zPosition = 21;
[self addChild:wgNode];
self.sprite1 =wgNode;
//道
SKSpriteNode *xdNode = [SKSpriteNode spriteNodeWithImageNamed:@"道"];
xdNode.size = CGSizeMake(60, 20);
xdNode.position = CGPointMake(CGRectGetMaxX(self.frame)-15, CGRectGetMidY(self.frame)-10);
xdNode.zPosition = 14;
[self addChild:xdNode];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//方法一
CGPoint origin = self.sprite.position;
CGPoint origin1 = self.sprite1.position;
if (origin.x < self.frame.size.width - 50) {
self.sprite.position = CGPointMake(origin.x + 10, CGRectGetMidY(self.frame)-68);
self.sprite1.position = CGPointMake(origin1.x - 5, CGRectGetMidY(self.frame)-75);
}}
小道.png
白云.png
背景.png
道.png
地板.png
红旗.png
马力.png
玛丽.jpeg
蘑菇.png
蘑菇1.png
墙.png
树.png
树1.png
树2.png
桶 .png
问号.png
下水道.png
云.png
apple.png
u=1526224811,2167958216&fm=23&gp=0.jpg
ww.png
网友评论