Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:19:44+00:00 2026-05-28T08:19:44+00:00

I am trying to have a CCSprite be the album artwork sprite for when

  • 0

I am trying to have a CCSprite be the album artwork sprite for when my iPod music plays but the problem is, when I change the image from the NoImage.png to the actual album artwork, the CCSprite seems to change size and the image is smaller than the CCSprite originally was. I honestly cannot see why this is happening but maybe someone else will!

Anyway here is how I create the CCSprite in the init method,

albumArtwork = [[[CCSprite alloc] initWithFile:@"NoImage.png"] autorelease];
        [albumArtwork setScaleX:159 / albumArtwork.contentSize.width];
        [albumArtwork setScaleY:139 / albumArtwork.contentSize.height];
        albumArtwork.position = ccp(320/2, 190);
        [self addChild:albumArtwork z:26];

Then when the iPod music starts I do this to change the CCSprite image from the NoImage.png to the iPod song artwork:

UIImage *albumArtworkImage = NULL;
    MPMediaItemArtwork *itemArtwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
    if (itemArtwork != nil) {
        albumArtworkImage = [itemArtwork imageWithSize:CGSizeMake(albumArtwork.contentSize.width, albumArtwork.contentSize.width)];
    }

    if (albumArtworkImage) {
        CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addCGImage:albumArtworkImage.CGImage forKey:@"albumArtwork"];
        [albumArtwork setTexture: tex];
    } else { // no album artwork
        CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:@"NoImage.png"];
        [albumArtwork setTexture:tex];
    }

Does anyone know why this is happening and if so, how could I fix it?

Edit2:
This is what I condensed it down to:

CCTexture2D *tex;
    MPMediaItemArtwork *itemArtwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
    if (itemArtwork) {
        UIImage *albumArtworkImage = NULL;
        UIImage *firstImage = [itemArtwork imageWithSize:CGSizeMake(159.0f, 139.0f)];
        albumArtworkImage = [firstImage resizedImage:CGSizeMake(albumArtwork.contentSize.width, albumArtwork.contentSize.height) interpolationQuality: kCGInterpolationHigh];
        albumArtworkImage = [albumArtworkImage roundedCornerImage:8 borderSize:4]; 
        tex = [[CCTextureCache sharedTextureCache] addCGImage:albumArtworkImage.CGImage forKey:@"albumArtwork"];
    } else { // no album artwork
        tex = [[CCTextureCache sharedTextureCache] addImage:@"NoImage.png"];
    }
    [albumArtwork setTexture:tex];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:19:45+00:00Added an answer on May 28, 2026 at 8:19 am
     if (albumArtworkImage) {
        CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addCGImage:albumArtworkImage.CGImage forKey:@"albumArtwork"];
        [albumArtwork setTexture: tex];
    } else { // no album artwork
        CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:@"NoImage.png"];
        [albumArtwork setTexture:tex];
    }
    // reset visual size after you set new texture:
    [albumArtwork setScaleX:159 / albumArtwork.contentSize.width];
    [albumArtwork setScaleY:139 / albumArtwork.contentSize.height];
    

    This means that your sprite always will be rendered with size 159×139 pixels independently of image size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to have the appearance of an image sliding from left to right continuously
I have trying to learn MVC4 Web API. I am running my project from
I'm trying to have images fade in with css3 once they're loaded. The problem
I have a problem trying to have a single onmouseover event fire in IE,
I'm trying to create a extended CCSprite class that can detect touches. I have
I have trying to install nhibernate according this tutorial, but it doesn't say where
Trying to have a different image show up on a mouseover event. Using the
I have an image I'm trying to use as a background in Android. The
I have a CCSprite called sprite that is a child of a CCLayer called
Afternoon, I am trying have an HTML file containing a frameset which contains two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.