Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Fixed sneaky joystick on WP8
Browse files Browse the repository at this point in the history
  • Loading branch information
netonjm committed Aug 22, 2014
1 parent 0575a9d commit 00ad318
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 204 deletions.
7 changes: 3 additions & 4 deletions SneakyJoystick/example/Common/IntroLayer.cs
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using CocosSharp;
using CocosSharp.Extensions.SneakyJoystick;
using SneakyJoystickExample.Windows;

namespace SneakyJoystickExample.Common
{
Expand Down Expand Up @@ -103,9 +102,9 @@ public void InitializeMonkey()
#endregion Initialization


protected override void AddedToNewScene()
protected override void AddedToScene()
{
base.AddedToNewScene();
base.AddedToScene();

InitializeJoystick();
InitializeMonkey();
Expand All @@ -114,7 +113,7 @@ protected override void AddedToNewScene()
CurrentSprite = monkeySprite;
joystickPanel.Player = CurrentSprite;

CurrentSprite.Position = VisibleBoundsWorldspace.Center;
CurrentSprite.Position = Window.WindowSizeInPixels.Center;

CCSimpleAudioEngine.SharedEngine.PreloadEffect("sound_oso");

Expand Down
96 changes: 18 additions & 78 deletions SneakyJoystick/example/wp8/AppDelegate.cs
Expand Up @@ -6,96 +6,36 @@

namespace SneakyJoystickExample.WP8
{
public class AppDelegate : CCApplication
public class AppDelegate : CCApplicationDelegate
{

int preferredWidth = 800;
int preferredHeight = 480;
static CCWindow sharedWindow;

public AppDelegate(Game game, GraphicsDeviceManager graphics)
: base(game, graphics)
public static CCWindow SharedWindow
{

// disable the automatic media restore so we don't get a deadlock when the game
// first starts.
HandleMediaStateAutomatically = false;

// set the render viewport size
graphics.PreferredBackBufferWidth = preferredWidth;
graphics.PreferredBackBufferHeight = preferredHeight;

// Initialize the graphics

// this controls anti-aliasing
graphics.PreferMultiSampling = false;

get { return sharedWindow; }
}

/// <summary>
/// Implement for initialize OpenGL instance, set source path, etc...
/// </summary>
public override bool InitInstance()
{
return base.InitInstance();
}
public static CCSize DefaultResolution;

/// <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()
public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
{
//initialize director
CCDirector pDirector = CCDirector.SharedDirector;
pDirector.SetOpenGlView();


// 2D projection
pDirector.Projection = CCDirectorProjection.Projection2D;

var resPolicy = CCResolutionPolicy.ShowAll; // This will letterbox your game
application.ContentRootDirectory = "Content";
sharedWindow = mainWindow;
DefaultResolution = new CCSize(
application.MainWindow.WindowSizeInPixels.Width,
application.MainWindow.WindowSizeInPixels.Height);

CCDrawManager.SetDesignResolutionSize(preferredWidth,
preferredHeight,
resPolicy);
//mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);
//application.HandleMediaStateAutomatically = false;
//mainWindow.DisplayStats = true;

// turn on display FPS
//pDirector.DisplayStats = true;
CCScene scene = new CCScene(sharedWindow);
CCLayer layer = new IntroLayer(DefaultResolution);

// set FPS. the default value is 1.0/60 if you don't call this
pDirector.AnimationInterval = 1.0 / 60;

CCScene pScene = IntroLayer.Scene;

pDirector.RunWithScene(pScene);
return true;
}

/// <summary>
/// The function be called when the application enters the background
/// </summary>
public override void ApplicationDidEnterBackground()
{
// stop all of the animation actions that are running.
CCDirector.SharedDirector.Pause();

// if you use SimpleAudioEngine, your music must be paused
// CCSimpleAudioEngine.SharedEngine.PauseBackgroundMusic = true;
scene.AddChild(layer);
sharedWindow.RunWithScene(scene);
}

/// <summary>
/// The function be called when the application enter foreground
/// </summary>
public override void ApplicationWillEnterForeground()
{
CCDirector.SharedDirector.Resume();

// if you use SimpleAudioEngine, your background music track must resume here.
//CCSimpleAudioEngine.SharedEngine.PauseBackgroundMusic = false;

}
}
}
80 changes: 0 additions & 80 deletions SneakyJoystick/example/wp8/Game1.cs

This file was deleted.

23 changes: 3 additions & 20 deletions SneakyJoystick/example/wp8/GamePage.xaml.cs
Expand Up @@ -14,33 +14,16 @@ namespace SneakyJoystickExample.WP8
{
public partial class GamePage : PhoneApplicationPage
{
private Game1 _game;

// Constructor
public GamePage()
{
InitializeComponent();

_game = XamlGame<Game1>.Create("", this);

// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
CocosSharp.CCApplication.Create(new AppDelegate(), "", this);

}

// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
// // Set the page's ApplicationBar to a new instance of ApplicationBar.
// ApplicationBar = new ApplicationBar();

// // Create a new button and set the text value to the localized string from AppResources.
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);

// // Create a new menu item with the localized string from AppResources.
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}

}
}
19 changes: 15 additions & 4 deletions SneakyJoystick/example/wp8/SneakyJoystickExample.WP8.csproj
Expand Up @@ -25,7 +25,7 @@
<ValidateXaml>true</ValidateXaml>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<NuGetPackageImportStamp>976f25dc</NuGetPackageImportStamp>
<NuGetPackageImportStamp>4fc1929e</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -81,7 +81,6 @@
<Compile Include="GamePage.xaml.cs">
<DependentUpon>GamePage.xaml</DependentUpon>
</Compile>
<Compile Include="Game1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\AppResources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -114,14 +113,26 @@
<Link>Content\control\joystick_thumb.xnb</Link>
</Content>
<Content Include="..\Content\magic-beard.plist">
<Link>Content\magic-beard.plist</Link>
<Link>Content\animations\magic-beard.plist</Link>
</Content>
<Content Include="..\Content\magic-beard.xnb">
<Link>Content\magic-beard.xnb</Link>
<Link>Content\animations\magic-beard.xnb</Link>
</Content>
<Content Include="..\Content\sound_oso.xnb">
<Link>Content\sound_oso.xnb</Link>
</Content>
<Content Include="..\Content\SD\animations\AnimBear.plist">
<Link>Content\animations\AnimBear.plist</Link>
</Content>
<Content Include="..\Content\SD\animations\AnimBear.xnb">
<Link>Content\animations\AnimBear.xnb</Link>
</Content>
<Content Include="..\Content\SD\animations\monkey.plist">
<Link>Content\animations\monkey.plist</Link>
</Content>
<Content Include="..\Content\SD\animations\monkey.xnb">
<Link>Content\animations\monkey.xnb</Link>
</Content>
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml">
<SubType>Designer</SubType>
Expand Down
Expand Up @@ -177,14 +177,16 @@ public override void OnExit()

}

