2013年4月23日 星期二

[Windows 8] How to show or hide the components with windows store app by C#

Example

private void PlayMedia(object sender, MouseButtonEventArgs args)
{
    pauseBTN.Visibility = Visibility.Visible;
    playBTN.Visibility = Visibility.Collapsed;

    media.SpeedRatio = 1.0;
    media.Play();
}

XAML Attribute Usage

<uiElement Visibility="Visible" .../>
or
<uiElement Visibility="Collapsed" .../>
The default value is Visible

UIElement.Visibility Property

Member name
Description
Visible Display the element.
Collapsed Do not display the element

reference:

[Windows 8] How to create a login screen in Windows Store App by C#


Today, I will show you how to create a login screen in Windows Style Application by C#.

The result in the following shown:
Firstly, create the xaml page and add the codes:

<Page x:Class="FacebookDemo.FacebookLogin" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:FacebookDemo" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d">

    <ContentControl x:Name="container" Height="450" Margin="0,194,0,124">
        <Popup x:Name="logincontrol" IsOpen="False" >
           <StackPanel Orientation="Vertical" Background="#3F000000" Height="400" x:Name="pop" > 
               <WebView Name="WebView" Width="450" Height="400" Loaded="WebView_Loaded" /> 
           </StackPanel>
        </Popup>
    </ContentControl>
</Page>

and then add the codes into xaml.cs construct:
namespace FacebookDemo
{
    public sealed partial class FacebookLogin : Page
    {
 ...
        public FacebookLogin()
        {
     ... 
            this.InitializeComponent();

            container.IsEnabled = true;
            logincontrol.IsOpen = true;
            pop.Width = Window.Current.Bounds.Width;
        }
 ...
    }
}

Secondly, I add the codes to show popup windows in the main page:
namespace FacebookDemo
{
    ...
    public sealed partial class MainPage : FacebookDemo.Common.LayoutAwarePage
    {
 ...
        Popup popup = new Popup();
        public MainPage()
        {
            this.InitializeComponent();
            popup.Child = new FacebookLogin();
            popup.VerticalOffset = 0;
            popup.HorizontalOffset = 0;
            popup.Width = Window.Current.Bounds.Width;
            popup.Height = Window.Current.Bounds.Height;

            popup.IsOpen = true;
            IsEnabled = false;
            App.fbevents.FBEvent += fbevents_FBEvent;
     ...
        }
        ...
        void fbevents_FBEvent(object sender, string accesscode)
        {
            IsEnabled = true;
            ...
        }
    }
}

When the popup windows is shown, the main page should set IsEnable to false. When the popup windows is closed, the main page must set  IsEnable to true.

[Windows 8] How to use the timer in the Windows Store Application by C#

// defines
private DispatcherTimer _timer;

// Init
_timer= new DispatcherTimer();
_timer.Tick += _timer_Tick;
_timer.Interval = new TimeSpan(0, 0, 1);

...
_timer.Start();                 // start timer


private void _timer_Tick(object sender, object e)
{
   // do something
}

_timer.Stop();                 // stop timer
_timer.Tick -= _timer_Tick;    // delete function reference

Reference:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dispatchertimer(v=win.10).aspx

2013年4月21日 星期日

[Android] 如何使用Ellispe開啟AndEngine遊戲引擎程式庫

- 首先下載AndEngine 原始碼的存放處: http://code.google.com/p/andengine
- 開啟Ellipse, File > New > Project > Android> Android Project from Existing Code

- 在New Project對話視窗中按"Next",出現Import Project的對話視窗,按下Browse...,找到下載AndEngine 原始碼的路徑

- 按下"Finish",專案完成如下圖

- 在Project的Properties\Android\Project build Target,選擇Android 4.1.2, 且在Library欄位勾選"Is library",然後按"Apply"鍵設定選取的項目

- 在Project的Properties\Java Build Path,勾選Android 4.1.2,然後按"OK"鍵,完成設定。

[Android] How to use Ellispe open AndEngine game engine library

First, get AndEngine source download reference: http://code.google.com/p/andengine
Open the Ellipse, File \ New \ Project \ Android \ Android Project from Existing Code

In the New Project dialog window, press the "Next", and Import Project of dialog is shown. In this dialog, press "Browse ..." to set the downloaded path of AndEngine source.

Press "Finish", completion of the opening project as shown below

In the Project \ Properties \ Android \ Project build Target, select Android 4.1.2, and check "Is library in the Library field, and then press the "Apply" button to set the selected item.

In the Project Properties \ Java Build Path, check the Android 4.1.2, then press the "OK" button to complete the setting.

[Android] 如何成功執行"Learning Android Game Programming" 書上的例子


這篇文章主要是在學習過程中遇到的問題,記下來分享給大家。首先,在
    http://www.informit.com/title/9780321769626
下載書上的例子,使用Ellipse開啟並執行程式,一開始出現一片黑的畫面,最後專案已停止的訊息(如下圖),程式無法正常執行的問題。

解決方法:

- 開啟Example,以chapter_2_code\V302為例,開啟Ellipse, File > New > Project > Android> Android Project from Existing Code

- 在New Project對話視窗中按"Next",出現Import Project的對話視窗,按下Browse...,設定Root Directory。

- 按下"Finish",專案開啟(如下圖)。

- 設定StartActivity專案的Properties,在Package Explorer\右鍵\Properties\Android\Project build Target, 選擇Android 2.2,然後按"Apply"鍵設定選取的項目

- 在Project的Properties\Java Build Path, 勾選Android 2.2,andengine.jar - StartActivity/lib,Android Dependencies,然後按"OK"鍵完成設定,

- 然後執行程式,正確出現我們要的結果


[Android] How to run successfully the example apps in "Learning Android Game Programming" book


This article is mainly the problems encountered in the learning process, write it down for everyone to share. First, get the book examples' source:
    http://www.informit.com/title/9780321769626
Download the book example, and then using the Ellipse open and run the program. We see the result shown a message (see below) began to appear a black screen, and finally the project has stopped, running properly.

Solution:

This is the description by chapter_2_code \ V302 example.The Ellipse is opened File> New> Project> Android> Android Project from Existing Code

In the New Project dialog window, press "Next", then appear the Import Project of dialogue window, click "Browse ..." to set the Root Directory.

Press "Finish" project is open (see below).

Set StartActivity project in the Package Explorer \ right mouse\ Properties \ Android \ Project build Target, select Android 2.2, and then press the "Apply" button to set the selected item

In the Project Properties \ Java Build Path, check the Android 2.2 andengine.jar - startActivity / lib Android Dependencies, and then press the "OK" button to complete the setting.

Then run the program, we want correctly