Creating a Simple Windows 8 Game with JavaScript Part 4

Gauloran

Kıdemli Moderatör
7 Tem 2013
8,096
585
local
Adding the Remaining Assets

[FONT=&quot]
Now that you’ve seen how to add the background. It’s mostly a matter of repetition to include the others (with a bit more math thrown in.) Head back to default.js and include the following in prepareGame():[/FONT]​
[FONT=&quot]
image026.png
[/FONT]​
[FONT=&quot]
A few notes on this:[/FONT]

  • The catapults appear at "ground level" which we need to scale along with the overall size of the images
  • Drawing player 2’s catapult is tricky because we need it to face the other direction. Using regX to set a transform point and setting a negative scale gets the job done.
  • We create and add the ammo (boulder) image, but hide it until it’s fired later.
Adding Some Text

[FONT=&quot]
To wrap things up for this post, let’s use EaselJS’s Text class to add a game title along with indicators for each player’s remaining catapults. First, we’ll need a few variables near the top of default.js:[/FONT]​
[FONT=&quot]
image027.png
[/FONT]​
[FONT=&quot]
Then, add the following to prepareGame();[/FONT]​
[FONT=&quot]
image028.png
[/FONT]​
[FONT=&quot]
To the Stage, Text instances are children just like the Bitmaps we added earlier.[/FONT]​
[FONT=&quot]
What does the game look like now?[/FONT]​
[FONT=&quot]
image029.png
[/FONT]​
What’s Next?

[FONT=&quot]
Things are looking pretty good, but unfortunately that’s about it – nothing’s moving. In the next post, we’ll dive in to the game’s mechanics, fleshing out the game loop by adding motion, collision detection, scorekeeping, and the endgame.[/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.