Hi,
I'm trying to figure out why when i change my sprite's texture the old one appears in the lower left corner.
Can't get rid of it.
Thanks in advance
A fast, easy to use, free, and community supported 2D game engine
Hi,
I'm trying to figure out why when i change my sprite's texture the old one appears in the lower left corner.
Can't get rid of it.
Thanks in advance
because you dont remove it from the layer / spritesheer probably
Thanks.
How do i remove that???
I tried releasing the texture but it crashes.
[sprite.parent removeChild:sprite];
something like this
That removes the sprite from screen.
I just want to switch the sprite texture but can't seem to get rid of the original one.
HELP!
are you using spritesheet or separe images for the sprites ?
well, you probably use separate images
for that I used animations...
Id recommend you to just look into the code samples (sprite test)
I use normal Sprites.
Have not used SpriteSheet
Here is sample code for changing the texture:
Texture2D *texture = [[Texture2D alloc] initWithImage:[UIImage imageNamed:file]];
[powerBlock setTexture:texture];
I searched all sprite test example but there is nothing about changing textures.
Is the only way of changing the sprite's texture by removing and adding another child???
no. we have used Animation in 0.7.0 and it should also be working in newer releases
here is the code we used, bear in mind it's from 0.7 so you might have to make sme modifications:
// create animation
Animation * someAnim = [Animation animationWithName:@"anim_name" delay:0.0 images:@"image1.png",@"image2.png", nil];
// create sprite
Sprite * spr = [Sprite spriteWithFile:@"image1.png"];
[spr addAnimation:someAnim];
[spr setDisplayFrame: @"anim_name" index:1];
that should switch the image to image2.png
You must log in to post.