First, postion
The postion here is the same as the Layer.postion in app development, and the value of postion represents the relative position of the view in the parent node, such as an attempted parent node that is Self.view. Here we want to make this attempt to center in Self.view, then Layer.postion=cgpointmake (self.view.frame.size.widht/2,self.view.frame.size.height /2) ... Coordinates are the standard two-dimensional coordinate system, X is reduced, position is shifted to the left, X increases like right shift, Y increases like move up, y decreases like move down, and center point is the coordinate origin. This property is typically used when using animations in app development.
First, Anchor Point
The value range of the anchor point is (0,0.5,1) The default anchor point of the attempt is: (0.5,0.5), anchor I understand it as an attempt to repeat the same action in a range of support points, below I say something.
Here is a view can take the anchor point value, originally wanted to pass a recorded video, the image of the description of this thing, but TMD found not to transmit video, to a detailed address, to understand themselves to see.
Http://jingyan.baidu.com/album/9f63fb918fa9ddc8400f0ec5.html?picindex=4
Third, scrolling scene background map
On the implementation of the scrolling scene of the background of the method of scrolling many, here is just my own way, you may have a better, first scrolling background to want to connect seamlessly, it must be the art of the figure is done, here I use three sprite nodes as the background, when each sprite node postion y beyond the top of the screen, Assign the postion of the last added background node to it, and paste the code below.
1 #import "GameScene.h"2 @implementationGamescene3 4 {5 //Scene background node Sprite holds array6Nsmutablearray *Nearbyarray;7 8 }9 Ten /*method of initializing the scene, the method that is called when Uiviwecontroller initializes the scene*/ One-(Instancetype) Initwithsize: (cgsize) Size A { - if(self =[Super Initwithsize:size]) { - thenearbyarray=[[Nsmutablearray alloc]init]; - /*first scene background node*/ -UIImage *fartextureimage=[uiimage imagenamed:@"Planeback"]; -Sktexture *fartexture =[Sktexture texturewithimage:fartextureimage]; + -Skspritenode *fartexturespriteone =[Skspritenode spritenodewithtexture:fartexture size:self.size]; + //Fartexturespriteone.anchorpoint=cgpointmake (DEVICE_WIDTH/2, DEVICE_HEIGHT/2); Afartexturespriteone.zposition=0; atFartexturespriteone.position=cgpointmake (self.frame.size.width/2, self.frame.size.height/2 ); - - - - - /*second scene background node*/ inUIImage *fartextureimagetwo=[uiimage imagenamed:@"Planeback"]; -Sktexture *fartexturetwo =[Sktexture texturewithimage:fartextureimagetwo]; toSkspritenode *fartexturespritetwo =[Skspritenode spritenodewithtexture:fartexturetwo size:self.size]; + //fartexturespritetwo.anchorpoint=cgpointmake (0, 0); -fartexturespritetwo.zposition=0; theFartexturespritetwo.position=cgpointmake (fartexturespriteone.position.x,-(self.frame.size.height/2-Ten)); * $ Panax Notoginseng - /*A third scene background node*/ theUIImage *fartextureimagethree=[uiimage imagenamed:@"Planeback"]; +Sktexture *fartexturethree =[Sktexture Texturewithimage:fartextureimagethree]; A theSkspritenode *fartexturespritethree =[Skspritenode spritenodewithtexture:fartexturethree size:self.size]; + -fartexturespritethree.zposition=0; $Fartexturespritethree.position=cgpointmake (fartexturespriteone.position.x,-(self.frame.size.height/2+self.frame.size.height- -)); $ - - the - [self addchild:fartexturespriteone];Wuyi [self addchild:fartexturespritetwo]; the [self addchild:fartexturespritethree]; - Wu /*add three scene background nodes to an array, wait for it to scroll, then get each node quickly, reset postion*/ - [Nearbyarray Addobject:fartexturespriteone]; About [Nearbyarray addobject:fartexturespritetwo]; $ [Nearbyarray Addobject:fartexturespritethree]; - - - } A returnSelf ; + the } - $ /*How to set the background picture to scroll*/ the-(void) Backmove: (cgfloat) Movespeed the { the the for(intI=0; i<nearbyarray.count; i++) { -Skspritenode *tempsprite=[Nearbyarray objectatindex:i]; in the the[Tempsprite Setposition:cgpointmake (tempsprite.position.x,tempsprite.position.y+movespeed)]; About } the the //cyclic scrolling algorithm theSkspritenode *rollonesprite=[nearbyarray Objectatindex:0]; +Skspritenode *rolltwosprite=[nearbyarray Objectatindex:1]; -Skspritenode *threebacksprit=[nearbyarray Objectatindex:2]; the Bayi if(Rollonesprite.position.y> (self.frame.size.height/2+self.frame.size.height)) the { theRollonesprite.position=cgpointmake (rollonesprite.position.x,-(self.frame.size.height/2+self.frame.size.height- -)); - - } the if(Rolltwosprite.position.y> (self.frame.size.height/2+self.frame.size.height)) { theRolltwosprite.position=cgpointmake (rollonesprite.position.x,-(self.frame.size.height/2+self.frame.size.height- -)); the the } - if(Threebacksprit.position.y> (self.frame.size.height/2+self.frame.size.height)) { theThreebacksprit.position=cgpointmake (rollonesprite.position.x,-(self.frame.size.height/2+self.frame.size.height- -)); the the }94 } the the /*This method is Spritekit with the scene, and is called every second .*/ the-(void) Update: (cftimeinterval) currenttime {98[Self Backmove:2]; About - 101 }102 103 @end
Uiviewcontroller Call
1- (void) Viewdidload2 {3 [Super Viewdidload];4 5 //Configure the view.6Skview * Skview = (Skview *) Self.view;7Skview.showsfps =YES;8Skview.showsnodecount =YES;9 /*Sprite Kit applies additional optimizations to improve rendering performance*/TenSkview.ignoressiblingorder =YES; One A -Gamescene *scene =[[Gamescene alloc]initwithsize:skview.bounds.size]; - theScene.scalemode =Skscenescalemodeaspectfill; - - [Skview Presentscene:scene]; - +}
IOS 2D Game Development Framework spritekit--> (postion, Anchor Point, game scrolling scene)