Since I need more than 1 spritesheet for my sprites, I'm trying to swap the texture for the AtlasSpriteManager that the sprite uses. However as noobish as this might sound I have no idea how to do this. The class member "mAtlas" in the AtlasSpriteManager class seems to be the pointer to the texture itself, but there are no setter available to change it. So I think I must be going the wrong way. Any advice?
How do you change the texture in atlasManager?
(14 posts) (3 voices)-
Posted 2 years ago #
-
[sprite setDisplayFrame: frame]or
[sprite setTextureRect: rect]where sprite is an instance of AtlasSprite.
The the AtlasTest example for more info.Posted 2 years ago # -
Thanks for the reply, but aren't you just changing the frame of the same spritesheet?
Posted 2 years ago # -
Btw I have also looked in AtlasTest and AtlasSpriteTest, but I can't find any code snippet that changes the texture of an AtlasSpriteManager instance.
Posted 2 years ago # -
Sorry, I misundertood the question.
In v0.8 (available from trunk) you can change the texture from the the AtlasSpriteManager using:
[manager setTexture:newTexture]Posted 2 years ago # -
hmm, is there anyway to do this in 0.7.1? I tried updating my cocos2d library but it didn't work that well...
Posted 2 years ago # -
No, but you can set the texture property as readwrite,retain and it should work.
Posted 2 years ago # -
I updated to v0.8 and tried using setTexture like below, but I'm getting a blank white texture instead. What am I missing?
mgr = [[mySpriteManager alloc] initWithFile:@"oa01.png" capacity:2 width:120 height:120];
Texture2D *newImg = [[Texture2D alloc] initWithImage:[UIImage imageWithContentsOfFile: @"oa02.png" ]];
[mgr setTexture:newImg];Posted 2 years ago # -
Does oa01.png and oa02.png have the same size ? the same coordinates for the sprite ?
Posted 2 years ago # -
no, they are of different sizes and have different coordinates for the sprite, but after I called setTexture, I have redefined the coordinate as below:
[atlasSprite spriteWithRect:CGRectMake(0, 0, 32, 32) spriteManager:mgr ];
as you can see, sprite size is 120x120 for oa01.png and 32x32 for oa2.png.
Are you suggesting that only textures with identical size and sprite coordinate/size can be used with a single atlasSpriteManager?
Sorry to be hammering you with noobish questions when you're busy sorting out stuff for this new group!
Posted 2 years ago # -
Has anyone use [AtlasSpriteManager setTexture] with any success? If so could you please give me some pointers?
Posted 2 years ago # -
it's working ok for me.
I've just added a test in r1021. See AtlasSpriteTest.m.Posted 2 years ago # -
Thanks a lot for the example Riq! I finally got it to work by loading the Texture using sharedTextureMgr instead of loading it directly per above.
Posted 2 years ago # -
Hi
I am using this way to change the texture of my AtlasManager, it works perfectly.
I have a problem :
I want to make a user to choose the Texture 2D, so I use a UIImagePickerController to get a png file.
If i put the file in my resources, it works perfectly, if i take exactly the same file with the UIImagePicker, it doesn't work ...
Have you got an idea?Posted 2 years ago #
Reply
You must log in to post.