本文整理汇总了C#中Cocos2D.CCRect.PointsToPixels方法的典型用法代码示例。如果您正苦于以下问题:C# CCRect.PointsToPixels方法的具体用法?C# CCRect.PointsToPixels怎么用?C# CCRect.PointsToPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cocos2D.CCRect
的用法示例。
在下文中一共展示了CCRect.PointsToPixels方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitTexCoordsWithRect
// pointRect should be in Texture coordinates, not pixel coordinates
private void InitTexCoordsWithRect(CCRect pointRect)
{
// convert to Tex coords
var rect = pointRect.PointsToPixels();
float wide = pointRect.Size.Width;
float high = pointRect.Size.Height;
if (m_pTexture != null)
{
wide = m_pTexture.PixelsWide;
high = m_pTexture.PixelsHigh;
}
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
float left = (rect.origin.x*2+1) / (wide*2);
float bottom = (rect.origin.y*2+1) / (high*2);
float right = left + (rect.size.width*2-2) / (wide*2);
float top = bottom + (rect.size.height*2-2) / (high*2);
#else
float left = rect.Origin.X / wide;
float bottom = rect.Origin.Y / high;
float right = left + rect.Size.Width / wide;
float top = bottom + rect.Size.Height / high;
#endif
// ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
// Important. Texture in cocos2d are inverted, so the Y component should be inverted
float tmp = top;
top = bottom;
bottom = tmp;
CCV3F_C4B_T2F_Quad[] quads;
int start, end;
if (m_pBatchNode != null)
{
quads = m_pBatchNode.TextureAtlas.m_pQuads.Elements;
m_pBatchNode.TextureAtlas.Dirty = true;
start = m_uAtlasIndex;
end = m_uAtlasIndex + m_uTotalParticles;
}
else
{
quads = m_pQuads.Elements;
start = 0;
end = m_uTotalParticles;
}
for (int i = start; i < end; i++)
{
// bottom-left vertex:
quads[i].BottomLeft.TexCoords.U = left;
quads[i].BottomLeft.TexCoords.V = bottom;
// bottom-right vertex:
quads[i].BottomRight.TexCoords.U = right;
quads[i].BottomRight.TexCoords.V = bottom;
// top-left vertex:
quads[i].TopLeft.TexCoords.U = left;
quads[i].TopLeft.TexCoords.V = top;
// top-right vertex:
quads[i].TopRight.TexCoords.U = right;
quads[i].TopRight.TexCoords.V = top;
}
}
示例2: SetTextureCoords
private void SetTextureCoords(CCRect rect)
{
rect = rect.PointsToPixels();
CCTexture2D tex = m_pobBatchNode != null ? m_pobTextureAtlas.Texture : m_pobTexture;
if (tex == null)
{
return;
}
float atlasWidth = tex.PixelsWide;
float atlasHeight = tex.PixelsHigh;
float left, right, top, bottom;
if (m_bRectRotated)
{
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
left = (2 * rect.Origin.X + 1) / (2 * atlasWidth);
right = left + (rect.Size.Height * 2 - 2) / (2 * atlasWidth);
top = (2 * rect.Origin.Y + 1) / (2 * atlasHeight);
bottom = top + (rect.Size.Width * 2 - 2) / (2 * atlasHeight);
#else
left = rect.Origin.X / atlasWidth;
right = (rect.Origin.X + rect.Size.Height) / atlasWidth;
top = rect.Origin.Y / atlasHeight;
bottom = (rect.Origin.Y + rect.Size.Width) / atlasHeight;
#endif
if (m_bFlipX)
{
CCMacros.CCSwap(ref top, ref bottom);
}
if (m_bFlipY)
{
CCMacros.CCSwap(ref left, ref right);
}
m_sQuad.BottomLeft.TexCoords.U = left;
m_sQuad.BottomLeft.TexCoords.V = top;
m_sQuad.BottomRight.TexCoords.U = left;
m_sQuad.BottomRight.TexCoords.V = bottom;
m_sQuad.TopLeft.TexCoords.U = right;
m_sQuad.TopLeft.TexCoords.V = top;
m_sQuad.TopRight.TexCoords.U = right;
m_sQuad.TopRight.TexCoords.V = bottom;
}
else
{
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
left = (2 * rect.Origin.X + 1) / (2 * atlasWidth);
right = left + (rect.Size.Width * 2 - 2) / (2 * atlasWidth);
top = (2 * rect.Origin.Y + 1) / (2 * atlasHeight);
bottom = top + (rect.Size.Height * 2 - 2) / (2 * atlasHeight);
#else
left = rect.Origin.X / atlasWidth;
right = (rect.Origin.X + rect.Size.Width) / atlasWidth;
top = rect.Origin.Y / atlasHeight;
bottom = (rect.Origin.Y + rect.Size.Height) / atlasHeight;
#endif
if (m_bFlipX)
{
CCMacros.CCSwap(ref left, ref right);
}
if (m_bFlipY)
{
CCMacros.CCSwap(ref top, ref bottom);
}
m_sQuad.BottomLeft.TexCoords.U = left;
m_sQuad.BottomLeft.TexCoords.V = bottom;
m_sQuad.BottomRight.TexCoords.U = right;
m_sQuad.BottomRight.TexCoords.V = bottom;
m_sQuad.TopLeft.TexCoords.U = left;
m_sQuad.TopLeft.TexCoords.V = top;
m_sQuad.TopRight.TexCoords.U = right;
m_sQuad.TopRight.TexCoords.V = top;
}
}
示例3: InitWithTexture
protected virtual bool InitWithTexture(CCTexture2D pobTexture, CCRect rect)
{
CCRect rectInPixels = rect.PointsToPixels();
return InitWithTexture(pobTexture, rectInPixels, false, new CCPoint(0, 0), rectInPixels.Size);
}