Better Silverlight resource sorting in codeproject of foreign websites 3-similar to the serialization-bubble breaker game

Source: Internet
Author: User

Introduction

It is great fun to work using the Silverlight technology, and it was a very
Exciting experience for me to develop a game for the Web. This article has good
Stuff for beginners who want to develop games using the Silverlight
Technology.

Bubble breaker is a puzzle game developed using Silverlight. Select bubbles
With the same color by clicking, and then destroy them by clicking again.
More you break with one click, the higher the score you get.

Draw bubble

The XAML ofBubbleControl is very simple. I used
CanvasControl as a container becauseCanvas
Control provides two positioning controls.CanvasContains
BorderControl as a child control, which allows to set the top and
Left coordinates easily. Finally,ButtonIs a child of
BorderControl which will draw the actual bubble shape.


Collapse Copy code
 <  Canvas  >  <  Border   X: Name  =" Canvasbubble"   Width  ="  26"  Height  ="  26"   Rendertransformorigin  ="  0.5, 0.5"  >  <  Button   X: Name  ="  Btnbubble"   Height  =" Auto"   Width  ="  Auto"  Style  ="  {Staticresource buttonstyleblue }"   Click  ="  Btnbubble_click"  Background  ="  Aliceblue"  Borderthickness  ="  0, 0, 0"   Horizontalalignment ="  Center"  Verticalalignment  ="  Center"  Mouseleave  ="  Btnbubble_mouseleave"   Cursor  ="  Hand"  Rendertransformorigin  ="  0.5, 0.5"  >  <  / Button  >  <  /  Border  >  <  /  Canvas  > 
Template and Style

In Silverlight, we can easily change the default shape of the controls. I
Changed the default shape ofButtonTo circle. Expression Blend
Provides an easy way to change/create templates for controls. Right click on
Element and select "Edit Control Parts (Template)" and then select "create
Empty ". It opens a dialog where you can give a name for the template and press
OK. Then, it shows the design view where the user can create/Change
Templates.

You can also create styles for controls in Silverlight. I set a style for
Button usingStyle = "{staticresource buttonstyleblue }"Property.
For creating a style, select a control from the "object and timeline" Panel and
Then click "object" from the menu, click on "Edit style" and then select "create"
Empty ". It opens a form where you can set the style.

Bubble breaker has five colors of bubbles, and I created a style for each
Color. I did not create a separate template. Each style has its own
Template.


Collapse Copy code
 <  Style   X: Key  ="  Buttonstyleblue"   Targettype  ="  Button"  >  <  Setter   Property ="  Background"   Value  ="  # Ff1f3b53"  /  >  <  Setter   Property  ="  Foreground"   Value  ="  # Ff000000"  /  >  < Setter   Property  ="  Padding"   Value  ="  3"  /  >  <  Setter   Property  ="  Borderthickness"   Value  ="  1"  / >  <  Setter   Property  ="  Borderbrush"  >  <  Setter. Value  >  <  Lineargradientbrush   Endpoint  ="  0.5, 1"   Startpoint  =" 0.5, 0"  >  <  Gradientstop   Color  ="  # Ffa3aeb9"   Offset  ="  0"  /  >  <  Gradientstop   Color  ="  # Ff8399a9"   Offset ="  0.375"  /  >  <  Gradientstop   Color  ="  # Ff718597"   Offset  ="  0.375"  /  >  <  Gradientstop   Color  =" # Ff617584"   Offset  ="  1"  /  >  <  /  Lineargradientbrush  >  <  /  Setter. Value  >  <  /  Setter  > <  Setter   Property  ="  Template"  >  <  Setter. Value  >  <  Controltemplate   Targettype  ="  Button"  >  <  Ellipse  Height  ="  25"   Width  ="  25"  Strokethickness  ="  1"   X: Name  ="  Ellipse"  Rendertransformorigin  ="  0.5, 0.5"  Stroke  ="  # Ff000000"  Margin  ="  0, 0, 0"  > ................ <  /  Ellipse  >  <  /  Controltemplate  >  <  /  Setter. Value  >  < /  Setter  >  <  /  Style  > 

You can easily set the control style at runtime.


Collapse Copy code
Switch(_ Bubblecolor ){CaseBubblecolor. Blue: {btnbubble. Style = (style) app. Current. Resources ["Buttonstyleblue"];Break;}CaseBubblecolor. RED: {btnbubble. Style = (style) app. Current. Resources ["Buttonstylered"];Break;}CaseBubblecolor. Green: {btnbubble. Style = (style) app. Current. Resources ["Buttonstylegreen"];Break;}}
Animate bubble

You can easily animate controls in Silverlight. Click on the "+" button. It
Opens a dialog where you give the name of the "story board ".
StoryboardIs a container where you can put animation objects.
StoryboardIs saved as a resource that is available to the object
That you want to animate.


Collapse Copy code
    usercontrol. resources       storyboard   X: name   = "  storyboardshakebubble"   repeatbehavior   = "  forever"    ............   /  storyboard      /  usercontrol. resources    

StoryboardProvidesBegin ()Method to start
Animation andStop ()Method To stop animation.


Collapse Copy code
 
If(Seleted) {storyboardshakebubble. Begin ();}Else{Storyboardshakebubble. Stop ();}
  

Original:

bytes Article : I put all the articles I have read in my blog. In this way, I will open my blog directly if I want to find an article. You can open the original article connection for download, but you need to register it. In order to facilitate the download, I have placed the source file below. We recommend that you save this website, which is really good for Silverlight enthusiasts. You must read more English articles. English is so important. It doesn't matter if you are not used to it at the beginning. We also recommend that you install a lingers dictionary.
Code download:/files/6666/bubblebreaker.pdf a video game. Zip

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.