Let’s say we have a CCSprite object that has an actions tied to it:
-(void) moveJack
{
CCSpriteSheet *sheet = (CCSpriteSheet*)[self getChildByTag:kSheet];
CCSprite *jack = (CCSprite*)[sheet getChildByTag:kJack];
...
CCSequence *seq = [CCSequence actions: jump1, [jump1 reverse], jump2, nil];
[jack runAction:seq];
}
If the sprite crosses over the screen boundary, I would like to display it at opposite side.
So, original sprite is half displayed on the right side (for example), and half on the left side, because it has not fully crossed yet.
Obviously (or is it), I need 2 sprites to achieve this.
One on the right side (original), and one on the left side (a copy).
The problem is – I don’t know how to create exact copy of the original sprite, because tied actions have scaling and blending transformations (sprite is a bit distorted due to a transformations).
I would like to have something like:
CCSprite *copy = [[jack copy] autorelease];
so that I can add an exact copy to display it on the correct side (and kill it after transition is over).
It should be a bitmap with all transformations applied… Is it possible?
Any ideas?
I’ve solved the problem a while ago – just noticed that the question is still unanswered:
We need a
makeDoublerfunction that will copy current frame displayed in one sprite to another. I have implemented it as a member function of a class that inherits fromCCSprite, and it looks somewhat like the following.In header
in implementation
You can use it like:
and in the game loop (also adjust visibility and coordinates):
I don’t use blending and alpha-ing in this case, but you can easily extend the
makeDoublerfunction.