• Home
tudwaythecore.com
blog
  • Recent Posts

    • Detecting focus in flash player
    • BitmapData PerlinNoise
    • Creating bridges in APE part 2
    • Creating bridges in APE
    • SteerWheels 2
    • Creating a simple APE example
    • Design me some levels!
    • Finished Migrating
  • Recent Comments

    • tudway on Creating a simple APE example
    • Ellen on Creating a simple APE example
    • tudway on Detecting focus in flash player
    • Markel on Detecting focus in flash player
    • Shawn on Sound in flash cs3 part 2 – pause
  • Categories

    • APE
    • flash
    • game
    • platform
    • sound
    • tutorial
    • Uncategorized
  • Archives

    • May 2009
    • October 2008
    • September 2008
    • August 2008
    • May 2008
    • April 2008
    • March 2008
  •  

    March 2010
    M T W T F S S
    « May    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • games

    • Game Showcase
May 29

Detecting focus in flash player

flash, game, tutorial 2 Comments »

Have you ever wondered how games can detect if they are in focus? Well I'm going to show you anyway and it is a very useful function that i use in all my new projects.

I'm going to show you what i mean first.

Get Adobe Flash player

There should be a grey rectangle above. If you click it, you gain focus in the flash file until you click away, eg outside the swf, in the browser address bar or even out of the browser. when focus is gained the swf will go white.

This is because when the swf is not in focus i am creating a transparent block over the entire screen. Imagine it as pausing a game when the focus is lost.

I have created a universal function with a pause variable in the parameter so that you can easily pause a game or app when the focus is lost.

PLAIN TEXT
Actionscript:
  1. var p:Boolean=false;
  2. detectFocus(p);
  3. function detectFocus(pausevar:Boolean) {
  4. var focusm:MovieClip = new MovieClip();
  5. focusm.graphics.beginFill(0x000000, 0.6);
  6. focusm.graphics.drawRect(0,0,550,400);
  7. focusm.graphics.endFill();
  8. addChild(focusm)
  9. stage.addEventListener(Event.DEACTIVATE, notinfocus);
  10. stage.addEventListener(Event.ACTIVATE, infocus);
  11. function notinfocus(event:Event):void {
  12. pausevar=true;
  13. focusm.visible = true
  14. }
  15. function infocus(event:Event):void {
  16. pausevar=false;
  17. focusm.visible = false
  18. }
  19. }

line 1: Creating the pause variable that the detectfocus function changes, this is so the function can pause your game.

line 2: Calling the detectfocus function using the pause variable p.

line 3: setting up the constructor for the function with 1 variable, pausevar.

lines 4 - 8: creating the rectangle that goes over the top of the screen, for more help on the drawing api try this post note the alpha of the fill colour is 0.6 so it is transparent.

line 9: Adding an event listener for when the swf is not in focus which calls the function notinfocus.

line 10: Adding an event listener for when the swf is in focus which calls the function infocus surprisingly enough!

lines 11 - 14: Creating the notinfocus function which sets the pause variable to true and also makes the rectangle visible.

lines 15 - 18: Creating the in focus function that does exactly the opposite to the not in focus function, so it sets pause to false and makes the rectangle invisible.

Now lets see it in action for one of the new levels for steerwheels!

Get Adobe Flash player

Click inside to gain focus and then arrow keys to move. (you can't win yet)

Works well doesn't it!

May 26

BitmapData PerlinNoise

flash, game, tutorial No Comments »

I haven't posted in a while because i have been busy with other projects, which you will see soon.

I've decided to play with bitmapdata and see what it can be used for. I have used this effect in a game thats in production for the backgrounds because they look quite spacey. And its a quick way to get some awesome looking art without paying an artist.

First an example

Get Adobe Flash player

You should see a blue/green image that looks quite good, something you might find in a game.

PLAIN TEXT
Actionscript:
  1. import flash.display.Bitmap;
  2. import flash.display.BitmapData;
  3.  
  4. var seed:Number=Math.floor(Math.random()*100);
  5. var channels:uint=BitmapDataChannel.BLUE|BitmapDataChannel.GREEN;
  6. var myBitmapDataObject:BitmapData=new BitmapData(550,400,false, 0x00000000);
  7. myBitmapDataObject.perlinNoise(100, 80, 6, seed, false, true, channels, false, null);
  8. var myBitmap:Bitmap=new Bitmap(myBitmapDataObject);
  9. addChild(myBitmap);

Line 1 and 2: Importing the necessary classes needed in this example.

line 4: This is a random number between 1 and 100 that we use when creating the bitmap with perlin noise. This number can be any number but varying it changes the pattern produced.

line 5: Bitmapdata has 4 channels, red blue green and alpha, you can mix channels by using "|". This is what the perlin noise is made up of.

line 6: Creating a black bitmapdata that fills the whole stage. The parameters are : BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)

line 7: Creating a perlin noise over the top of the bitmapdata that we just created. This is what makes those cool effects, play around with the values and see what you get. the parameters are: perlinNoise(baseX:Number, baseY:Number, numOctaves:uint, randomSeed:int, stitch:Boolean, fractalNoise:Boolean, channelOptions:uint = 7, grayScale:Boolean = false, offsets:Array = null).

line 8: Creating the bitmap that will hold the bitmapdata that i created before so that i can display it on stage. You cant add bitmapdata directly to the stage.

line 9: Adding the bitmap to the stage so we can see it.

And thats all for now, i will be experimenting with this later.

Aug 24

Updating the site

flash, game No Comments »

Due to an increase in traffic i have moved my site tudway-experimental.com over to this new site, i am also using wordpress instead of iweb. Over the next few days i will move all of the content from the old site to this new one. So stay tuned!

Previous Entries
Powered by WordPress .::. Designed by SiteGround Web Hosting

cssandhtml