Skip to content

Instantly share code, notes, and snippets.

@kw0006667
kw0006667 / HelloWorldScene.h
Created October 11, 2012 04:33
Add sprite to your scene(.h)
class HelloWorld : public cocos2d::CCLayer
{
private:
CCSprite *charlie;
float totalTime;
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
@kw0006667
kw0006667 / HelloWorldScene.cpp
Created October 11, 2012 12:50
Add sprite to your scene(.cpp)
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
@kw0006667
kw0006667 / HellowWorldScene.cpp
Created October 11, 2012 12:53
Add sprite by plist
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("Charlie_plist.plist");
@kw0006667
kw0006667 / HeaderMenuControl.xaml
Created October 20, 2012 10:34
使用者控制項
<UserControl
x:Class="HeaderMenu.HeaderMenuControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HeaderMenu"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="180"
d:DesignWidth="300">
@kw0006667
kw0006667 / HeaderMenuControl.xaml
Created October 20, 2012 17:57
自訂 Header Menu 使用者控制項
<UserControl
x:Class="HeaderMenu.HeaderMenuControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HeaderMenu"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="210"
d:DesignWidth="250">
@kw0006667
kw0006667 / MainPage.xaml
Created October 20, 2012 18:00
在主頁面新增一個 Page Title
<Page
x:Class="HeaderMenu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HeaderMenu"
xmlns:common="using:HeaderMenu.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
@kw0006667
kw0006667 / MainPage.xaml.cs
Created October 20, 2012 18:03
在主頁面的程式碼中,加入控制項的呼叫
public sealed partial class MainPage : Page
{
public Popup headerMenuPopup;
// 自訂的控制項
public HeaderMenuControl headerMenuCtl;
// 是否已加入到 Popup 物件中
public bool isAddedToPopup;
@kw0006667
kw0006667 / MainPage.xaml.cs
Created October 20, 2012 18:07
將點擊選單後,會將選單關閉的事件寫入
private void pageTitle_Click_1(object sender, RoutedEventArgs e)
{
// 若是第一次按,則將物件新增到 Popup 物件裡。
if (!this.isAddedToPopup)
{
this.headerMenuPopup = ShowPopup(this.pageTitle, this.headerMenuCtl);
this.headerMenuCtl.Tapped += headerMenuCtl_Tapped;
this.isAddedToPopup = true;
}
// 顯示 Popup
@kw0006667
kw0006667 / Program.cs
Created October 23, 2012 17:15
10個學生的成績
namespace ListConsoleApp
{
public class Student
{
public string Name;
public int Score;
public Student(string name, int score)
{
this.Name = name;
this.Score = score;
@kw0006667
kw0006667 / gist:3940880
Created October 23, 2012 19:04
將學生分數由高到低排序
students.Sort((x, y) => { return -x.Score.CompareTo(y.Score); });