Bacon and Games

Tag: as3 (page 1 of 3)

Lazy Thief Released on ArmorGames.com

This past Friday I released a new web-game called Lazy Thief on Armor Games. It’s a project I chipped away at over the course of about a year with artist and friend Ajay Karat of Devils Garage. It’s hardly the Mona Lisa, but given the circumstances I’m quite pleased with how it turned out.

I may write a post-mortem one day but for now I’m just enjoying the divine embrace of a recently completed project :D Mmmmmm

This is just a quick peek at a level editor for a mobile game I’m working on. It’s currently codenamed “Quad”.

This is just a quick demo of a concept I’m working on for a mobile game. I’m going to give it a working title of “Blip”. This demo shows touch controls that work much like the old Lunar Lander game where you fire thrusters to move your “craft”. In this case, touch left or right to move laterally. Touch both left and right to thrust up. The dropped frames are a result of the screen capture. The game itself is super smooth. More coming soon.

Simple AS3 Debug Window

Sometimes when you’re chasing down a bug, the quick and dirty ‘caveman debugging’ approach is easier than using an actual debugger with breakpoints and ‘all that happiness’ (as my father says). The trace() function is great for this, but if want to view flash traces in a web-browser you have to deal with the debug player and Flash-tracer setup. And if you want to get input from someone who doesn’t have those tools you’re out of luck.

The other day I found myself in the above situation and so I wrote up a very lightweight and VERY basic class called DebugWindow. It recreates the trace() functionality within your swf, by adding a “debug window” to the display list. To use it, just call its output() method instead of using trace()

This movie requires Flash Player 9

As you can see from the demo, you can use SHIFT + SPACE to hide/show the debug window. CTRL + UP/DOWN allows you to scroll to view older text. There are a few other helper functions that allow you to clear the window entirely or clear then output in one call. You can also set window size, text, background and border colors in the constructor. It’s all commented in the class.

If you’re not done with your project and still wish to use the debug window but don’t want users seeing it, set the enabled property to false. This will remove all event listeners, hide the window and block any output calls. It’s still recommended you remove all debug code from your project when finalized.

I considered adding features like a scroll bar, line numbers and some other stuff but at the end of the day this is just meant to be a light and dirty way to get some data out of your swf no matter where it’s running, test mode, browser, iPad… whatever.

Here’s the AS3 DebugWindow Class

Oh and in case you’re wondering, I grabbed the bacon facts and Nintendo facts from these two sites… much more interesting than using Math.random()*5000 :P

Find All Strings Within a String with AS3

I’m working on a training simulator that allows people to virtually highlight text (like in iBooks) in a textField. I’ll probably post the code for the highlighting portion when the project is done.

For now, I thought I’d post this simple AS3 utility function I wrote, which allows you to find all instances of string inside another string. It accepts two arguments:

  • searchFor:String – string you wish to search FOR
  • searchIn:String – string you wish to search IN
  • caseSensitive:Boolean=true – (optional) determines whether comparisons are case sensitive

It will return an array containing the indices at which searchFor is found in searchIn. You can check the length of the array returned to get the number of times the search string appears in the search text. If the length is 0, searchFor does not appear in searchIn.

package com.baconandgames.utils{
public class Strings{
 
// returns an array of indexes for each occurance of searchFor in searchString
// var s:String = "Haw many cats are in this sentence about cats?";
// Strings.findAllStringsInString("cats",s); // returns [9,41];
 
public static function findAllStringsInString(searchFor:String,searchIn:String,caseSensitive:Boolean=true):Array{   
  if(!caseSensitive){             
    searchFor = searchFor.toLocaleLowerCase();        
    searchIn = searchIn.toLocaleLowerCase();   
  }       
  var a:Array = new Array();       
  var i:int = -1;     
  while ((i = searchIn.indexOf(searchFor, i+1)) != -1) a.push(i);      
  return a;
}
}

*simplified with suggestions by my good buddy and web-ninja Rob Colburn

Olderposts

Copyright © 2024 Bacon and Games

Theme by Anders NorenUp ↑