Issue with shadows/Opacity on sprites in cocos2d (.png format) - cocos2d-iphone

I'm having trouble understanding why sprites with shadows (%opacity layer) looks different in ps and on screen. Here is the comparison:

This is simply because of image formate you set. I guess you set RGBA4444 in code or while exporting spriteSheet. Also remove checkmark Premultiply alpha in texture packer.
Also check in AppDelegate Class:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 //Guru - replaced kEAGLColorFormatRGB565 with kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

Related

How to replace previous image with new image in QGrapicsScene

In Constructor, using QGraphicScene I'm adding many widgets and one image using Qpixmap. when I want to replace only image. i'm able replace the image but these widgets are not coming ..`
QPixmap *bkgnd=new QPixmap(":/res/Clamp Down - Pedistal Down - Arm Retracted - Complete.jpg");
m_bkImgScene.addPixmap(*bkgnd);
m_bkImgScene.addItem(&m_txtForelinePsr);
m_txtForelinePsr.setPos(POS_FORELINEPSR);
m_bkImgScene.addItem(&m_txtMechPump);
m_txtMechPump.setPos(POS_MECHPUMP);
m_bkImgScene.addItem(&m_txtRoughLnPsr);
m_txtRoughLnPsr.setPos(POS_ROUGHLINEPSR);
m_bkImgScene.addItem(&m_txtHeBartn);
m_bkImgScene.addItem(&m_txtHeMfc);
m_bkImgScene.addItem(&m_txtIonGfb);
m_bkImgScene.addItem(&m_txtProBaratronfb);
m_txtProBaratronfb.setPos(POS_PROBARATRONFB);
m_bkImgScene.addItem(&m_txtChamberPsr);
m_mapTxtWxs[CHAMBERPRESSUREFEEDBACK] = &m_txtChamberPsr;
m_txtChamberPsr.setPos(POS_CHAMBERPSR);`
mypixmap->load("secondimage_path");
mylabel->setPixmap(mypixmap);

How could I skew/shear a sprite via SpriteKit like Cocos2D?

In Cocos2D-x, CCNode class provides "skewX" & "skewY" to let me do some distortion of the sprite, however, I fail to find similar mapping in SKNode of SpriteKit.
My game uses Flash to port skeleton animations, in which the configs of positioning, scaling, rotation and shearing of sprites would be decomposed into game-engine's digestive. Except shearing, all other configs do have solutions to be done in SpriteKit.
You can achieve a skew affect using a CGAffineTransform, CoreImage filter and an SKEffectNode
let transform = CGAffineTransform(a: 1, b: 0.1, c: -0.3, d: 1, tx: 0, ty: 0)
let transformValue = NSValue(cgAffineTransform: transform)
let transformFilter = CIFilter(name: "CIAffineTransform")!
transformFilter.setValue(transformValue, forKey: "inputTransform")
let effectNode = SKEffectNode()
effectNode.addChild(sprite) // <-- Add sprite to effect node
effectNode.filter = transformFilter
effectNode.shouldRasterize = true
effectNode.shouldEnableEffects = true
No you can't.
SKNode doesn't have skew* properties. And SKShader allows to use only fragment shader. It means you can change the color of each pixel whatever you want, but you can't change the shape of a sprite.
So I recommend you to use Cocos2d-Swift, Cocos2d-x or so on instead of SpriteKit.
Another option is UIView. You can use the matrix from Adobe Flash to UIView via CALayer transform.

Cocos2d - retina images not displaying

Simply trying to test retina display. I setup the director like this:
CCDirectorIOS* director = (CCDirectorIOS*)[CCDirector sharedDirector];
director.wantsFullScreenLayout = NO;
director.projection = kCCDirectorProjection2D;
director.animationInterval = 1.0 / 60.0;
director.displayStats = YES;
[director enableRetinaDisplay:YES];
I create two versions of the file in Photoshop - outline-hd.png and outline.png. I color the HD version red so I can tell if it's being displayed.
Display code:
CCSprite *border = [CCSprite spriteWithFile:#"outline.png"];
[self addChild:border];
Yet it is the non-hd image that gets displayed on my iPhone5. Why?
I came across this question while trying to solve the exact same problem in my own project. Had to dig around in the cocos2d source to figure it out. The problem is that the director's enableRetinaDisplay:YES method doesn't work unless the director's view is set. So, it needs to be called after the glView is set up, and you've called setView on the director:
CCGLView *glView = [CCGLView viewWithFrame:aFrame
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[[CCDirector sharedDirector] setView:glView];
NSLog(#"glView is set, enable retina...");
[[CCDirector sharedDirector] enableRetinaDisplay:YES];
This should fix the problem for you!
May be you forgot:
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];
[sharedFileUtils setiPhoneRetinaDisplaySuffix:#"-hd"];

Blending with Direct3D SpriteBatch

I'm trying to achieve a simple effect: drawing an image on the screen with a transparent background. I'm using SpriteBatches to do this.
Here is my code for creating the blend state:
D3D11_BLEND_DESC descBlend;
ZeroMemory(&descBlend, sizeof(descBlend));
descBlend.RenderTarget[0].BlendEnable = true;
descBlend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
descBlend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
descBlend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
descBlend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
descBlend.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
descBlend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
m_d3dDevice->CreateBlendState(&descBlend, &m_Blend);
I begin drawing my sprites with:
m_SpriteBatch->Begin(SpriteSortMode_BackToFront, m_Blend);
Nothing shows up on the screen! Am I missing something?
I'm sure my image is correct because when I draw with no blending enabled, everything shows up except the transparent parts become pure white.
Any help would be appreciated.
I was once trying to achieve something similar and wrote down what I did over at gamedev
You have to identify which components of each pixel of a render target are writable during blending.
descBlend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
With ZeroMemory(&descBlend, sizeof(descBlend)); your clear all fields of the D3D11_BLEND_DESC inclusive the RenderTargetWriteMask. This mask determines whether the channels are written or not, if it's zero nothing is written. Try to set it to D3D11_COLOR_WRITE_ENABLE_ALL.

Cocos2D 0.99.5 CCDirector pixel format?

I'm trying to set the pixel format in my CCDirector but i can't find the method.
It seems to me that my version of cocos2d doesn't have that method??
Strange
In your app delegate, look for this line:
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
or search for
EAGLView *glView
and you will find it..