Forum > C# > Image Alpha rendering Issue/ Bug.

Image Alpha rendering Issue/ Bug.

By Logan Posted 2012-03-20 11:59 Comments 11
Logan
  • Posts: 88

Hi Everyone,
This is a very strange problem i’m encountering. Problem is that transparent area of the image appears black. Now this is strange because I never had this issue till now. I have tried both CCSprite and CCTexture2D, result is same. This is what i did-

  1. created a new project using cocos template in Visual studio 2010 Express Edition for Windows Phone. I did not use openX live SDK.
  2. Created a new Scene class and a layer class.
  3. Created a CCSprite object using usual steps. and added it to layer class.
  4. Added layer to scene. and then run the scene in Appdelegate class.

I’m not sure what i’m doing wrong here as this has worked perfectly before. but now every new project i create has this problem.

Edit: default Hello world program works fine. even adding images to the default hello world class works but adding your own class like i did above doesn’t seem to work. Please help me with this.. i’m not sure what i’m doing wrong.

cheers,
Raghu S

1.png - Black area around the image is supposed to be transparent. and No problem is not with the image itself (48.1 kB)

huangrh
  • Posts: 171

#1 RE: 2012-03-30 01:52

maybe the m_sBlendFunc value is different in HelloWorld and the template?

Logan
  • Posts: 88

#2 RE: 2012-03-30 06:53

I’m not sure about that. How to check that?
well this might sound strange but this bug appears mostly when i delete the default HelloWorldScene.cs and create my own custom class (layer/scene). If I don’t delete that file and work as usual then things seem to work normally.

DaveAPixel
  • Posts: 14

#3 RE: 2012-03-31 14:53

I don’t think its a permanent solution but I found if I put app.GraphicsDevice.BlendState = BlendState.AlphaBlend in CCSprites draw() function then the alphas work on my sprites.

Dave

Logan
  • Posts: 88

#4 RE: 2012-04-01 10:29

Thanks That works, but its kind of strange since AlphaBlend is the default BlendState in XNA 4?!.

huangrh
  • Posts: 171

#5 RE: 2012-04-13 09:48

Hi, Raghu S , i have implemented the steps you wrote above, but everything seems ok,
I change the codes of the scene() in helloworld.cs as follows:

public static CCScene scene()
{
// ‘scene’ is an autorelease object
CCScene scene = CCScene.node();

// ‘layer’ is an autorelease object
CCLayer layer = CCLayer.node();

CCSprite spriteCat = CCSprite.spriteWithFile(“woman”);
CCSize size = CCDirector.sharedDirector().getWinSize();
spriteCat.position = new CCPoint(size.width / 2, size.height / 2);
layer.addChild(spriteCat, 0);

// add layer as a child to scene
scene.addChild(layer);

// return the scene
return scene;
}

and the test image attached here:

huangrh
  • Posts: 171

#6 RE: 2012-04-13 09:58

Hi, Raghu S, AlphaBlend is the default BlendState in the engine.
and I have tried the steps you wrote above, but everything seems ok,

I changed the codes of scene() in helloworld.cs as follows:

        public static CCScene scene()
        {
            // 'scene' is an autorelease object
            CCScene scene = CCScene.node();

            // 'layer' is an autorelease object
            CCLayer layer = CCLayer.node();

            CCSprite spriteCat = CCSprite.spriteWithFile("woman");
            CCSize size = CCDirector.sharedDirector().getWinSize();
            spriteCat.position = new CCPoint(size.width / 2, size.height / 2);
            layer.addChild(spriteCat, 0);

            // add layer as a child to scene
            scene.addChild(layer);

            // return the scene
            return scene;
        }

and the test image attached here:

Logan
  • Posts: 88

#7 RE: 2012-04-13 11:30

hi RongHong Huang, Thanks for the reply. The method you followed is exactly how the hello world program is( creating a scene within a layer and adding layer to the scene method). Well following that method works but that’s not what i did. These is what i did-

class SampleScene : CCScene
{
  public SampleScene ()
  {
    SampleLayer sampleLayer = new SampleLayer();
    this.addChild(sampleLayer);
  }
}

