0
votes

I have 2 points A and B. The distance is 100 and my sprite image is 50. My question is can I resize the sprite from the center of the image in order to keep the quality and if its possible how can I do that? I tried with this code, but it just scale the image width and look awful.

-(void)resizeSprite:(CCSprite*)sprite toWidth:(float)width toHeight:(float)height {
sprite.scaleX = width / sprite.contentSize.width;
sprite.scaleY = height / sprite.contentSize.height;
1
What do you mean by "keep the quality"? Any amount of image scaling will affect quality. If you scale (ie resize) an image to a smaller size, fewer pixels of the image will remain to be displayed. If you want a higher quality downscale, you can use an image program like Seashore or texturepacker in order to apply a scaling algorithm with filtering (linear or bicubic) which may give slightly better results. - LearnCocos2D
For example, if you have an image with 50px width and distance between two points 100, can you add twice the image to the same sprite. - Viktor Todorov
You can add two sprites. - LearnCocos2D

1 Answers

0
votes

Not sure if this is what you're after - but if you just want to scale the sprite to twice the size without artefacts you can use linear filtering on the sprite texture

[sprite.texture setAliasTexParameters];

Then just scale it to whatever you like

[sprite setScale: 2.f];