本文整理汇总了C#中cocos2d.CCTexture2D.initWithData方法的典型用法代码示例。如果您正苦于以下问题:C# CCTexture2D.initWithData方法的具体用法?C# CCTexture2D.initWithData怎么用?C# CCTexture2D.initWithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocos2d.CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D.initWithData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: initWithSize
public bool initWithSize(ccGridSize gridSize)
{
CCDirector pDirector = CCDirector.sharedDirector();
CCSize s = pDirector.winSizeInPixels;
ulong POTWide = ccNextPOT((uint)s.width);
ulong POTHigh = ccNextPOT((uint)s.height);
// we only use rgba8888
CCTexture2DPixelFormat format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888;
CCTexture2D pTexture = new CCTexture2D();
pTexture.initWithData(null, format, (uint)POTWide, (uint)POTHigh, s);
if (pTexture == null)
{
CCLog.Log("cocos2d: CCGrid: error creating texture");
return false;
}
initWithSize(gridSize, pTexture, false);
return true;
}
示例2: initWithWidthAndHeight
/// <summary>
/// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid
/// </summary>
/// <param name="w"></param>
/// <param name="h"></param>
/// <param name="eFormat"></param>
/// <returns></returns>
public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
{
// If the gles version is lower than GLES_VER_1_0,
// some extended gles functions can't be implemented, so return false directly.
if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0)
{
return false;
}
bool bRet = false;
do
{
w = (int)CCDirector.sharedDirector().ContentScaleFactor;
h = (int)CCDirector.sharedDirector().ContentScaleFactor;
//glGetIntegerv(0x8CA6, m_nOldFBO);
// textures must be power of two squared
uint powW = (uint)ccUtils.ccNextPOT(w);
uint powH = (uint)ccUtils.ccNextPOT(h);
var data = (int)(powW * powH * 4);
//CC_BREAK_IF(! data);
//memset(data, 0, (int)(powW * powH * 4));
//m_ePixelFormat = eFormat;
m_pTexture = new CCTexture2D();
//CC_BREAK_IF(! m_pTexture);
m_pTexture.initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, new CCSize((float)w, (float)h));
//free( data );
// generate FBO
//ccglGenFramebuffers(1, &m_uFBO);
//ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);
// associate texture with FBO
//ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);
// check if it worked (probably worth doing :) )
//GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
//if (status != CC_GL_FRAMEBUFFER_COMPLETE)
//{
// CCAssert(0, "Render Texture : Could not attach texture to framebuffer");
// CC_SAFE_DELETE(m_pTexture);
// break;
//}
m_pTexture.setAliasTexParameters();
m_pSprite = CCSprite.spriteWithTexture(m_pTexture);
//m_pTexture->release();
m_pSprite.scaleY = -1;
this.addChild(m_pSprite);
ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 };
m_pSprite.BlendFunc = tBlendFunc;
//ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
bRet = true;
} while (true);
return bRet;
}