From 6cc00a05f41f903ee54390edb03d5f6d67891c76 Mon Sep 17 00:00:00 2001 From: Empty Keys Date: Thu, 20 Aug 2015 11:31:05 +0200 Subject: [PATCH] CocosSharp - UI render with custom render command, background TestLayer example --- .../BasicUI_CocosSharp/AppDelegate.cs | 2 ++ .../BasicUI_CocosSharp.csproj | 1 + .../GeneratedUI/BasicUI.xaml.cs | 1 + .../BasicUI_CocosSharp/IntroLayer.cs | 16 ++++++++++++---- .../BasicUI_CocosSharp/TestLayer.cs | 18 ++++++++++++++++++ BasicUI_CocosSharp/UserInterface/BasicUI.xaml | 2 +- 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 BasicUI_CocosSharp/BasicUI_CocosSharp/TestLayer.cs diff --git a/BasicUI_CocosSharp/BasicUI_CocosSharp/AppDelegate.cs b/BasicUI_CocosSharp/BasicUI_CocosSharp/AppDelegate.cs index a3a781f..1251a6b 100644 --- a/BasicUI_CocosSharp/BasicUI_CocosSharp/AppDelegate.cs +++ b/BasicUI_CocosSharp/BasicUI_CocosSharp/AppDelegate.cs @@ -42,7 +42,9 @@ public override void ApplicationDidFinishLaunching(CCApplication application, CC var scene = new CCScene(mainWindow); var introLayer = new IntroLayer(); + var testLayer = new TestLayer(); + scene.AddChild(testLayer); scene.AddChild(introLayer); mainWindow.RunWithScene(scene); diff --git a/BasicUI_CocosSharp/BasicUI_CocosSharp/BasicUI_CocosSharp.csproj b/BasicUI_CocosSharp/BasicUI_CocosSharp/BasicUI_CocosSharp.csproj index c60e003..0492671 100644 --- a/BasicUI_CocosSharp/BasicUI_CocosSharp/BasicUI_CocosSharp.csproj +++ b/BasicUI_CocosSharp/BasicUI_CocosSharp/BasicUI_CocosSharp.csproj @@ -65,6 +65,7 @@ + diff --git a/BasicUI_CocosSharp/BasicUI_CocosSharp/GeneratedUI/BasicUI.xaml.cs b/BasicUI_CocosSharp/BasicUI_CocosSharp/GeneratedUI/BasicUI.xaml.cs index 3ecb919..8eb9778 100644 --- a/BasicUI_CocosSharp/BasicUI_CocosSharp/GeneratedUI/BasicUI.xaml.cs +++ b/BasicUI_CocosSharp/BasicUI_CocosSharp/GeneratedUI/BasicUI.xaml.cs @@ -78,6 +78,7 @@ public partial class BasicUI : UIRoot { } private void InitializeComponent() { + this.Background = new SolidColorBrush(new ColorW(255, 255, 255, 0)); this.FontSize = 13.33333F; this.SetResourceReference(SoundManager.SoundsProperty, "Sounds"); InitializeElementResources(this); diff --git a/BasicUI_CocosSharp/BasicUI_CocosSharp/IntroLayer.cs b/BasicUI_CocosSharp/BasicUI_CocosSharp/IntroLayer.cs index 2841b5a..5ea6cc2 100644 --- a/BasicUI_CocosSharp/BasicUI_CocosSharp/IntroLayer.cs +++ b/BasicUI_CocosSharp/BasicUI_CocosSharp/IntroLayer.cs @@ -16,13 +16,15 @@ public class IntroLayer : CCLayerColor private BasicUI root; private DebugViewModel debug; private float elapsedGameTime; + private CCCustomCommand renderCommand; public IntroLayer() { // setup our color for the background - Color = new CCColor3B(CCColor4B.Blue); - Opacity = 255; - } + Color = new CCColor3B(CCColor4B.Red); + Opacity = 0; + renderCommand = new CCCustomCommand(RenderUI); + } protected override void AddedToScene() { @@ -65,6 +67,12 @@ private void UpdateUI(float frameTimeInSeconds) protected override void VisitRenderer(ref CCAffineTransform worldTransform) { base.VisitRenderer(ref worldTransform); + + Renderer.AddCommand(renderCommand); + } + + private void RenderUI() + { root.Draw(elapsedGameTime); debug.Draw(); } @@ -75,7 +83,7 @@ void OnTouchesEnded(List touches, CCEvent touchEvent) { // Perform touch handling here } - } + } } } diff --git a/BasicUI_CocosSharp/BasicUI_CocosSharp/TestLayer.cs b/BasicUI_CocosSharp/BasicUI_CocosSharp/TestLayer.cs new file mode 100644 index 0000000..e6a7b14 --- /dev/null +++ b/BasicUI_CocosSharp/BasicUI_CocosSharp/TestLayer.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CocosSharp; + +namespace BasicUI_CocosSharp +{ + public class TestLayer : CCLayerColor + { + public TestLayer() + { + Color = new CCColor3B(CCColor4B.Blue); + Opacity = 255; + } + } +} diff --git a/BasicUI_CocosSharp/UserInterface/BasicUI.xaml b/BasicUI_CocosSharp/UserInterface/BasicUI.xaml index ba5fa05..3264ead 100644 --- a/BasicUI_CocosSharp/UserInterface/BasicUI.xaml +++ b/BasicUI_CocosSharp/UserInterface/BasicUI.xaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ek="clr-namespace:EmptyKeys.UserInterface.Designer;assembly=EmptyKeys.UserInterface.Designer" mc:Ignorable="d" - d:DesignHeight="640" d:DesignWidth="800" FontSize="10pt" ek:SoundManager.Sounds="{DynamicResource Sounds}"> + d:DesignHeight="640" d:DesignWidth="800" FontSize="10pt" ek:SoundManager.Sounds="{DynamicResource Sounds}" Background="Transparent">