本文整理汇总了C#中Cocos2D.CCRect类的典型用法代码示例。如果您正苦于以下问题:C# CCRect类的具体用法?C# CCRect怎么用?C# CCRect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCRect类属于Cocos2D命名空间,在下文中一共展示了CCRect类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:12,代码来源:CCDrawingPrimitives.cs
示例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;
}
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:48,代码来源:CCFollow.cs
示例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));
}
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:19,代码来源:CCAffineTransform.cs
示例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)));
}
开发者ID:rtabbara,项目名称:Cocos3D-XNA,代码行数:20,代码来源:CC3ViewportUnitTests.cs
示例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;
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:21,代码来源:MainLayer.cs
示例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;
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:27,代码来源:CCAffineTransform.cs
示例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;
}
开发者ID:womandroid,项目名称:cocos2d-xna,代码行数:90,代码来源:CCBReader.cs
示例8: AddSpriteFrameWithTexture
public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
{
CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
AddSpriteFrame(pFrame);
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:5,代码来源:CCAnimation.cs
示例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;
}
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:22,代码来源:CCGeometry.cs
示例10: IntersectsRect
public bool IntersectsRect(ref CCRect rect)
{
return !(MaxX < rect.MinX || rect.MaxX < MinX || MaxY < rect.MinY || rect.MaxY < MinY);
}
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:4,代码来源:CCGeometry.cs
示例11: Equals
public bool Equals(CCRect rect)
{
return Origin.Equals(rect.Origin) && Size.Equals(rect.Size);
}
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:4,代码来源:CCGeometry.cs
示例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;
}
}
开发者ID:261117370,项目名称:cocos2d-xna,代码行数:82,代码来源:CCSprite.cs
示例13: SetVertexRect
// override this method to generate "double scale" sprites
protected virtual void SetVertexRect(CCRect rect)
{
m_obRect = rect;
}
开发者ID:261117370,项目名称:cocos2d-xna,代码行数:5,代码来源:CCSprite.cs
示例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);
}
}
开发者ID:261117370,项目名称:cocos2d-xna,代码行数:46,代码来源:CCSprite.cs
示例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;
}
开发者ID:rtabbara,项目名称:cocos2d-xna,代码行数:23,代码来源:CCTMXLayer.cs
示例16: updateQuads
public void updateQuads(float dt)
{
m_nIndex = (m_nIndex + 1) % 4;
var rect = new CCRect(m_nIndex * 32, 0, 32, 32);
var system = (CCParticleSystemQuad) m_emitter;
system.SetTextureWithRect(m_emitter.Texture, rect);
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:7,代码来源:ParticleTest.cs
示例17: CCPhysicsSprite
private b2Body m_pBody; // strong ref
public CCPhysicsSprite(CCTexture2D f, CCRect r)
: base(f, r)
{
}
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:6,代码来源:Box2DTest.cs
示例18: Intersection
public CCRect Intersection(CCRect rect)
{
if (!IntersectsRect(rect))
{
return (Zero);
}
/* +-------------+
* | |
* | +---+-----+
* +-----+---+ | | |
* | | | | | |
* | | | +---+-----+
* | | | |
* | | | |
* +-----+---+ |
* | |
* +-------------+
*/
float minx = 0, miny = 0, maxx = 0, maxy = 0;
// X
if (rect.MinX < MinX)
{
minx = MinX;
}
else if (rect.MinX < MaxX)
{
minx = rect.MinX;
}
if (rect.MaxX < MaxX)
{
maxx = rect.MaxX;
}
else if (rect.MaxX > MaxX)
{
maxx = MaxX;
}
// Y
if (rect.MinY < MinY)
{
miny = MinY;
}
else if (rect.MinY < MaxY)
{
miny = rect.MinY;
}
if (rect.MaxY < MaxY)
{
maxy = rect.MaxY;
}
else if (rect.MaxY > MaxY)
{
maxy = MaxY;
}
return new CCRect(minx, miny, maxx - minx, maxy - miny);
}
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:56,代码来源:CCGeometry.cs
示例19: 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: should not be re-init. Potential memeory leak. Not following best practices
// XXX: it shall call directory [setRect:rect]
m_pReusedTile.InitWithTexture(m_pobTextureAtlas.Texture, rect, false);
// Since initWithTexture resets the batchNode, we need to re add it.
// but should be removed once initWithTexture is not called again
m_pReusedTile.BatchNode = this;
}
return m_pReusedTile;
}
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:21,代码来源:CCTMXLayer.cs
示例20: Equal
public static bool Equal(ref CCRect rect1, ref CCRect rect2)
{
return rect1.Origin.Equals(rect2.Origin) && rect1.Size.Equals(rect2.Size);
}
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:4,代码来源:CCGeometry.cs
注:本文中的Cocos2D.CCRect类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论