views:

652

answers:

2

Is it possible to change just a portion of a Sprite's alpha in response to user interaction? A good example of what I mean is iFog or iSteam, where the user can wipe "steam" off the iPhone's screen. Swapping images out wouldn't be feasible due to the sheer number of possibilities where the user could touch and move...

For example, say you have a simple app that has a brick wall in the background that has graffiti on it, so there'd be two sprites, one of the brick wall, then one of the graffiti that has a higher z value than the brick wall. Then, based upon where the user touches (assuming their touch controls a sandblaster), some of the graffiti should be removed, but not all of it, which could be accomplished by changing the alpha value on a portion of the graffiti sprite. Is there any way to do this in cocos2d-iphone? Or, do I need to drop down into openGL, and if so, where would be a good place to start my search on how to accomplish this?

Ideally, I'd like to accomplish this on a cocos2d-iphone Sprite, but if it's not possible, where's the best place to start looking?

Thanks in advance, Ben

A: 

Hi Ben, I'm hitting with similar requirement. I want to overlay a layer on the background image and do some interesting stuff with gestures (similar to iSteam). Did you get success with the best approach to do so? Thanks in Advance, Amit

the.evangelist
Nope, sorry, I was never able to figure it out and kind of dropped the idea (for the moment anyway), if you have any thoughts, please let me know...
A: 

is this possible to change the alpha value of pixels of select the part of the image using iphone sdk

here is the code which i am using to erase the selected the part of the image but i am not able to revert the erase parth(like unerase) but when i am using change the value of alpha i think it's possible to change to alpha value.

UIGraphicsBeginImageContext(frontImage.frame.size);
    [frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaPremultipliedLast); //kCGImageAlphaPremultipliedLast);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 10, 10));



    CGContextStrokePath(UIGraphicsGetCurrentContext());
    frontImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

Kindly help me,

milanjansari
If you have a follow up question you should post it asa new question, not as an answer to this old question.More people will read it since old questions are not frequented very much.
sth