Windows Phone 7 development

Posts tagged ‘Programming’

Drawin cool simple text in XNA

I was wondering how to use some cool font in my XNA game. I came up with an idea to draw white and black text with an offset to give it “3d” look.

Here is the result:

Image

I made extension methods for SpriteBatch  that write this kind of text

public static class ExtensionMethods   
{       /// <summary>
        /// Draws white text with a black stroke
        /// </summary>
        public static void DrawStringBlackAndWhite(this SpriteBatch spriteBatch, SpriteFont smallFont, String text, Vector2 position)
        {
            spriteBatch.DrawStringWithStroke(smallFont, text, position, Color.White, Color.Black);
        }

        /// <summary>
        /// Draws white text with a black stroke
        /// </summary>
        public static void DrawStringBlackAndWhite(this SpriteBatch spriteBatch, SpriteFont smallFont, StringBuilder text, Vector2 position)
        {
            spriteBatch.DrawStringWithStroke(smallFont, text, position, Color.White, Color.Black);
        }

		/// <summary>
		/// Draws string with a stroke on up and right side of text
		/// </summary>
		public static void DrawStringWithStroke(this SpriteBatch spriteBatch, SpriteFont smallFont, String text, Vector2 position, Color color, Color stroke)
		{
			spriteBatch.DrawString(smallFont, text, position, stroke);
			spriteBatch.DrawString(smallFont, text, new Vector2(position.X - 1, position.Y + 1), color);
		}

		/// <summary>
		/// Draws string with a stroke on up and right side of text
		/// </summary>
		public static void DrawStringWithStroke(this SpriteBatch spriteBatch, SpriteFont smallFont, StringBuilder text, Vector2 position, Color color, Color stroke)
		{
			spriteBatch.DrawString(smallFont, text, position, stroke);
			spriteBatch.DrawString(smallFont, text, new Vector2(position.X - 1, position.Y + 1), color);
		}
	}

Advertisements

statically typed vs dynamically typed – How to get 90% discount.

There are a lot pros and cons of diffrent typing, yet on the one hand static typing wins – security. Yes both can be more or less secure buy static typing tells you a lot about your code and prevents from bugs, certain types of bugs. Do you want to buy a new flashy notebook with 90% discount? Everybody does 🙂

  1. find a victim. Website with on-line shop.
  2. Pick your laptop and start the order
  3. In this process fill out the amount textbox with value ‘.1’ (dot and one)

Since most of the systems calculate the final value of bill :

ValueOfOneLaptop x AmountOfLaptops = TotalAmount

If there is no valiadtion upon floating point TotalAmout will be 10% of a laptop’s value. How? .1 stands for 0.1 and therefore  0.1 gives you 90% discount :). Most likely shop engine is wirtten in PHP or Python so you have a lot of chance to get it pass through. A shop employee validates the order  and will not spot the little dot.

Brilliant isn’t it?

Web Devs need to bare in mind this.

Static vs Dynamic 1:0.

Ps Cheating is bad mkay

Tips about WP7

A few tips that make your life easer.

General

  1. Run your Visual Studio as an administrator (Right-click -> run as administrator) to get better FPS.
  2. Do not place IsTrial() in a loop. It take 60ms or more to return.
  3. Code generation in the compact framework is not the same as  Windows’ code. Jitter is optimized to run fast, not to produce the fastest code.
  4. Property is just a function for .Net CF.

Emulator

  1. To input text into emulator press Page-up (while editing a texbox f.e.) and then use your keybord to enter some text.
  2. Use F9 and F10 to change the volume

Marketplace

  1. To see app on marketplace if you are not from the country that has own marketplace go to Control Panel -> Location and change it to United States.
  2. Do not use transparent images at all!
  3. http://stackoverflow.com/questions/4141186/tips-for-a-successful-windows-phone-7-marketplace-submission

Silverlight

  1. Take as much as you can from Compositor Thread (for callback animations use BitmapCache).
  2. Use Canvas or custom popup instead of default one (Popup class) – lack of hardware acceleration.
  3. If your app loads very fast get rid off the spash screen.

XNA

  1. Use DXT format for textures and pack them into 1 file (faster loading and fewer GPU texture switches).
  2. For things like game stats avoid using strings( immutable). SpriteBatch.DrawString can take a StringBuilder directly for drawing text.
  3. Avoid using/abusing LINQ and foreach (it may causes garbage).
  4. Use Jagged arrays( arrays of arrays) instead of 2d arrays.

More info

%d bloggers like this: