Win2D Learning Series (1): Hello Win2D, win2dhello

Source: Internet
Author: User

Win2D Learning Series (1): Hello Win2D, win2dhello

The first time I saw win2d was an article in IT house in September. Microsoft pushed Win8.1/WP8.1 universal Win2D API, and accelerated graphics. According to the description, win2d api uses C # To obtain the GPU graphics acceleration function of Direct2D. It is a long-awaited experience for developers who want to develop games in win8.1 and wp8.1. However, at that time, I did not have a deep understanding of the work relationship. Until recently, I carefully read win2D documents and used win2d to develop a pixel bird beta test. Haha, the game is small, but it is also dirty.

Since XNA is no longer updated and VS2013 is no longer integrated with XNA templates, developers of WP game development are faced with difficult choices. Do they turn to C ++ and DirectX and invest in Unity3D? No matter which option you choose, there is no small learning cost. With the advent of win2d, I believe that we have a more direct choice to develop games in wp and win8.1. We can use the familiar C # For Development and GPU acceleration, win2d can also be perfectly integrated with xaml, making it easy for silverlight and xna developers to get started.

Let's get to know the mysterious win2d.

First, use VS2013 to create a general application (Win2d is not applicable to wp8 applications and WPF of silverlight ).

  

Add win2d from Nuget. The current version is 0.0.12:

  

In the Configuration Manager, we need to change the compilation platform to X86 (if debugging is performed on a real machine, we need to change it to ARM ):

  

Open MainPage. xaml and add reference to win2d namespace: xmlns: canvas = "using: Microsoft. Graphics. Canvas"

Add CanvasControl to the page layout:

  

<Page    x:Class="App1.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:App1"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    xmlns:canvas="using:Microsoft.Graphics.Canvas"    mc:Ignorable="d">    <Grid Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">        <canvas:CanvasControl Name="canvas"/>    </Grid></Page>

  

  

Open the MainPage. xaml. cs file:

Register the Draw event of CanvasControl In the constructor:

  

 public MainPage() {     this.InitializeComponent();     canvas.Draw += canvas_Draw; } void canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) {          }

  

  

Add the following code to the canvas_Draw method:

  

void canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args){       CanvasDrawingSession ds = args.DrawingSession;       ds.DrawText("Hello Win2D", 240, 180, Colors.White);}

  

  

 

 

Appendix:

  

1. Microsoft win2D Team Blog: Win2D Team Blog

2. api Documentation: Win2D Documentation

3, Win2D source code can be downloaded in Github: https://github.com/Microsoft/Win2D

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.