本文整理汇总了C#中Cocos2D.CCSprite类的典型用法代码示例。如果您正苦于以下问题:C# CCSprite类的具体用法?C# CCSprite怎么用?C# CCSprite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCSprite类属于Cocos2D命名空间,在下文中一共展示了CCSprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HighScoreLayer
public HighScoreLayer (int score): base()
{
currentScore = score;
var batchnode = GetChildByTag ((int)Tags.SpriteManager) as CCSpriteBatchNode;
var title = new CCSprite(batchnode.Texture,new CCRect(608,192,225,57));
title.Position=new CCPoint(160,240);
batchnode.AddChild (title);
var button1 = new CCMenuItemImage("Images/playAgainButton", "Images/playAgainButton",
new Action<object>(delegate(object o) {
CCDirector.SharedDirector.ReplaceScene(new CCTransitionFade(.5f, GameLayer.Scene, new CCColor3B(255,255,255)));
}));
var button2 = new CCMenuItemImage("Images/changePlayerButton", "Images/changePlayerButton", new Action<object>(delegate (object sender) {
// do nothing
}));
var menu = new CCMenu(button1,button2);
menu.Position=new CCPoint(160,58);
menu.AlignItemsVerticallyWithPadding(9);
AddChild (menu);
}
示例2: GameLayer
public GameLayer()
{
TouchEnabled = true;
localBananas = new List<CCSprite> ();
localMonkey = new CCSprite ("MonkeyLocal");
localMonkey.PositionY = 0;
localMonkey.PositionX = CCDirector.SharedDirector.WinSize.Width / 2;
AddChild (localMonkey);
remoteMonkey = new CCSprite ("MonkeyRemote");
remoteMonkey.PositionY = CCDirector.SharedDirector.WinSize.Height - remoteMonkey.ContentSizeInPixels.Height/2;
remoteMonkey.PositionX = CCDirector.SharedDirector.WinSize.Width / 2;
AddChild (remoteMonkey);
if (!Context.isRoomCreator) {
byte[] message = buildStartMessage ();
sendWarpUpdate (message);
beginLocalGame ();
}
Color = new CCColor3B (XNA.Color.ForestGreen);
Opacity = 255;
}
示例3: SpriteBatchNodeReorderIssue767
public SpriteBatchNodeReorderIssue767()
{
CCSize s = CCDirector.SharedDirector.WinSize;
CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts");
CCNode aParent;
CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;
//
// SpriteBatchNode: 3 levels of children
//
aParent = new CCSpriteBatchNode("animations/ghosts");
AddChild(aParent, 0, (int) kTagSprite.kTagSprite1);
// parent
l1 = new CCSprite("father.gif");
l1.Position = (new CCPoint(s.Width / 2, s.Height / 2));
aParent.AddChild(l1, 0, (int) kTagSprite.kTagSprite2);
CCSize l1Size = l1.ContentSize;
// child left
l2a = new CCSprite("sister1.gif");
l2a.Position = (new CCPoint(-25 + l1Size.Width / 2, 0 + l1Size.Height / 2));
l1.AddChild(l2a, -1, (int) kTags.kTagSpriteLeft);
CCSize l2aSize = l2a.ContentSize;
// child right
l2b = new CCSprite("sister2.gif");
l2b.Position = (new CCPoint(+25 + l1Size.Width / 2, 0 + l1Size.Height / 2));
l1.AddChild(l2b, 1, (int) kTags.kTagSpriteRight);
CCSize l2bSize = l2a.ContentSize;
// child left bottom
l3a1 = new CCSprite("child1.gif");
l3a1.Scale = (0.65f);
l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, -50 + l2aSize.Height / 2));
l2a.AddChild(l3a1, -1);
// child left top
l3a2 = new CCSprite("child1.gif");
l3a2.Scale = (0.65f);
l3a2.Position = (new CCPoint(0 + l2aSize.Width / 2, +50 + l2aSize.Height / 2));
l2a.AddChild(l3a2, 1);
// child right bottom
l3b1 = new CCSprite("child1.gif");
l3b1.Scale = (0.65f);
l3b1.Position = (new CCPoint(0 + l2bSize.Width / 2, -50 + l2bSize.Height / 2));
l2b.AddChild(l3b1, -1);
// child right top
l3b2 = new CCSprite("child1.gif");
l3b2.Scale = (0.65f);
l3b2.Position = (new CCPoint(0 + l2bSize.Width / 2, +50 + l2bSize.Height / 2));
l2b.AddChild(l3b2, 1);
Schedule(reorderSprites, 1);
}
示例4: updateQuantityOfNodes
public override void updateQuantityOfNodes()
{
CCSize s = CCDirector.SharedDirector.WinSize;
// increase nodes
if (currentQuantityOfNodes < quantityOfNodes)
{
StartTimer();
for (int i = 0; i < (quantityOfNodes - currentQuantityOfNodes); i++)
{
CCSprite sprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32));
batchNode.AddChild(sprite);
sprite.Position = new CCPoint(CCRandom.Next() * s.Width, CCRandom.Next() * s.Height);
sprite.Visible = false;
}
EndTimer("Current Quantity: add");
}
// decrease nodes
else if (currentQuantityOfNodes > quantityOfNodes)
{
StartTimer();
for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++)
{
int index = currentQuantityOfNodes - i - 1;
batchNode.RemoveChildAtIndex(index, true);
}
EndTimer("Current Quantity: add");
}
currentQuantityOfNodes = quantityOfNodes;
}
示例5: SpriteZOrder
public SpriteZOrder()
{
m_dir = 1;
CCSize s = CCDirector.SharedDirector.WinSize;
float step = s.Width / 11;
for (int i = 0; i < 5; i++)
{
CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121));
sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2));
AddChild(sprite, i);
}
for (int i = 5; i < 10; i++)
{
CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 0, 85, 121));
sprite.Position = new CCPoint((i + 1) * step, s.Height / 2);
AddChild(sprite, 14 - i);
}
CCSprite sprite1 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 3, 121 * 0, 85, 121));
AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
sprite1.Position = (new CCPoint(s.Width / 2, s.Height / 2 - 20));
sprite1.Scale = 6;
sprite1.Color = new CCColor3B(Color.Red);
Schedule(reorderSprite, 1);
}
示例6: SpriteBatchNodeAliased
public SpriteBatchNodeAliased()
{
CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 10);
AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);
CCSize s = CCDirector.SharedDirector.WinSize;
CCSprite sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
sprite1.Position = (new CCPoint(s.Width / 2 - 100, s.Height / 2));
batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1);
CCSprite sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
sprite2.Position = (new CCPoint(s.Width / 2 + 100, s.Height / 2));
batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2);
CCActionInterval scale = new CCScaleBy(2, 5);
CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
CCActionInterval seq = (CCActionInterval)(new CCSequence(scale, scale_back));
CCAction repeat = new CCRepeatForever (seq);
CCAction repeat2 = (CCAction)(repeat.Copy());
sprite1.RunAction(repeat);
sprite2.RunAction(repeat2);
}
示例7: performanceRotationScale
private void performanceRotationScale(CCSprite pSprite)
{
CCSize size = CCDirector.SharedDirector.WinSize;
pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
pSprite.Rotation = CCRandom.Float_0_1() * 360;
pSprite.Scale = CCRandom.Float_0_1() * 2;
}
示例8: Test5
public Test5()
{
CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
sp2 = new CCSprite(TestResource.s_pPathSister2);
sp1.Position = (new CCPoint(100, 160));
sp2.Position = (new CCPoint(380, 160));
CCRotateBy rot = new CCRotateBy (2, 360);
var rot_back = rot.Reverse() as CCActionInterval;
CCAction forever = new CCRepeatForever ((CCActionInterval)new CCSequence(rot, rot_back));
forever2 = (CCAction) (forever.Copy());
forever.Tag = (101);
forever2.Tag = (102);
AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);
AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);
RemoveChild(sp2, true);
AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);
// Sprite 1 should run and run
// Sprite 2 should stop
sp1.RunAction(forever);
sp2.RunAction(forever2);
// Experiment with removing sp2 and re-adding it after cleanup to reproduce an error in child management
// ScheduleOnce(Stage2OfTest, 2.0f);
Schedule(addAndRemove, 2.0f);
}
示例9: SpriteBatchNodeZOrder
public SpriteBatchNodeZOrder()
{
m_dir = 1;
// small capacity. Testing resizing.
// Don't use capacity=1 in your real game. It is expensive to resize the capacity
CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1);
AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);
CCSize s = CCDirector.SharedDirector.WinSize;
float step = s.Width / 11;
for (int i = 0; i < 5; i++)
{
CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2));
batch.AddChild(sprite, i);
}
for (int i = 5; i < 10; i++)
{
CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
sprite.Position = new CCPoint((i + 1) * step, s.Height / 2);
batch.AddChild(sprite, 14 - i);
}
CCSprite sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 0, 85, 121));
batch.AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
sprite1.Position = (new CCPoint(s.Width / 2, s.Height / 2 - 20));
sprite1.Scale = 6;
sprite1.Color = new CCColor3B(Color.Red);
Schedule(reorderSprite, 1);
}
示例10: Test6
public Test6()
{
CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
CCSprite sp11 = new CCSprite(TestResource.s_pPathSister1);
CCSprite sp2 = new CCSprite(TestResource.s_pPathSister2);
CCSprite sp21 = new CCSprite(TestResource.s_pPathSister2);
sp1.Position = (new CCPoint(100, 160));
sp2.Position = (new CCPoint(380, 160));
CCActionInterval rot = new CCRotateBy (2, 360);
var rot_back = rot.Reverse() as CCActionInterval;
CCAction forever1 = new CCRepeatForever ((CCActionInterval)new CCSequence(rot, rot_back));
var forever11 = (CCAction) (forever1.Copy());
var forever2 = (CCAction) (forever1.Copy());
var forever21 = (CCAction) (forever1.Copy());
AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);
sp1.AddChild(sp11);
AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);
sp2.AddChild(sp21);
sp1.RunAction(forever1);
sp11.RunAction(forever11);
sp2.RunAction(forever2);
sp21.RunAction(forever21);
Schedule(addAndRemove, 2.0f);
}
示例11: Init
public override bool Init()
{
InitWithColor(new CCColor4B(0, 0, 255, 255));
var item0 = new CCMenuItemFont("(3) Touch to pushScene (self)", item0Clicked);
var item1 = new CCMenuItemFont("(3) Touch to popScene", item1Clicked);
var item2 = new CCMenuItemFont("(3) Touch to popToRootScene", item2Clicked);
var item3 = new CCMenuItemFont("(3) Touch to popToSceneStackLevel(2)", item3Clicked);
CCMenu menu = new CCMenu(item0, item1, item2, item3);
menu.AlignItemsVertically();
AddChild(menu);
CCSize s = CCDirector.SharedDirector.WinSize;
CCSprite sprite = new CCSprite(s_pPathGrossini);
AddChild(sprite);
sprite.Position = new CCPoint(s.Width /2, 40);
CCActionInterval rotate = new CCRotateBy (2, 360);
CCAction repeat = new CCRepeatForever (rotate);
sprite.RunAction(repeat);
Schedule(testDealloc);
return true;
}
示例12: TableCellAtIndex
public virtual CCTableViewCell TableCellAtIndex(CCTableView table, int idx)
{
string str = idx.ToString();
var cell = table.DequeueCell();
if (cell == null) {
cell = new CustomTableViewCell();
var sprite = new CCSprite("Images/Icon");
sprite.AnchorPoint = CCPoint.Zero;
sprite.Position = new CCPoint(0, 0);
cell.AddChild(sprite);
var label = new CCLabelTTF(str, "Helvetica", 20.0f);
label.Position = CCPoint.Zero;
label.AnchorPoint = CCPoint.Zero;
label.Tag = 123;
cell.AddChild(label);
}
else
{
var label = (CCLabelTTF)cell.GetChildByTag(123);
label.Label = (str);
}
return cell;
}
示例13: 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;
}
示例14: addNewSpriteWithCoords
public void addNewSpriteWithCoords(CCPoint p)
{
CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode);
int idx = (int)(CCRandom.NextDouble() * 1400 / 100);
int x = (idx % 5) * 85;
int y = (idx / 5) * 121;
CCSprite sprite = new CCSprite(BatchNode.Texture, new CCRect(x, y, 85, 121));
BatchNode.AddChild(sprite);
sprite.Position = (new CCPoint(p.X, p.Y));
CCActionInterval action = null;
float random = (float)CCRandom.NextDouble();
if (random < 0.20)
action = new CCScaleBy(3, 2);
else if (random < 0.40)
action = new CCRotateBy (3, 360);
else if (random < 0.60)
action = new CCBlink (1, 3);
else if (random < 0.8)
action = new CCTintBy (2, 0, -255, -255);
else
action = new CCFadeOut (2);
CCActionInterval action_back = (CCActionInterval)action.Reverse();
CCActionInterval seq = (CCActionInterval)(new CCSequence(action, action_back));
sprite.RunAction(new CCRepeatForever (seq));
}
示例15: RenderTextureCompositeTest
public RenderTextureCompositeTest()
{
var winSize = CCDirector.SharedDirector.WinSize;
var characterSpriteFactory = new CharacterSpriteFactory();
_testSprite = new CCSprite(@"Images\grossini_dance_01");
_testSprite2 = new CCSprite(@"Images\grossini_dance_02");
_swingAnimate = characterSpriteFactory.CreateAnimateAction();
_thrustAnimate = characterSpriteFactory.CreateAnimateAction();
_dodgeAnimate = characterSpriteFactory.CreateAnimateAction();
_collapseAnimate = characterSpriteFactory.CreateAnimateAction();
_swingAnimate2 = characterSpriteFactory.CreateAnimateAction();
_thrustAnimate2 = characterSpriteFactory.CreateAnimateAction();
_dodgeAnimate2 = characterSpriteFactory.CreateAnimateAction();
_collapseAnimate2 = characterSpriteFactory.CreateAnimateAction();
_testSprite.Position = new CCPoint(winSize.Width / 2 -200, winSize.Height / 2 + 100);
AddChild(_testSprite);
_testSprite2.Position = new CCPoint(winSize.Width / 2 + 200, winSize.Height / 2 + 100);
_testSprite2.FlipX = true;
AddChild(_testSprite2);
AnimationLoop();
AnimationLoop2();
}