本文整理汇总了C#中Cocos2D.CCSize类的典型用法代码示例。如果您正苦于以下问题:C# CCSize类的具体用法?C# CCSize怎么用?C# CCSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCSize类属于Cocos2D命名空间,在下文中一共展示了CCSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNativeLabel
internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment, string fontName,
float fontSize, CCColor4B textColor)
{
if (string.IsNullOrEmpty(text))
{
return new CCTexture2D();
}
var font = CreateFont (fontName, fontSize);
if (dimensions.Equals(CCSize.Zero))
{
CreateBitmap(1, 1);
var ms = _graphics.MeasureString(text, font);
dimensions.Width = ms.Width;
dimensions.Height = ms.Height;
}
CreateBitmap((int)dimensions.Width, (int)dimensions.Height);
var stringFormat = new StringFormat();
switch (hAlignment)
{
case CCTextAlignment.Left:
stringFormat.Alignment = StringAlignment.Near;
break;
case CCTextAlignment.Center:
stringFormat.Alignment = StringAlignment.Center;
break;
case CCTextAlignment.Right:
stringFormat.Alignment = StringAlignment.Far;
break;
}
switch (vAlignment)
{
case CCVerticalTextAlignment.Top:
stringFormat.LineAlignment = StringAlignment.Near;
break;
case CCVerticalTextAlignment.Center:
stringFormat.LineAlignment = StringAlignment.Center;
break;
case CCVerticalTextAlignment.Bottom:
stringFormat.LineAlignment = StringAlignment.Far;
break;
}
_graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
_graphics.Flush();
var texture = new CCTexture2D();
texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);
return texture;
}
示例2: CreateScaledMenuItemLabel
public static CCMenuItem CreateScaledMenuItemLabel(CCSize buttonSize, int labelPadding, float strokeSize, CCColor3B textColor, CCColor3B strokeColor, CCColor3B backColor, string labelText, Action action)
{
var menuItem = action != null ? new CCMenuItem(o => action()) : new CCMenuItem();
var labelSize = new CCSize(buttonSize.Width - labelPadding, buttonSize.Height - labelPadding);
// Add background
var blockSprite = new CCSprite("images/Block_Back");
blockSprite.ScaleTo(buttonSize);
blockSprite.Color = backColor;
menuItem.AddChild(blockSprite);
menuItem.ContentSize = buttonSize;
// Add label
var labelTtf = new CCLabelTTF(labelText, "arial-24", 10);
labelTtf.Color = textColor;
// Add Stroke to label
// if (strokeSize > 0) labelTtf.AddStroke(strokeSize, strokeColor);
if (labelTtf.ContentSize.Width > labelSize.Width)
{
labelTtf.ScaleTo(labelSize);
}
menuItem.AddChild(labelTtf);
return menuItem;
}
示例3: updateSize
public void updateSize(CCPoint touchLocation)
{
CCSize s = CCDirector.SharedDirector.WinSize;
CCSize newSize = new CCSize(Math.Abs(touchLocation.X - s.Width / 2) * 2, Math.Abs(touchLocation.Y - s.Height / 2) * 2);
CCLayerColor l = (CCLayerColor)GetChildByTag(kTagLayer);
l.ContentSize = newSize;
}
示例4: InitWithTarget
public bool InitWithTarget(Action<CCMenuItem> selector, CCMenuItem[] items)
{
base.InitWithTarget(selector);
CascadeColorEnabled = true;
CascadeOpacityEnabled = true;
m_pSubItems = new List<CCMenuItem>();
float w = float.MinValue;
float h = float.MinValue;
foreach (CCMenuItem item in items)
{
m_pSubItems.Add(item);
AddChild(item, 0);
item.Visible = false;
if (w < item.ContentSize.Width)
{
w = item.ContentSize.Width;
}
if (h < item.ContentSize.Height)
{
h = item.ContentSize.Height;
}
item.AnchorPoint = CCPoint.AnchorMiddle;
}
ContentSize = new CCSize(w, h);
foreach (CCMenuItem item in items)
{
item.Position = ContentSize.Center;
}
m_uSelectedIndex = int.MaxValue;
SelectedIndex = 0;
return true;
}
示例5: Transform
public static CCSize Transform(CCSize size, CCAffineTransform t)
{
var s = new CCSize();
s.Width = (float) ((double) t.a * size.Width + (double) t.c * size.Height);
s.Height = (float) ((double) t.b * size.Width + (double) t.d * size.Height);
return s;
}
示例6: ApplicationDidFinishLaunching
/// <summary>
/// Implement CCDirector and CCScene init code here.
/// </summary>
/// <returns>
/// true Initialize success, app continue.
/// false Initialize failed, app terminate.
/// </returns>
public override bool ApplicationDidFinishLaunching()
{
//initialize director
CCDirector pDirector = CCDirector.SharedDirector;
pDirector.SetOpenGlView();
CCSpriteFontCache.RegisterFont("arial", 12, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 38, 50, 64);
CCSpriteFontCache.RegisterFont("MarkerFelt", 16, 18, 22);
CCSpriteFontCache.RegisterFont("MarkerFelt-Thin", 12, 18);
CCSpriteFontCache.RegisterFont("Paint Boy", 26);
CCSpriteFontCache.RegisterFont("Schwarzwald Regular", 26);
CCSpriteFontCache.RegisterFont("Scissor Cuts", 26);
CCSpriteFontCache.RegisterFont("A Damn Mess", 26);
CCSpriteFontCache.RegisterFont("Abberancy", 26);
CCSpriteFontCache.RegisterFont("Abduction", 26);
// turn on display FPS
pDirector.DisplayStats = true;
// set FPS. the default value is 1.0/60 if you don't call this
pDirector.AnimationInterval = 1.0 / 60;
CCSize designSize = new CCSize(480, 320);
if (CCDrawManager.FrameSize.Height > 320)
{
CCSize resourceSize = new CCSize(960, 640);
CCContentManager.SharedContentManager.SearchPaths.Add("hd");
pDirector.ContentScaleFactor = resourceSize.Height / designSize.Height;
}
CCDrawManager.SetDesignResolutionSize(designSize.Width, designSize.Height, CCResolutionPolicy.ShowAll);
/*
#if WINDOWS || WINDOWSGL
CCDrawManager.SetDesignResolutionSize(1280, 768, CCResolutionPolicy.ExactFit);
#else
CCDrawManager.SetDesignResolutionSize(800, 480, CCResolutionPolicy.ShowAll);
//CCDrawManager.SetDesignResolutionSize(480, 320, CCResolutionPolicy.ShowAll);
#endif
*/
// create a scene. it's an autorelease object
CCScene pScene = new CCScene();
CCLayer pLayer = new TestController();
/*
CCScene pScene = CCScene.node();
var pLayer = Box2DView.viewWithEntryID(0);
pLayer.scale = 10;
pLayer.anchorPoint = new CCPoint(0, 0);
pLayer.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width / 2, CCDirector.sharedDirector().getWinSize().height / 4);
*/
pScene.AddChild(pLayer);
pDirector.RunWithScene(pScene);
return true;
}
示例7: LCC3GraphicsTexture
public LCC3GraphicsTexture(int tag, string name)
: base(tag, name)
{
_size = new LCC3IntSize(0, 0);
_coverage = CCSize.Zero;
_hasMipmap = false;
_isFlippedVertically = true;
_hasPremultipliedAlpha = false;
this.TextureParameters = this.DefaultTextureParameters;
}
示例8: OnHandlePropTypeSize
protected override void OnHandlePropTypeSize(CCNode node, CCNode parent, string propertyName, CCSize pSize, CCBReader reader)
{
if (propertyName == PROPERTY_CONTENTSIZE)
{
((CCScrollView) node).ViewSize = pSize;
}
else
{
base.OnHandlePropTypeSize(node, parent, propertyName, pSize, reader);
}
}
示例9: InitWithTileFile
public bool InitWithTileFile(string tile, string mapFile, int tileWidth, int tileHeight)
{
LoadTgAfile(mapFile);
CalculateItemsToRender();
if (base.InitWithTileFile(tile, tileWidth, tileHeight, m_nItemsToRender))
{
m_pPosToAtlasIndex = new Dictionary<CCGridSize, int>();
UpdateAtlasValues();
ContentSize = new CCSize(m_pTGAInfo.width * m_uItemWidth, m_pTGAInfo.height * m_uItemHeight);
return true;
}
return false;
}
示例10: CCSizeFromString
public static CCSize CCSizeFromString(string pszContent)
{
CCSize ret = new CCSize();
do
{
List<string> strs = new List<string>();
if (!CCUtils.SplitWithForm(pszContent, strs)) break;
float width = CCUtils.CCParseFloat(strs[0]);
float height = CCUtils.CCParseFloat(strs[1]);
ret = new CCSize(width, height);
} while (false);
return ret;
}
示例11: Enemy
private CCSize _winSize; // Contains the dimensions of the game window
#endregion Fields
#region Constructors
/// <summary>
/// Creates a new instance of an enemy using the Enemy content and mask.
/// </summary>
public Enemy()
: base(GameObjectType.Enemy, "Images/Enemy", "Enemy")
{
// Create a new instance of the shots list
_shots = new List<GameObject>();
// Get the dimensions of the window
_winSize = CCDirector.SharedDirector.WinSize;
// Set the speed of the enemy
_speed = CollisionGame.Rand.Next(2, 7);
// Get the next time that a shot will be fired
_nextShot = CollisionGame.Rand.Next(2, 5);
// Tell Cocos2d-XNA to schedule a call to this sprite's Update method
ScheduleUpdate();
}
示例12: updateAlignment
private void updateAlignment()
{
var blockSize = new CCSize(200, 160);
CCSize s = CCDirector.SharedDirector.WinSize;
if (m_plabel != null)
{
m_plabel.RemoveFromParentAndCleanup(true);
}
m_plabel = new CCLabelTTF(getCurrentAlignment(), "Marker Felt", 32,
blockSize, m_eHorizAlign, m_eVertAlign);
m_plabel.AnchorPoint = new CCPoint(0, 0);
m_plabel.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2);
AddChild(m_plabel);
}
示例13: GetAbsolutePosition
public static CCPoint GetAbsolutePosition(CCPoint pt, CCBPositionType nType, CCSize containerSize, string pPropName)
{
CCPoint absPt = new CCPoint(0, 0);
if (nType == CCBPositionType.RelativeBottomLeft)
{
absPt = pt;
}
else if (nType == CCBPositionType.RelativeTopLeft)
{
absPt.X = pt.X;
absPt.Y = containerSize.Height - pt.Y;
}
else if (nType == CCBPositionType.RelativeTopRight)
{
absPt.X = containerSize.Width - pt.X;
absPt.Y = containerSize.Height - pt.Y;
}
else if (nType == CCBPositionType.RelativeBottomRight)
{
absPt.X = containerSize.Width - pt.X;
absPt.Y = pt.Y;
}
else if (nType == CCBPositionType.Percent)
{
absPt.X = (int) (containerSize.Width * pt.X / 100.0f);
absPt.Y = (int) (containerSize.Height * pt.Y / 100.0f);
}
else if (nType == CCBPositionType.MultiplyResolution)
{
float resolutionScale = CCBReader.ResolutionScale;
absPt.X = pt.X * resolutionScale;
absPt.Y = pt.Y * resolutionScale;
}
return absPt;
}
示例14: LabelTTFTest
public LabelTTFTest()
{
var blockSize = new CCSize(200, 160);
CCSize s = CCDirector.SharedDirector.WinSize;
CCLayerColor colorLayer = new CCLayerColor(new CCColor4B(100, 100, 100, 255), blockSize.Width, blockSize.Height);
colorLayer.AnchorPoint = new CCPoint(0, 0);
colorLayer.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2);
AddChild(colorLayer);
CCMenuItemFont.FontSize = 30;
CCMenu menu = new CCMenu(
new CCMenuItemFont("Left", setAlignmentLeft),
new CCMenuItemFont("Center", setAlignmentCenter),
new CCMenuItemFont("Right", setAlignmentRight)
);
menu.AlignItemsVerticallyWithPadding(4);
menu.Position = new CCPoint(50, s.Height / 2 - 20);
AddChild(menu);
menu = new CCMenu(
new CCMenuItemFont("Top", setAlignmentTop),
new CCMenuItemFont("Middle", setAlignmentMiddle),
new CCMenuItemFont("Bottom", setAlignmentBottom)
);
menu.AlignItemsVerticallyWithPadding(4);
menu.Position = new CCPoint(s.Width - 50, s.Height / 2 - 20);
AddChild(menu);
m_plabel = null;
m_eHorizAlign = CCTextAlignment.CCTextAlignmentLeft;
m_eVertAlign = CCVerticalTextAlignment.CCVerticalTextAlignmentTop;
updateAlignment();
}
示例15: showFont
public void showFont(string pFont)
{
CCSize s = CCDirector.SharedDirector.WinSize;
var blockSize = new CCSize(s.Width / 3, 200);
float fontSize = 26;
RemoveChildByTag(kTagLabel1, true);
RemoveChildByTag(kTagLabel2, true);
RemoveChildByTag(kTagLabel3, true);
RemoveChildByTag(kTagLabel4, true);
CCLabelTTF top = new CCLabelTTF(pFont, "Arial", 24);
CCLabelTTF left = new CCLabelTTF("alignment left", pFont, fontSize,
blockSize, CCTextAlignment.Left,
FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);
CCLabelTTF center = new CCLabelTTF("alignment center", pFont, fontSize,
blockSize, CCTextAlignment.Center,
FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);
CCLabelTTF right = new CCLabelTTF("alignment right", pFont, fontSize,
blockSize, CCTextAlignment.Right,
FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);
top.AnchorPoint = new CCPoint(0.5f, 1);
left.AnchorPoint = new CCPoint(0, 0.5f);
center.AnchorPoint = new CCPoint(0, 0.5f);
right.AnchorPoint = new CCPoint(0, 0.5f);
top.Position = new CCPoint(s.Width / 2, s.Height - 20);
left.Position = new CCPoint(0, s.Height / 2);
center.Position = new CCPoint(blockSize.Width, s.Height / 2);
right.Position = new CCPoint(blockSize.Width * 2, s.Height / 2);
AddChild(left, 0, kTagLabel1);
AddChild(right, 0, kTagLabel2);
AddChild(center, 0, kTagLabel3);
AddChild(top, 0, kTagLabel4);
}