Skip to content

Commit

Permalink
CocosSharp - UI render with custom render command, background TestLay…
Browse files Browse the repository at this point in the history
…er example
  • Loading branch information
EmptyKeys committed Aug 20, 2015
1 parent 397dc52 commit 6cc00a0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions BasicUI_CocosSharp/BasicUI_CocosSharp/AppDelegate.cs
Expand Up @@ -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);
Expand Down
Expand Up @@ -65,6 +65,7 @@
<Compile Include="IntroLayer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestLayer.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\hd\animations\" />
Expand Down
Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions BasicUI_CocosSharp/BasicUI_CocosSharp/IntroLayer.cs
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
}
Expand All @@ -75,7 +83,7 @@ void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
{
// Perform touch handling here
}
}
}
}
}

18 changes: 18 additions & 0 deletions 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;
}
}
}
2 changes: 1 addition & 1 deletion BasicUI_CocosSharp/UserInterface/BasicUI.xaml
Expand Up @@ -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">

<!-- User can define style for his root control -->
<!--ek:UIRoot.Style>
Expand Down

0 comments on commit 6cc00a0

Please sign in to comment.