开发者

Moving Sprits location with location issue

开发者 https://www.devze.com 2023-03-03 09:19 出处:网络
When i move my layer that\'s contain all sprits by scrolling, sprits loc开发者_开发知识库ation does\'t change.i want\'s to change my sprits location with scrolling. please give me some solution for th

When i move my layer that's contain all sprits by scrolling, sprits loc开发者_开发知识库ation does't change.i want's to change my sprits location with scrolling. please give me some solution for this.

Thanks in Advance......


// simple position update
CGPoint a = [[CCDirector sharedDirector] convertToGL:[touch previousLocationInView:touch.view]];
CGPoint b = [[CCDirector sharedDirector] convertToGL:[touch locationInView:touch.view]];
CGPoint nowPosition = scrollLayer.position;
nowPosition.y += ( b.y - a.y );
nowPosition.y = MAX( 0, nowPosition.y );
nowPosition.y = MIN(20, nowPosition.y);
scrollLayer.position = nowPosition;

My scrollLayer contain all the sprits. This is the code by which my layer moves to a new location. All sprits also move with the layer but their position does not change with respect to the layer moving. When i touch on that possition the sprits move. But I want to touch on sprits for moving them.


if you move a layer without moving its child sprites, the sprite.position will return the same value even after moving the layer because its returning it relative to node space (layer). To get the position of the sprite according to the world or your scene you need to convert it to world space:

CGPoint worldPosition  = [self convertToWorldSpace:sprite.position];

i hope this answers your question because it wasnt very clear.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号