class SampleLayer : CCLayer
{
  public SampleLayer()
  {
    CCSprite spriteCat = CCSprite.spriteWithFile("cat");
    CCSize size = CCDirector.sharedDirector().getWinSize();
    spriteCat.position = new CCPoint(size.width / 2, size.height / 2);
    this.addChild(spriteCat);
  }
}

then in appDelegate class i added the following-

SampleScene myScene= new SampleScene ();
pDirector.runWithScene(myScene);

Note: I also deleted the default HelloWorldScene Class which comes with the template. This is when the problem really started to appear.(!)

Also solution given above by Dave Allanson seems to work for both this issue and the Sprite opacity issue which i mentioned in my other post here - [[http://www.cocos2d-x.org/boards/17/topics/9313]].
Dev’s please look into this..

huangrh
  • Posts: 171

#8 RE: 2012-04-16 08:19

Sorry, I couldn’t help you.
I couldn’t reproduce the bug, whenever I comment the helloworld code or directly delete the helloworld.cs file.

pekayatt
  • Posts: 151
  • Location: Brazil

#9 RE: 2012-05-09 18:09

Just started to work with COCOS2d for XNA and I am having the same problem.

I have used the template to start a new project and when using sprites linked to a png with transparence the area that should be with alpha 0 is black.

Am I doing something wrong?

class SampleScene : CCScene
{
public SampleScene()
{
SampleLayer sampleLayer = new SampleLayer();
this.addChild(sampleLayer);
}
}
>
class SampleLayer : CCLayer
{
public SampleLayer()
{
CCSprite spriteCat = CCSprite.spriteWithFile(“images/notext_play”);
>
CCSprite testSprite = CCSprite.spriteWithFile(“images/new_MENU”);
>
CCSize size = CCDirector.sharedDirector().getWinSize();
spriteCat.position = new CCPoint(size.width / 2, size.height / 2);
this.addChild(spriteCat);
this.addChild(testSprite, 1);
}
}

I used this SampleScene to test just it.

PS: cocos2d-x for xna 0.1.1 Apr.20 2012

Co-Founder and CEO @ http://www.nakedmonkey.mobi

Our Games: Harlem Shake [ "iOS":http://bit.ly/hSiPhone | "Android":http://bit.ly/harlemShakeGame ] / jump Monkey [ "WP7":http://bit.ly/jumpMonkey | "Android":http://bit.ly/jumpMonkeyAndroid | "iOS":http://itunes.apple.com/us/app/id653510897 ]
Our Apps: Series Notifier [ "WP7":http://bit.ly/seriesNotifier ]

pekayatt
  • Posts: 151
  • Location: Brazil

#10 RE: 2012-05-09 19:33

Forget about it guys!
I have just started a new project and now everything works fine.
Still need to understand what has happened before!

Co-Founder and CEO @ http://www.nakedmonkey.mobi

Our Games: Harlem Shake [ "iOS":http://bit.ly/hSiPhone | "Android":http://bit.ly/harlemShakeGame ] / jump Monkey [ "WP7":http://bit.ly/jumpMonkey | "Android":http://bit.ly/jumpMonkeyAndroid | "iOS":http://itunes.apple.com/us/app/id653510897 ]
Our Apps: Series Notifier [ "WP7":http://bit.ly/seriesNotifier ]

pekayatt
  • Posts: 151
  • Location: Brazil

#11 RE: 2012-05-10 22:40

Found that the error is related to the CCLabelTTF…

If you remove it from the Scene all the PNG images loses it’s transparence.

Do not know why yet…

Co-Founder and CEO @ http://www.nakedmonkey.mobi

Our Games: Harlem Shake [ "iOS":http://bit.ly/hSiPhone | "Android":http://bit.ly/harlemShakeGame ] / jump Monkey [ "WP7":http://bit.ly/jumpMonkey | "Android":http://bit.ly/jumpMonkeyAndroid | "iOS":http://itunes.apple.com/us/app/id653510897 ]
Our Apps: Series Notifier [ "WP7":http://bit.ly/seriesNotifier ]

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps