I have successfully implemented slider to my Cocos2D project using this resource.
The problem is that I make my game using pixel art so I usually use [sprite.texture setAliasTexParameters]; to make them look crisp. I just can’t figure out how to do it with this example code.
This is what the slider looks like now.
I create the slider like this:
self.musicSlider = [CCMenuItemSlider itemFromTrackImage: @"slider_bar.png" knobImage: @"slider_knob.png" target:self selector: @selector(onMusicSlide:)];
I believe here’s all the code you need to see from the mentioned example .m file:
+(id) itemFromTrackImage: (NSString*)value knobImage:(NSString*) value2 {
return [[[self alloc] initFromTrackImage:value knobImage:value2 target:nil selector:nil] autorelease];
}
+(id) itemFromTrackImage: (NSString*)value knobImage:(NSString*) value2 target:(id) t selector:(SEL) s {
return [[[self alloc] initFromTrackImage:value knobImage:value2 target: t selector: s] autorelease];
}
-(id) initFromTrackImage: (NSString *)trkImage
knobImage: (NSString *)knbImage
target: (id)target
selector: (SEL)selector
{
if( (self=[super initWithTarget:target selector:selector]) ) {
self.trackImage = [CCSprite spriteWithFile: trkImage];
self.knobImage = [CCSprite spriteWithFile: knbImage];
// Content size of the track is our reference
// Knob must lie within
[self setContentSize: trackImage_.contentSize];
[self addChild: knobImage_ z:2];
isVertical = (self.contentSize.height > self.contentSize.width);
self.minValue = 0.0f;
self.maxValue = 100.0f;
self.value = 50.0f;
}
return self;
}
The sprite is declared CCNode<CCRGBAProtocol> in the .h file and I can’t put .texture behind that.
Thank you very much in advance for all the help and please ask, if you need some more specifications.
I got it working by changing the code so it uses sprite sheet and not single images.
I changed this:
To this:
I thought I tried this yesterday before asking, but I guess I was too tired and did some stupid mistake.