Creating a Simple Windows 8 Game with JavaScript Part 2

Gauloran

Kıdemli Moderatör
7 Tem 2013
8,119
599
local
Adding the HTML5 Canvas

[FONT=&quot]
First, we’re going to need something to display the game. The HTML5 canvas element is essentially a sandbox of pixels that you can draw to dynamically. We’re going to use a canvas to render the game, so we need to add it to our HTML page. Open default.html and replace Line 17 (the "Content goes here" line) with a canvas tag, so it looks like this:[/FONT]​
[FONT=&quot]
image013.png
[/FONT]​
[FONT=&quot]
Normally, you’d specify width & height and add fallback content in case canvas isn’t supported, but we’ll set width/height later and we know canvas will be supported. However, this is just one of the many times you should consider coding practices in case you want to reuse some of your app code as a traditional web application – but that’s a story for another series of posts...[/FONT]​
Making Things Easier with CreateJS

[FONT=&quot]
So how do we add things like our background and catapults? Unlike HTML content, canvas content is entirely created via JavaScript instructions. For the basics, read "How to draw on an HTML5 canvas" on MSDN.[/FONT]​
[FONT=&quot]
Of course, we could use canvas methods to draw our game directly, but there are libraries of JavaScript out there to help, including ones well-suited to game development. CreateJS is a set of JavaScript libraries & tools, including EaselJS, PreloadJS, and others. We’ll use these in our game, so download EaselJS and PreloadJS, create a new folder for them as /js/CreateJS, and copy in the scripts (from the "lib" folders) as follows:[/FONT]​
[FONT=&quot]
image013.png
[/FONT]​
[FONT=&quot]
Adding the JavaScript files to the project isn’t enough to use them, so reference them from default.html:[/FONT]​
[FONT=&quot]
image014.png
[/FONT]​
[FONT=&quot]
Tip: You can add script references by dragging the script from Solution Explorer onto the page. (Extra Tip: in HTML5, you don't need the type="text/javascript" script attribute anymore.)[/FONT]​
[FONT=&quot]
We’ll use PreloadJS to help load assets before to use in the game and EaselJS to make it easier to manage the game loop and the drawing of image assets.[/FONT]​
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.