public void Draw()
protected override void Draw()
{
base.Draw();
CCDrawingPrimitives.Begin();
CCDrawingPrimitives.DrawRect(new CCRect(0, 0, this.ContentSize.Width, this.ContentSize.Height), CCColor4B.Blue);
CCDrawingPrimitives.End();
}




}
}
Expand Up @@ -208,9 +208,9 @@ public SneakyJoystickControl(CCRect rect) : base()

}

protected override void AddedToNewScene()
protected override void AddedToScene()
{
base.AddedToNewScene();
base.AddedToScene();

var rect = ControlSize;

Expand Down
Expand Up @@ -199,9 +199,9 @@ public SneakyPanelControl(CCSize visibleBoundsSize, int buttons) : base(visibleB

}

protected override void AddedToNewScene()
protected override void AddedToScene()
{
base.AddedToNewScene();
base.AddedToScene();

Opacity = DEFAULT_TRANSPARENCY;

Expand Down
14 changes: 1 addition & 13 deletions SneakyJoystick/src/SneakyJoystick/wp8/SneakyJoystick.WP8.csproj
Expand Up @@ -18,7 +18,7 @@
<ValidateXaml>true</ValidateXaml>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<NuGetPackageImportStamp>90bcf0af</NuGetPackageImportStamp>
<NuGetPackageImportStamp>7f20a0ae</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -84,12 +84,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\..\helpers\src\CCMathExHelper.cs">
<Link>Helpers\CCMathExHelper.cs</Link>
</Compile>
<Compile Include="..\..\..\..\helpers\src\CCPointExHelper.cs">
<Link>Helpers\CCPointExHelper.cs</Link>
</Compile>
<Compile Include="..\Common\ColoredCircleSprite.cs">
<Link>ColoredCircleSprite.cs</Link>
</Compile>
Expand All @@ -114,12 +108,6 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<ProjectExtensions />
<Import Project="..\packages\CocosSharp.PCL.Shared.1.0.0.0\build\wp8\CocosSharp.PCL.Shared.targets" Condition="Exists('..\packages\CocosSharp.PCL.Shared.1.0.0.0\build\wp8\CocosSharp.PCL.Shared.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\CocosSharp.PCL.Shared.1.0.0.0\build\wp8\CocosSharp.PCL.Shared.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CocosSharp.PCL.Shared.1.0.0.0\build\wp8\CocosSharp.PCL.Shared.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down

0 comments on commit 00ad318

Please sign in to comment.