本文整理汇总了C#中Sprite.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# Sprite.AddChild方法的具体用法?C# Sprite.AddChild怎么用?C# Sprite.AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite.AddChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
/// <summary>
/// Sets the screen up (UI components, multimedia content, etc.)
/// </summary>
public override void Initialize()
{
base.Initialize();
//Loads the spritesheet
SpriteSheet spriteSheetChuck = ResourceManager.CreateSpriteSheet("chuckSpriteSheet");
//Create the Sprites
Sprite spriteHead = new Sprite("head", spriteSheetChuck["head"]) { Pivot = Vector2.One / 2, Touchable = false };
Sprite spriteBody = new Sprite("body", spriteSheetChuck["body"]) { Pivot = Vector2.One / 2 };
Sprite spriteArmLeft1 = new Sprite("arm_left_1", spriteSheetChuck["arm_left_1"]) { Pivot = new Vector2(0.75f, 0.65f), Touchable = false };
Sprite spriteArmLeft2 = new Sprite("arm_left_2", spriteSheetChuck["arm_left_2"]) { Pivot = new Vector2(0.75f, 0.25f), Touchable = false };
Sprite spriteArmRight1 = new Sprite("arm_right_1", spriteSheetChuck["arm_right_1"]) { Pivot = new Vector2(0.75f, 0.35f), Touchable = false };
Sprite spriteArmRight2 = new Sprite("arm_right_2", spriteSheetChuck["arm_right_2"]) { Pivot = new Vector2(0.75f, 0.75f), Touchable = false };
Sprite spriteFootLeft = new Sprite("foot_left", spriteSheetChuck["foot_left"]) { Pivot = Vector2.One / 2, Touchable = false };
Sprite spriteFootRight = new Sprite("foot_right", spriteSheetChuck["foot_right"]) { Pivot = Vector2.One / 2, Touchable = false };
spriteBody.Draggable = true;
// Sprite tree
spriteBody.AddChild(spriteHead);
spriteBody.AddChild(spriteArmLeft2);
spriteBody.AddChild(spriteArmRight2);
spriteBody.AddChild(spriteFootLeft);
spriteBody.AddChild(spriteFootRight);
spriteArmLeft2.AddChild(spriteArmLeft1);
spriteArmRight2.AddChild(spriteArmRight1);
// Adds the player to the screen
AddComponent(spriteBody, 0.5f * Preferences.ViewportManager.VirtualWidth, 0.5f * Preferences.ViewportManager.VirtualHeight);
// Positions
spriteArmLeft2.Position = spriteBody.Position + Vector2.UnitY * spriteBody.Size.Y * spriteBody.Pivot.Y * 0.9f;
spriteArmRight2.Position = spriteBody.Position - Vector2.UnitY * spriteBody.Size.Y * spriteBody.Pivot.Y * 0.9f;
spriteArmLeft1.Position = spriteArmLeft2.Position - new Vector2(spriteArmLeft2.Size.X * spriteArmLeft2.Pivot.X, -spriteArmLeft2.Size.Y * spriteArmLeft2.Pivot.Y);
spriteArmRight1.Position = spriteArmRight2.Position - new Vector2(spriteArmRight2.Size.X * spriteArmRight2.Pivot.X, spriteArmLeft2.Size.Y * spriteArmLeft2.Pivot.Y);
spriteFootLeft.Position = spriteBody.Position + Vector2.UnitY * spriteBody.Size * spriteBody.Pivot * 0.3f - Vector2.UnitX * 10;
spriteFootRight.Position = spriteBody.Position - Vector2.UnitY * spriteBody.Size * spriteBody.Pivot * 0.3f - Vector2.UnitX * 10;
// ordered
SendToFront(spriteHead);
SendToFront(spriteArmLeft1);
SendToFront(spriteArmRight1);
// Rotation slider
Slider sliderAngle = new Slider() { Pivot = new Vector2(0.5f, 1.0f) };
sliderAngle.ValueChangeEvent += (s) =>
{
spriteBody.Rotation = MathHelper.ToRadians(sliderAngle.Value * 3.60f);
};
AddComponent(sliderAngle, Preferences.ViewportManager.BottomCenterAnchor);
///////// DEFEND ANIMATION ////////
// Animaciones
Animation animationDefendHead = Animation.CreateAnimation(9);
animationDefendHead.AnimationType = AnimationType.Relative;
animationDefendHead.AddKey(new KeyFrame(0, Vector2.Zero));
animationDefendHead.AddKey(new KeyFrame(2, -Vector2.UnitX * 2));
animationDefendHead.AddKey(new KeyFrame(4, Vector2.Zero));
animationDefendHead.AddKey(new KeyFrame(6, Vector2.UnitX * 2));
animationDefendHead.AddKey(new KeyFrame(8, Vector2.Zero));
animationDefendHead.FramePerSeconds = 10;
AddAnimation(animationDefendHead);
//Some variables to use in animations
float degree = 45f;
int framesDefend = 30;
int waitfps = 60;
Animation animationDefendLeftArm = Animation.CreateAnimation(framesDefend);
animationDefendLeftArm.AnimationType = AnimationType.Relative;
animationDefendLeftArm.AddKey(new KeyFrame(0, Vector2.Zero, 0.0f, 1.0f));
animationDefendLeftArm.AddKey(new KeyFrame((int)(0.5f * framesDefend), Vector2.Zero, MathHelper.ToRadians(degree), 1.0f));
animationDefendLeftArm.AddKey(new KeyFrame(framesDefend - 1, Vector2.Zero, 0.0f, 1.0f));
animationDefendLeftArm.FramePerSeconds = waitfps;
AddAnimation(animationDefendLeftArm);
Animation animationDefendRightArm = Animation.CreateAnimation(framesDefend);
animationDefendRightArm.AnimationType = AnimationType.Relative;
animationDefendRightArm.AddKey(new KeyFrame(0, Vector2.Zero, 0.0f, 1.0f));
animationDefendRightArm.AddKey(new KeyFrame((int)(0.5f * framesDefend), Vector2.Zero, MathHelper.ToRadians(-degree), 1.0f));
animationDefendRightArm.AddKey(new KeyFrame(framesDefend - 1, Vector2.Zero, 0.0f, 1.0f));
animationDefendRightArm.FramePerSeconds = waitfps;
AddAnimation(animationDefendRightArm);
///////// RIGHT ATTACK ANIMATION ///////
int rpfps = 60;
int frames = 20;
// body
Animation animationAttackPunchBody = Animation.CreateAnimation(frames);
animationAttackPunchBody.AnimationType = AnimationType.Relative;
animationAttackPunchBody.AddKey(new KeyFrame(0, Vector2.Zero, 0.0f, 1.0f));
animationAttackPunchBody.AddKey(new KeyFrame((int)(frames * 0.5), -Vector2.UnitX * 20, MathHelper.ToRadians(-85), 1.0f));
animationAttackPunchBody.AddKey(new KeyFrame(frames - 1, Vector2.Zero, 0.0f, 1.0f));
animationAttackPunchBody.FramePerSeconds = rpfps;
AddAnimation(animationAttackPunchBody);
//.........这里部分代码省略.........
示例2: Initialize
/// <summary>
/// Sets the screen up (UI components, multimedia content, etc.)
/// </summary>
public override void Initialize()
{
base.Initialize();
// Background
SetBackground(ResourceManager.CreateImage("Images/background_ios"), Screen.Adjustment.CENTER);
// Sprite sheet image
SpriteSheet iSpriteSheet = ResourceManager.CreateSpriteSheet("Images/PigeonsAttackSpriteSheet");
// Pigeons
Sprite[] lPigeons = new Sprite[5];
Image iPigeonLookingAtLeft = iSpriteSheet["pigeon_1"];
Image iPigeonLookingAtRight = iSpriteSheet["pigeon_2"];
random = new Random();
lPigeons[0] = new Sprite("pigeon", iPigeonLookingAtLeft);
lPigeons[1] = new Sprite("pigeon", iPigeonLookingAtLeft);
lPigeons[2] = new Sprite("pigeon", iPigeonLookingAtRight);
lPigeons[3] = new Sprite("pigeon", iPigeonLookingAtLeft);
lPigeons[4] = new Sprite("pigeon", iPigeonLookingAtRight);
AddComponent(lPigeons[0], 79, 12);
AddComponent(lPigeons[1], 207, 15);
AddComponent(lPigeons[2], 345, 16);
AddComponent(lPigeons[3], 495, 16);
AddComponent(lPigeons[4], 634, 7);
// Car
cCar = new Sprite("cCar", Image.CreateImage(Color.Transparent, 238, 164));
// Car itself
lCar = new Sprite("car", iSpriteSheet["car"]);
cCar.AddChild(lCar);
// Tires
Image iTire = iSpriteSheet["steel"];
lLeftTire = new Sprite("lLeftTire", iTire) { Position = new Vector2(70, 138), Pivot = Vector2.One / 2};
cCar.AddChild(lLeftTire);
lRightTire = new Sprite("lRightTire", iTire) { Position = new Vector2(162, 138), Pivot = Vector2.One / 2 };
cCar.AddChild(lRightTire);
AddComponent(cCar, 11, 480 - 164 - 24);
if (AccelerometerSensor.Instance.IsConnected)
{
accelerometerDetected = true;
AccelerometerSensor.Instance.Start();
}
#region Shits
Image iShit = iSpriteSheet["shit"];
lShit = new Sprite("shit", iShit) { Pivot = Vector2.One / 2};
// The shit will be hidden since the very begining, so doesn't matter where to place it
AddComponent(lShit, -100, -100);
lShit.Visible = false;
shitPositions = new Vector2[5];
shitPositions[0] = new Vector2(135, 63);
shitPositions[1] = new Vector2(267, 70);
shitPositions[2] = new Vector2(367, 70);
shitPositions[3] = new Vector2(553, 70);
shitPositions[4] = new Vector2(657, 63);
elapsedTimeBetweenShits = TimeSpan.Zero;
// 60 will cause the animation to take 1 s to complete
aShitFalling = Animation.CreateAnimation(75);
aShitFalling.AnimationType = AnimationType.Relative;
aShitFalling.AddKey(new KeyFrame(0, Vector2.Zero));
aShitFalling.AddKey(new KeyFrame(aShitFalling.NumFrames - 1, new Vector2(0, 400)));
// Once the shit touches the road it must dissapear
aShitFalling.EndEvent += delegate { lShit.Visible = false; };
AddAnimation(aShitFalling);
#endregion Shits
// Semaphore lights
lRed = new Sprite("red", iSpriteSheet["red"]);
AddComponent(lRed, 716, 187);
lAmber = new Sprite("amber", iSpriteSheet["amber"]);
AddComponent(lAmber, 715, 215);
lGreen = new Sprite("green", iSpriteSheet["green"]);
AddComponent(lGreen, 717, 241);
lAmber.Visible = lGreen.Visible = false;
// This var will hold the playing time
elapsedGameTime = TimeSpan.Zero;
#if DEBUG
lLog = new Label("N/A", Color.Black, Color.White);
AddComponent(lLog, Preferences.ViewportManager.TopLeftAnchor);
#endif
impacts = 0;
minClamp = 11;
// The car won't overpass the semaphore until it turns green
//.........这里部分代码省略.........