grouping sprites and moving them?
i want to group my sprites that i call from an array, so that i can move them as a group. I was told to use cocosnode, but i'm pretty sure he meant ccnode. Here is my code so far:
sprites1 = (CCSprite *)[c1array objectAtIndex:0];
sprites2 = (CCSprite *)[c1array objectAtIndex:1];
sprites3 = (CCSprite *)[c1array objectAtIndex:2];
sprites4 = (CCSprite *)[c1array objectAtIndex:3];
sprites5 = (CCSprite *)[c1array objectAtIndex:4];
sprites6 = (CCSprite *)[c1array objectAtIndex:5];
sprites7 = (CCSprite *)[c1array objectAtIndex:6];
sprites8 = (CCSprite *)[c1array objectAtIndex:7];
column1 = [CCNode node];
[column1 addChild:sprites1];
[column1 addChild:sprites2];
[column1 addChild:sprites3];
[column1 addChild:sprites4];
column1.position = ccp(0,0);
[self addChild:column1];
column2 = [CCNode node];
[column2 addChild:sprites5];
[column2 addChild:sprites6];
[column2 addChild:sprites7];
[column2 addChild:sprites8];
column2.position = ccp(30,0);
[self addChild:column2];
//ccotouchmov开发者_Go百科ed code
column1.anchorPoint = ccp(touchLocation.x,touchLocation.y);
if (CGRectContainsPoint(c1,touchLocation)) {
touchLocation.x = column1.position.x;
column1.position = ccp(touchLocation.x,touchLocation.y);
}
how do I make the ccnode move smoothly. It jumps up a lot but I want a smooth transition up and down.
xxx
xxx
xxx
x are my sprites i am moving my x down and up as a whole column and need to be able to move my x as a whole row as well, and once it goes off the top of the screen i need it to reappear on the opposite side of the screen and vice versa same for left and right.
Possibly the reason it's crashed is that one of Sprite5, Sprite6, Sprite7, Sprite8 in nil
. And it's denied to add nil children to CCNode
.
In touchBegan method:
CGPoint touchLocation = ...;
CGPoint referencePoint = ccpSub(touchLocation, myNode.position);
//keep reference point somewhere
in TouchMoved method:
CGPoint touchLocation = ...;
myNode.position = ccpSub(touchLocation, referencePoint);
精彩评论