本文整理汇总了C#中Cocos2D.CCTexture2D.InitWithTexture方法的典型用法代码示例。如果您正苦于以下问题:C# CCTexture2D.InitWithTexture方法的具体用法?C# CCTexture2D.InitWithTexture怎么用?C# CCTexture2D.InitWithTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cocos2D.CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D.InitWithTexture方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAtlasFromTexture2D
public static CCTextureAtlas CreateAtlasFromTexture2D(Microsoft.Xna.Framework.Graphics.Texture2D texture2d)
{
CCTexture2D texture = new CCTexture2D();
texture.InitWithTexture(texture2d);
CCTextureAtlas textureAtlas = CCTextureAtlas.Create(texture, 128);
return textureAtlas;
}
示例2: MakeTexture
private void MakeTexture()
{
m_pTexture = new CCTexture2D();
m_pTexture.OnReInit = TextureReInit;
m_pTexture.IsAntialiased = false;
m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(m_Width, m_Height, m_ColorFormat, m_DepthFormat, m_Usage);
m_pTexture.InitWithTexture(m_pRenderTarget2D, m_ColorFormat, true, false);
m_bFirstUsage = true;
m_pSprite = new CCSprite(m_pTexture);
//m_pSprite.scaleY = -1;
m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;
AddChild(m_pSprite);
}
示例3: InitWithWidthAndHeight
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
{
w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor());
h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor());
m_pTexture = new CCTexture2D();
m_pTexture.IsAntialiased = false;
m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false);
m_bFirstUsage = true;
m_pSprite = new CCSprite(m_pTexture);
//m_pSprite.scaleY = -1;
m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;
AddChild(m_pSprite);
return true;
}
示例4: InitWithWidthAndHeight
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
{
w = (w * CCMacros.CCContentScaleFactor());
h = (h * CCMacros.CCContentScaleFactor());
m_pTexture = new CCTexture2D();
m_pTexture.SetAliasTexParameters();
m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
m_pTexture.InitWithTexture(m_pRenderTarget2D);
m_bFirstUsage = true;
m_pSprite = new CCSprite(m_pTexture);
//m_pSprite.scaleY = -1;
m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
AddChild(m_pSprite);
return true;
}
示例5: EndTexture
public CCTexture2D EndTexture()
{
Texture2D xnaTexture = new Texture2D(CCApplication.SharedApplication.GraphicsDevice, this.imageBuffer.Width, this.imageBuffer.Height);
xnaTexture.SetData<byte>(this.imageBuffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return ccTexture;
}
示例6: CreateText
public static CCSprite CreateText(string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1)
{
TypeFacePrinter printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves));
double width = printer.LocalBounds.Width;
double height = printer.LocalBounds.Height;
RectangleDouble rect = new RectangleDouble();
bounding_rect.bounding_rect_single(printer, 0, ref rect);
VertexSourceApplyTransform path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(-rect.Left, -rect.Bottom));
ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
Graphics2D g = buffer.NewGraphics2D();
if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
Texture2D xnaTexture = XnaTexture((int)width, (int)height);
xnaTexture.SetData<byte>(buffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return new CCSprite(ccTexture);
}
示例7: CreateRectangle
//矩形
public static CCSprite CreateRectangle(
double width, double height,
double radiusX, double radiusY,
CCColor4B fill, CCColor4B stroke,
double strokeThickness = 1
)
{
ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
Graphics2D g = buffer.NewGraphics2D();
RoundedRect path;
if (stroke.A > 0) //有border
{
//border是以线的中间对齐,所以转换成int,如果是1个像素,正好变成零
int halfThickness = (int)(strokeThickness / 2);
path = new RoundedRect(halfThickness, halfThickness, width - halfThickness, height - halfThickness, Math.Min(radiusX, radiusY));
}
else
{
path = new RoundedRect(0, 0, width, height, Math.Min(radiusX, radiusY));
}
if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
Texture2D xnaTexture = XnaTexture((int)width, (int)height);
xnaTexture.SetData<byte>(buffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return new CCSprite(ccTexture);
}
示例8: CreatePath
//路径
public static CCSprite CreatePath(
double width, double height,
string[] paths,
double contentX, double contentY,
double contentWidth, double contentHeight,
CCColor4B fill, CCColor4B stroke,
double strokeThickness = 1,
UIGraphic.Stretch stretch = UIGraphic.Stretch.StretchNone
)
{
if (width == 0) width = contentWidth;
if (height == 0) height = contentHeight;
ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
Graphics2D g = buffer.NewGraphics2D();
double scalex = 0;
double scaley = 0;
//if (stretch == Stretch.StretchNone) { } else
if (stretch == UIGraphic.Stretch.StretchFill)
{
if (width != contentWidth || height != contentHeight)
{
scalex = width / contentWidth;
scaley = height / contentHeight;
}
}
else if (stretch == UIGraphic.Stretch.StretchUniformToFill)
{
scalex = scaley = Math.Min(width / contentWidth, height / contentHeight);
}
foreach (string path in paths)
{
IVertexSource vertexs = MiniLanguage.CreatePathStorage(path);
if (contentX != 0 || contentY != 0)
vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(-contentX, -contentY));
if (scalex != 0 || scaley != 0)
vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley));
if (fill.A > 0) g.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
if (stroke.A > 0) g.Render(new Stroke(vertexs, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
}
Texture2D xnaTexture = XnaTexture((int)width, (int)height);
xnaTexture.SetData<byte>(buffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return new CCSprite(ccTexture);
}
示例9: CreateLine
public static CCSprite CreateLine(
int width, int height,
CCColor4B stroke,
double strokeThickness = 1
)
{
ImageBuffer buffer = new ImageBuffer(width, height, 32, new BlenderRGBA());
Graphics2D g = buffer.NewGraphics2D();
if (stroke.A > 0)
{
//g.Line没有厚度
PathStorage linesToDraw = new PathStorage();
linesToDraw.remove_all();
linesToDraw.MoveTo(0, 0);
linesToDraw.LineTo(width, height);
Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness);
g.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
}
Texture2D xnaTexture = XnaTexture((int)width, (int)height);
xnaTexture.SetData<byte>(buffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return new CCSprite(ccTexture);
}
示例10: CreateEllipse
//圆形
public static CCSprite CreateEllipse(
double width, double height,
CCColor4B fill, CCColor4B stroke,
double strokeThickness = 1
)
{
ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
Graphics2D g = buffer.NewGraphics2D();
MatterHackers.Agg.VertexSource.Ellipse path;
if (stroke.A > 0) //有border
{
//border是以线的中间对齐,所以转换成int,如果是1个像素,正好变成零
int halfThickness = (int)(strokeThickness / 2);
path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2 - halfThickness, height / 2 - halfThickness);
}
else
{
path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2, height / 2);
}
if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
Texture2D xnaTexture = XnaTexture((int)width, (int)height);
xnaTexture.SetData<byte>(buffer.GetBuffer());
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return new CCSprite(ccTexture);
}
示例11: CCTextureFromPng
public static CCTexture2D CCTextureFromPng(Stream pngStream)
{
Texture2D xnaTexture = XnaTextureFromPng(pngStream);
CCTexture2D ccTexture = new CCTexture2D();
ccTexture.InitWithTexture(xnaTexture);
return ccTexture;
}
示例12: saveImage
public void saveImage(object pSender)
{
using (var stream = new MemoryStream())
{
m_pTarget.SaveToStream(stream, CCImageFormat.PNG);
//m_pTarget.saveToFile(jpg, ImageFormat.JPG);
stream.Position = 0;
Texture2D xnatex = Texture2D.FromStream(CCDrawManager.GraphicsDevice, stream);
var tex = new CCTexture2D();
tex.InitWithTexture(xnatex);
CCSprite sprite = new CCSprite(tex);
sprite.Scale = 0.3f;
AddChild(sprite);
sprite.Position = new CCPoint(40, 40);
sprite.Rotation = counter * 3;
}
counter++;
}