本文整理汇总了C#中Cocos2D.CCRect类的典型用法代码示例。如果您正苦于以下问题:C# CCRect类的具体用法?C# CCRect怎么用?C# CCRect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCRect类属于Cocos2D命名空间,在下文中一共展示了CCRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawRect
public static void DrawRect(CCRect rect, CCColor4B color)
{
float x1 = rect.MinX;
float y1 = rect.MinY;
float x2 = rect.MaxX;
float y2 = rect.MaxY;
DrawLine(new CCPoint(x1, y1), new CCPoint(x2, y1), color);
DrawLine(new CCPoint(x2, y1), new CCPoint(x2, y2), color);
DrawLine(new CCPoint(x2, y2), new CCPoint(x1, y2), color);
DrawLine(new CCPoint(x1, y2), new CCPoint(x1, y1), color);
}
示例2: InitWithTarget
private bool InitWithTarget(CCNode pFollowedNode, CCRect rect)
{
Debug.Assert(pFollowedNode != null);
m_pobFollowedNode = pFollowedNode;
if (rect.Equals(CCRect.Zero))
{
m_bBoundarySet = false;
}
else
{
m_bBoundarySet = true;
}
m_bBoundaryFullyCovered = false;
CCSize winSize = CCDirector.SharedDirector.WinSize;
m_obFullScreenSize = (CCPoint)winSize;
m_obHalfScreenSize = m_obFullScreenSize * 0.5f;
if (m_bBoundarySet)
{
m_fLeftBoundary = -((rect.Origin.X + rect.Size.Width) - m_obFullScreenSize.X);
m_fRightBoundary = -rect.Origin.X;
m_fTopBoundary = -rect.Origin.Y;
m_fBottomBoundary = -((rect.Origin.Y + rect.Size.Height) - m_obFullScreenSize.Y);
if (m_fRightBoundary < m_fLeftBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2;
}
if (m_fTopBoundary < m_fBottomBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2;
}
if ((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary))
{
m_bBoundaryFullyCovered = true;
}
}
return true;
}
示例3: CCRectApplyAffineTransform
public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
{
float top = CCRect.CCRectGetMinY(rect);
float left = CCRect.CCRectGetMinX(rect);
float right = CCRect.CCRectGetMaxX(rect);
float bottom = CCRect.CCRectGetMaxY(rect);
CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);
float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));
return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
}
示例4: Is_ContainsPoint_Robust
public void Is_ContainsPoint_Robust()
{
CCRect vpRect = new CCRect(5.0f, -5.0f, 15.0f, 20.0f);
CCSize vpSize = vpRect.Size;
CC3Viewport vp = new CC3Viewport(vpRect);
// General sanity test
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width / 2.0f, vpSize.Height / 2.0f)));
// Checking corners of viewport
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin));
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width, 0.0f)));
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(0.0f, vpSize.Height)));
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(vpSize.Width, vpSize.Height)));
// Test sensitivity to decimal changes in coordinates
// Floats are cast as ints in viewport fields
Assert.IsFalse(vp.ContainsPoint(vpRect.Origin + new CCPoint(-0.1f, 0.0f)));
Assert.IsTrue(vp.ContainsPoint(vpRect.Origin + new CCPoint(0.1f, 0.0f)));
}
示例5: InitCloud
void InitCloud () {
CCRect rect;
switch(ran.Next()%3) {
case 0:
rect = new CCRect(336, 16, 256, 108);
break;
case 1:
rect = new CCRect(336, 128, 257, 110);
break;
default:
rect = new CCRect(336, 240, 252, 119);
break;
}
var batchNode = GetChildByTag((int)Tags.SpriteManager) as CCSpriteBatchNode;
var cloud = new CCSprite(batchNode.Texture, rect);
batchNode.AddChild(cloud,3,currentCloudTag);
cloud.Opacity = 128;
}
示例6: Transform
public void Transform(ref CCRect rect)
{
float top = rect.MinY;
float left = rect.MinX;
float right = rect.MaxX;
float bottom = rect.MaxY;
CCPoint topLeft = new CCPoint(left, top);
CCPoint topRight = new CCPoint(right, top);
CCPoint bottomLeft = new CCPoint(left, bottom);
CCPoint bottomRight = new CCPoint(right, bottom);
Transform(ref topLeft);
Transform(ref topRight);
Transform(ref bottomLeft);
Transform(ref bottomRight);
float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));
rect.Origin.X = minX;
rect.Origin.Y = minY;
rect.Size.Width = maxX - minX;
rect.Size.Height = maxY - minY;
}
示例7: ReadKeyframe
private CCBKeyframe ReadKeyframe(CCBPropertyType type)
{
var keyframe = new CCBKeyframe();
keyframe.Time = ReadFloat();
var easingType = (CCBEasingType) ReadInt(false);
float easingOpt = 0;
object value = null;
if (easingType == CCBEasingType.CubicIn
|| easingType == CCBEasingType.CubicOut
|| easingType == CCBEasingType.CubicInOut
|| easingType == CCBEasingType.ElasticIn
|| easingType == CCBEasingType.ElasticOut
|| easingType == CCBEasingType.ElasticInOut)
{
easingOpt = ReadFloat();
}
keyframe.EasingType = easingType;
keyframe.EasingOpt = easingOpt;
if (type == CCBPropertyType.Check)
{
value = new CCBValue(ReadBool());
}
else if (type == CCBPropertyType.Byte)
{
value = new CCBValue(ReadByte());
}
else if (type == CCBPropertyType.Color3)
{
byte r = ReadByte();
byte g = ReadByte();
byte b = ReadByte();
var c = new CCColor3B(r, g, b);
value = new CCColor3BWapper(c);
}
else if (type == CCBPropertyType.Degrees)
{
value = new CCBValue(ReadFloat());
}
else if (type == CCBPropertyType.ScaleLock || type == CCBPropertyType.Position || type == CCBPropertyType.FloatXY)
{
float a = ReadFloat();
float b = ReadFloat();
value = new List<CCBValue>
{
new CCBValue(a),
new CCBValue(b)
};
}
else if (type == CCBPropertyType.SpriteFrame)
{
string spriteSheet = ReadCachedString();
string spriteFile = ReadCachedString();
CCSpriteFrame spriteFrame;
if (String.IsNullOrEmpty(spriteSheet))
{
spriteFile = _CCBRootPath + spriteFile;
CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height);
spriteFrame = new CCSpriteFrame(texture, bounds);
}
else
{
spriteSheet = _CCBRootPath + spriteSheet;
CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
// Load the sprite sheet only if it is not loaded
if (!_loadedSpriteSheets.Contains(spriteSheet))
{
frameCache.AddSpriteFramesWithFile(spriteSheet);
_loadedSpriteSheets.Add(spriteSheet);
}
spriteFrame = frameCache.SpriteFrameByName(spriteFile);
}
value = spriteFrame;
}
keyframe.Value = value;
return keyframe;
}
示例8: AddSpriteFrameWithTexture
public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
{
CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
AddSpriteFrame(pFrame);
}
示例9: ContainsPoint
public static bool ContainsPoint(ref CCRect rect, ref CCPoint point)
{
bool bRet = false;
if (float.IsNaN(point.X))
{
point.X = 0;
}
if (float.IsNaN(point.Y))
{
point.Y = 0;
}
if (point.X >= rect.MinX && point.X <= rect.MaxX && point.Y >= rect.MinY &&
point.Y <= rect.MaxY)
{
bRet = true;
}
return bRet;
}
示例10: IntersectsRect
public bool IntersectsRect(ref CCRect rect)
{
return !(MaxX < rect.MinX || rect.MaxX < MinX || MaxY < rect.MinY || rect.MaxY < MinY);
}
示例11: Equals
public bool Equals(CCRect rect)
{
return Origin.Equals(rect.Origin) && Size.Equals(rect.Size);
}
示例12: 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;
}
}
示例13: SetVertexRect
// override this method to generate "double scale" sprites
protected virtual void SetVertexRect(CCRect rect)
{
m_obRect = rect;
}
示例14: SetTextureRect
public void SetTextureRect(CCRect value, bool rotated, CCSize untrimmedSize)
{
m_bRectRotated = rotated;
ContentSize = untrimmedSize;
SetVertexRect(value);
SetTextureCoords(value);
CCPoint relativeOffset = m_obUnflippedOffsetPositionFromCenter;
// issue #732
if (m_bFlipX)
{
relativeOffset.X = -relativeOffset.X;
}
if (m_bFlipY)
{
relativeOffset.Y = -relativeOffset.Y;
}
m_obOffsetPosition.X = relativeOffset.X + (m_obContentSize.Width - m_obRect.Size.Width) / 2;
m_obOffsetPosition.Y = relativeOffset.Y + (m_obContentSize.Height - m_obRect.Size.Height) / 2;
// rendering using batch node
if (m_pobBatchNode != null)
{
// update dirty_, don't update recursiveDirty_
Dirty = true;
}
else
{
// self rendering
// Atlas: Vertex
float x1 = 0 + m_obOffsetPosition.X;
float y1 = 0 + m_obOffsetPosition.Y;
float x2 = x1 + m_obRect.Size.Width;
float y2 = y1 + m_obRect.Size.Height;
// Don't update Z.
m_sQuad.BottomLeft.Vertices = CCTypes.Vertex3(x1, y1, 0);
m_sQuad.BottomRight.Vertices = CCTypes.Vertex3(x2, y1, 0);
m_sQuad.TopLeft.Vertices = CCTypes.Vertex3(x1, y2, 0);
m_sQuad.TopRight.Vertices = CCTypes.Vertex3(x2, y2, 0);
}
}
示例15: ReusedTileWithRect
private CCSprite ReusedTileWithRect(CCRect rect)
{
if (m_pReusedTile == null)
{
m_pReusedTile = new CCSprite();
m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);
m_pReusedTile.BatchNode = this;
}
else
{
// XXX HACK: Needed because if "batch node" is nil,
// then the Sprite'squad will be reset
m_pReusedTile.BatchNode = null;
// Re-init the sprite
m_pReusedTile.SetTextureRect(rect, false, rect.Size);
// restore the batch node
m_pReusedTile.BatchNode = this;
}
return m_pReusedTile;
}