Club Galactik is LIVE!!!
Posted on June 4, 2009
Filed Under Actionscript 3.0, General, Papervision | 3 Comments
I’m proud to tell everyone that the company where I work, VirtualFairground / BigwheelStudio, has released Club Galactik’s 3D Avatar Creator! Go check it and start creating your own Avatar! And do not forget to Keep checking the site cause there is a lot more to come!
Press release:
Virtual Fairground previews next generation virtual world and MMOG
Amsterdam, the Netherlands – Club Galactik (www.clubgalactik.com), home of the upcoming MMO game and virtual world based on animation hit series Galactik Football (www.galactikfootball.com) went live today. With the site already fully localized for multiple territories, kids and tweens from all over the world can now start creating their own Club Galactik characters. They can currently choose from three of the seven Galactik Football teams: the superstar Snow Kids, the agile Wambas and the sinister Shadows. Users can also explore the lore of the Galactik Football universe and will soon be able to play a unique card game featuring their character. 3D Flash-based mini-games that you can play using your avatar will be added to the site in the coming weeks.
Club Galactik is completely developed and published in-house by Virtual Fairground (www.virtualfairground.com). The game is based on the Gaumont/Jetix co-produced animation series Galactik Football. The full MMO game experience is set to launch April 2010 in time for the start of the FIFA World Cup Soccer 2010 and the third season of the Galactik Football animation series.
“As soon as we announced that we were working on a Galactik Football MMO game there was a lot of interest from fans that wanted to see what we are working on”, says Maarten Brands of Virtual Fairground. “With a gradual roll-out of games and features we will have plenty going on to keep the fans happy while we work towards a full launch next year.”
“Launching the avatar creator and some of the mini-games is a great way for us to show what our team can do with Flash in a browser”, adds Ilja Goossens. “We feel that there a lot of misconceptions about what you can do with this technology in relation to games. The high penetration rate of Flash is a huge benefit and we want to show that our talented developers can create high-end entertainment experiences in a browser using this technology.”
Games games games
Posted on April 16, 2009
Filed Under General | 2 Comments
FLARToolkit Single & MultipleMarker Detection
Posted on March 23, 2009
Filed Under Actionscript 3.0, Opensource, Papervision, experiments | 11 Comments
What you will need:
1. Photoshop (any will do)
2. Papervision3D rev. 817 or later
3. FlarToolkit
4. ArToolkit Marker Generator (flash player 10)
5. webcam
6. Fash CS3 or Higher
There are allready some great sites experimenting and writing tutorials about Augmented reality in flash. This is nothing new, just my experience in writing the code to create a simple version so I can learn from the others who started it. So before I start credits go out to squidder.com for some amazing tutorials and examples and saqoosha.net for starting the FlarToolkit.
For creating the best markers go and see the tutorial at squidder.com
For the starters kit you can get flartoolkit via libspark repository or download the starterskit at saqoosha.net.
Example of a Single Marker Detection:
Code Single Marker detection:
-
package nl.wisman.codexperiments.augmented
-
{
-
// papervision
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
-
import org.papervision3d.render.LazyRenderEngine;
-
import org.papervision3d.scenes.Scene3D;
-
import org.papervision3d.view.Viewport3D;
-
-
// flash
-
import flash.display.PixelSnapping;
-
import flash.display.Bitmap;
-
import flash.net.URLRequest;
-
import flash.events.Event;
-
import flash.net.URLLoaderDataFormat;
-
import flash.net.URLLoader;
-
import flash.display.BitmapData;
-
import flash.media.Video;
-
import flash.media.Camera;
-
import flash.display.Sprite;
-
import org.papervision3d.objects.DisplayObject3D;
-
-
// libspark
-
import org.libspark.flartoolkit.core.FLARCode;
-
import org.libspark.flartoolkit.core.param.FLARParam;
-
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
-
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
-
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
-
import org.libspark.flartoolkit.pv3d.FLARBaseNode;
-
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
-
-
public class FlarSingleMarkerDemo extends Sprite
-
{
-
// flar properties
-
private var _camParameters:FLARParam;
-
private var _marker4Pattern:FLARCode;
-
private var _raster:FLARRgbRaster_BitmapData;
-
private var _detector:FLARSingleMarkerDetector;
-
private var _flarCam3D:FLARCamera3D;
-
private var _resultMat:FLARTransMatResult;
-
private var _baseNode:FLARBaseNode;
-
-
// flash properties
-
private var _cam:Camera;
-
private var _vid:Video;
-
private var _capture:Bitmap;
-
private var _loader:URLLoader;
-
-
// papervision3d
-
private var _vp:Viewport3D;
-
private var _scene:Scene3D;
-
private var _renderer:LazyRenderEngine;
-
private var _light:PointLight3D;
-
private var _cube:Cube;
-
-
public function FlarSingleMarkerDemo()
-
{
-
loadCamera();
-
}
-
-
private function loadCamera():void
-
{
-
_loader = new URLLoader();
-
_loader.dataFormat = URLLoaderDataFormat.BINARY;
-
_loader.addEventListener(Event.COMPLETE, onLoadCamParam);
-
_loader.load(new URLRequest("camera_para.dat"));
-
}
-
-
// camera parameters are loaded, load the marker you want to use
-
private function onLoadCamParam(event:Event):void
-
{
-
_loader.removeEventListener(Event.COMPLETE, onLoadCamParam);
-
_camParameters = new FLARParam();
-
_camParameters.loadARParam(_loader.data);
-
_camParameters.changeScreenSize(500, 500);
-
-
_loader.dataFormat = URLLoaderDataFormat.TEXT;
-
_loader.addEventListener(Event.COMPLETE, onLoadCode);
-
_loader.load(new URLRequest("yourmarker.pat"));
-
}
-
-
// marker now also loaded, so remove _loader and create a FlarCode
-
private function onLoadCode(event:Event):void
-
{
-
initWebcam();
-
-
_marker4Pattern = new FLARCode(4, 4, 65, 65);
-
_marker4Pattern.loadARPatt(_loader.data);
-
-
_loader.removeEventListener(Event.COMPLETE, onLoadCode);
-
_loader = null;
-
-
// create bitmap and bitmapdata where we can draw the webcam into
-
var bmd:BitmapData = new BitmapData(500, 500, false, 0);
-
_capture = new Bitmap(bmd, PixelSnapping.AUTO,false);
-
_capture.width = 500;
-
_capture.height = 500;
-
addChild(_capture);
-
-
_raster = new FLARRgbRaster_BitmapData(_capture.bitmapData);
-
_detector = new FLARSingleMarkerDetector(_camParameters, _marker4Pattern, 65);
-
-
initFlar();
-
initPV3D();
-
initListeners();
-
}
-
-
private function initWebcam():void
-
{
-
_cam = Camera.getCamera();
-
_cam.setMode(500, 500, 60);
-
_vid = new Video(500, 500);
-
_vid.attachCamera(_cam);
-
}
-
-
private function initFlar():void
-
{
-
_flarCam3D = new FLARCamera3D(_camParameters);
-
_resultMat = new FLARTransMatResult();
-
_baseNode = new FLARBaseNode();
-
}
-
-
private function initPV3D():void
-
{
-
_vp = new Viewport3D(500, 500);
-
addChild(_vp);
-
-
_scene = new Scene3D();
-
_scene.addChild(_baseNode);
-
-
_light = new PointLight3D();
-
-
// add a cube or whatever we want to show when pattern is recognised
-
// in the basenode (FLARBaseNode, which extends from a DisplayObject3D)
-
var fmat:FlatShadeMaterial = new FlatShadeMaterial(_light, 0×7DC202, 0xCCCCCC);
-
_cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 80);
-
_cube.z = 20;
-
_cube.name = "cube";
-
_baseNode.addChild(_cube);
-
-
_renderer = new LazyRenderEngine(_scene, _flarCam3D, _vp);
-
}
-
-
private function initListeners():void
-
{
-
addEventListener(Event.ENTER_FRAME, render);
-
}
-
-
private function render(event:Event):void
-
{
-
_capture.bitmapData.draw(_vid);
-
-
if (_detector.detectMarkerLite(_raster, 65) && _detector.getConfidence() > 0.5)
-
{
-
// when deteactmarker finds the marker you created show the baseNode
-
_detector.getTransformMatrix(_resultMat);
-
_baseNode.setTransformMatrix(_resultMat);
-
_baseNode.visible = true;
-
}
-
else
-
{
-
_baseNode.visible = false;
-
}
-
-
if(_baseNode.visible)
-
{
-
Cube(_baseNode.getChildByName("cube")).roll(1);
-
}
-
-
_renderer.render();
-
}
-
}
-
}
Example of a Multiple Marker Detection: (its still a work in progress, still shifts cube from one pattern to another but he…)
Code Multiple Marker detection:
-
package
-
{
-
// bulkloader
-
import br.com.stimuli.loading.BulkLoader;
-
-
// papervision
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
-
import org.papervision3d.render.LazyRenderEngine;
-
import org.papervision3d.scenes.Scene3D;
-
import org.papervision3d.view.Viewport3D;
-
-
// flash
-
import flash.display.PixelSnapping;
-
import flash.display.Bitmap;
-
import flash.net.URLRequest;
-
import flash.events.Event;
-
import flash.net.URLLoaderDataFormat;
-
import flash.net.URLLoader;
-
import flash.display.BitmapData;
-
import flash.media.Video;
-
import flash.media.Camera;
-
import flash.display.Sprite;
-
import org.papervision3d.objects.DisplayObject3D;
-
-
// libspark
-
import org.libspark.flartoolkit.core.FLARCode;
-
import org.libspark.flartoolkit.core.param.FLARParam;
-
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
-
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
-
import org.libspark.flartoolkit.detector.FLARMultiMarkerDetector;
-
import org.libspark.flartoolkit.pv3d.FLARBaseNode;
-
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
-
-
public class FlarMultiMarkerDemo extends Sprite
-
{
-
// flar properties
-
private var _camParameters:FLARParam;
-
private var _raster:FLARRgbRaster_BitmapData;
-
private var _detector:FLARMultiMarkerDetector;
-
private var _flarCam3D:FLARCamera3D;
-
private var _resultMat:FLARTransMatResult;
-
-
// flash properties
-
private var _cam:Camera;
-
private var _vid:Video;
-
private var _capture:Bitmap;
-
private var _loader:URLLoader;
-
private var _allMarkers:Array;
-
-
// papervision3d
-
private var _vp:Viewport3D;
-
private var _scene:Scene3D;
-
private var _renderer:LazyRenderEngine;
-
private var _light:PointLight3D;
-
private var _bLoader:BulkLoader;
-
-
public function FlarMultiMarkerDemo()
-
{
-
_allMarkers = [
-
{markerSource: "path/your_first_marker.pat", segments: 4, size: 65},
-
{markerSource: "path/your_second_marker.pat", segments: 4, size: 65},
-
{markerSource: "path/your_third_marker.pat", segments: 4, size: 65},
-
];
-
-
loadCamera();
-
}
-
-
private function loadCamera():void
-
{
-
_loader = new URLLoader();
-
_loader.dataFormat = URLLoaderDataFormat.BINARY;
-
_loader.addEventListener(Event.COMPLETE, onLoadCamParam);
-
_loader.load(new URLRequest("camera_para.dat"));
-
}
-
-
// camera parameters are loaded, load the marker you want to use
-
// camera parameters are loaded, load the marker you want to use
-
private function onLoadCamParam(event:Event):void
-
{
-
_loader.removeEventListener(Event.COMPLETE, onLoadCamParam);
-
-
// setup camera parameters
-
_camParameters = new FLARParam();
-
_camParameters.loadARParam(_loader.data);
-
_camParameters.changeScreenSize(500, 500);
-
-
// reset loader
-
_loader = null;
-
-
_bLoader = new BulkLoader("markerLoader");
-
_bLoader.addEventListener(Event.COMPLETE, markersLoadedHandler);
-
// now load multiple markers (for now its 3)
-
for (var i:int = 0; i < _allMarkers.length; i++)
-
{
-
_bLoader.add(_allMarkers[i].markerSource, {id: "marker_" + i.toString() });
-
}
-
_bLoader.start();
-
}
-
-
private function markersLoadedHandler(event:Event):void
-
{
-
var codes:Array = new Array();
-
var sizes:Array = new Array();
-
for (var i:int = 0; i < _allMarkers.length; i++)
-
{
-
var code:FLARCode = new FLARCode(_allMarkers[i].segments, _allMarkers[i].segments, _allMarkers[i].size, _allMarkers[i].size);
-
code.loadARPatt(_bLoader.getContent( "marker_" + i.toString()));
-
codes.push(code);
-
sizes.push(_allMarkers[i].size);
-
}
-
-
initWebcam();
-
-
// create bitmap and bitmapdata where we can draw the webcam into
-
var bmd:BitmapData = new BitmapData(500, 500, false, 0);
-
_capture = new Bitmap(bmd, PixelSnapping.AUTO,false);
-
_capture.width = 500;
-
_capture.height = 500;
-
addChild(_capture);
-
-
_raster = new FLARRgbRaster_BitmapData(_capture.bitmapData);
-
_detector = new FLARMultiMarkerDetector(_camParameters, codes, sizes, codes.length);
-
-
initFlar();
-
initPV3D();
-
initListeners();
-
}
-
-
private function initWebcam():void
-
{
-
_cam = Camera.getCamera();
-
_cam.setMode(500, 500, 60);
-
_vid = new Video(500, 500);
-
_vid.attachCamera(_cam);
-
}
-
-
private function initFlar():void
-
{
-
_flarCam3D = new FLARCamera3D(_camParameters);
-
_resultMat = new FLARTransMatResult();
-
}
-
-
private function initPV3D():void
-
{
-
_vp = new Viewport3D(500, 500);
-
addChild(_vp);
-
-
_scene = new Scene3D();
-
-
_light = new PointLight3D();
-
-
// add a cube or whatever we want to show when pattern is recognised
-
// in the basenode (FLARBaseNode, which extends from a DisplayObject3D)
-
for (var i:int = 0; i < _allMarkers.length; i++)
-
{
-
var fmat:FlatShadeMaterial = new FlatShadeMaterial(_light, 0×7DC202 * Math.random(), 0xCCCCCC);
-
var cube:Cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 80);
-
cube.z = 20;
-
cube.name = "cube_" + i.toString();
-
var baseNode:FLARBaseNode = new FLARBaseNode();
-
baseNode.name = "baseNode_" + i;
-
baseNode.addChild(cube);
-
_scene.addChild(baseNode);
-
}
-
-
_renderer = new LazyRenderEngine(_scene, _flarCam3D, _vp);
-
}
-
-
private function initListeners():void
-
{
-
addEventListener(Event.ENTER_FRAME, render);
-
}
-
-
private function render(event:Event):void
-
{
-
_capture.bitmapData.draw(_vid);
-
-
for (var i:int = 0; i< _allMarkers.length; i++)
-
{
-
if(_detector.detectMarkerLite(_raster, 65) && _detector.getConfidence(i) > .5)
-
{
-
_detector.getTransmationMatrix(i, _resultMat);
-
FLARBaseNode(_scene.getChildByName("baseNode_" + i)).setTransformMatrix(_resultMat);
-
_scene.getChildByName("baseNode_" + i).visible = true;
-
}
-
else
-
{
-
_scene.getChildByName("baseNode_" + i).visible = false;
-
}
-
}
-
-
_renderer.render();
-
}
-
}
-
}
And last but not least a flash version to play with:
Try it yourself, but don’t forget to download the patterns first.
Augmented Reality Drumkit by Squidder
Posted on March 20, 2009
Filed Under Actionscript 3.0, Interaction, Opensource, experiments | 1 Comment
Augmented Reality Drum Kit (demo #1) from squidder on Vimeo. source: squidder
Pearl Jam The Game
Posted on March 18, 2009
Filed Under General, Interaction, Papervision | Leave a Comment
Great 3D puzzle game!! Definately check it out! (source: thefwa)
Nice truck game
Posted on March 15, 2009
Filed Under Papervision | Leave a Comment
source - strongesttruck
Flash Press by NoPonies
Posted on March 15, 2009
Filed Under Actionscript 3.0, Opensource | Leave a Comment
Flash Press is simply an AMFPHP and Zend_AMF service for connecting to Wordpress. The purpose of the project is to allow for using Wordpress as a CMS for Flash websites etc. Currently it only supports read operations from the Wordpress database. However, they are looking at adding write support.
It’s still in development but a nice project they are working on, so have a look.
PV3D - Interactive Shaded Cube
Posted on March 8, 2009
Filed Under Actionscript 3.0, Papervision, experiments | 7 Comments
Ryan and myself wanted to figure out how to create have an interactive cube which uses a ShadedMaterial (MovieMaterial + Shader). Problem was that when you had a shadedmaterial you didn’t get any interactiveScene3DEvent’s back, when you used only the MovieMaterial and set it to interactive=true everything worked fine, but in combination with a shader it created a problem. So I had a look at it today and came up with the following solution.
-
package
-
{
-
import flash.events.Event;
-
-
import org.papervision3d.materials.shaders.PhongShader;
-
import org.papervision3d.materials.shaders.ShadedMaterial;
-
import org.papervision3d.events.InteractiveScene3DEvent;
-
import org.papervision3d.materials.MovieAssetMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.view.BasicView;
-
import org.papervision3d.core.proto.CameraObject3D;
-
import org.papervision3d.core.proto.MaterialObject3D;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.core.geom.renderables.Triangle3D;
-
-
public class DemoShader extends BasicView
-
{
-
private var _clipsAndSides:Array;
-
private var _light:PointLight3D;
-
private var _cube:Cube;
-
-
public function DemoShader()
-
{
-
// linked library assets and the cubeSides we want it to belong to
-
_clipsAndSides = [ {linkageId: "clip_1", cubeSide:"front" },
-
{linkageId: "clip_2", cubeSide:"back" },
-
{linkageId: "clip_3", cubeSide:"top" },
-
{linkageId: "clip_4", cubeSide:"bottom"},
-
{linkageId: "clip_5", cubeSide:"left"},
-
{linkageId: "clip_6", cubeSide:"right"}
-
];
-
-
// light
-
_light = new PointLight3D();
-
_light.z = camera.z;
-
_light.x = camera.x;
-
_light.y = 250;
-
-
// place camera a bit higher up
-
camera.y = 500;
-
-
viewport.buttonMode = true;
-
viewport.interactive = true;
-
-
var mList:MaterialsList = new MaterialsList();
-
for (var i:int = 0; i < _clipsAndSides.length; i++)
-
{
-
var ma:MovieAssetMaterial = new MovieAssetMaterial(_clipsAndSides[i].linkageId);
-
var phongShader:PhongShader = new PhongShader(_light, 0xFFFFFF, 0×333333);
-
var shadedMaterial:ShadedMaterial = new ShadedMaterial(ma, phongShader);
-
shadedMaterial.interactive = true;
-
shadedMaterial.name = _clipsAndSides[i].linkageId;
-
mList.addMaterial(shadedMaterial, _clipsAndSides[i].cubeSide);
-
}
-
-
_cube = new Cube(mList, 500, 500, 500, 2, 2, 2);
-
_cube.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, objectClicked);
-
scene.addChild(_cube);
-
-
// render
-
addEventListener(Event.ENTER_FRAME, update);
-
}
-
-
private function objectClicked(event:InteractiveScene3DEvent):void
-
{
-
switch(event.face3d.material.name)
-
{
-
case "clip_1":
-
trace("clip 1 clicked");
-
break;
-
-
case "clip_2":
-
trace("clip 2 clicked");
-
break;
-
-
case "clip_3":
-
trace("clip 3 clicked");
-
break;
-
-
case "clip_4":
-
trace("clip 4 clicked");
-
break;
-
-
case "clip_5":
-
trace("clip 5 clicked");
-
break;
-
-
case "clip_6":
-
trace("clip 6 clicked");
-
break;
-
}
-
}
-
-
private function update(event:Event):void
-
{
-
camera.lookAt(_cube);
-
-
_cube.yaw(1.5); // y-axis
-
_cube.pitch(1.5); // x-axis
-
-
singleRender();
-
}
-
}
-
}
Hope everything is clear and if you have a better solution please comment a post!
Brownian Motion + CollisionGrid
Posted on March 1, 2009
Filed Under Actionscript 3.0, experiments | 3 Comments
Started reading Advanced Actionscript 3 Animation written by Keith Peters & Seb Lee-DeLisle (technical reviewer) so here’s a little experiment with grid collision using the FP10 Vector class. Let it run for a while and it creates a nice weird image.
Brownian CollisionDemo:
-
package
-
{
-
import flash.display.BlendMode;
-
import flash.filters.BlurFilter;
-
import flash.display.Bitmap;
-
import flash.display.BitmapData;
-
import flash.events.Event;
-
import flash.display.StageScaleMode;
-
import flash.display.StageAlign;
-
import flash.display.DisplayObject;
-
import flash.display.Sprite;
-
-
public class CollisionDemo extends Sprite
-
{
-
private const GRID_SIZE:Number = 30;
-
private const RADIUS:Number = 15;
-
-
private var _screen:BitmapData = new BitmapData(800, 600, false, 0);
-
private var _balls:Vector.<DisplayObject>;
-
private var _grid:CollisionGrid;
-
private var _numBalls:int = 100;
-
private var _ballContainer:Sprite = new Sprite();
-
-
public function CollisionDemo()
-
{
-
stage.align = StageAlign.TOP_LEFT;
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
-
addChild(new Bitmap(_screen));
-
addChild(_ballContainer);
-
-
_grid = new CollisionGrid(stage.stageWidth, stage.stageHeight, GRID_SIZE);
-
_grid.drawGrid(graphics, 0, .1);
-
-
makeBalls();
-
-
addEventListener(Event.ENTER_FRAME, onEnterFrame);
-
}
-
-
function onEnterFrame(event:Event):void
-
{
-
updateBalls();
-
_grid.check(_balls);
-
-
var numChecks:int = _grid.checks.length;
-
for(var j:int = 0; j < numChecks; j += 2)
-
{
-
checkCollision(_grid.checks[j] as Circle, _grid.checks[j + 1] as Circle);
-
}
-
-
_screen.draw(_ballContainer);
-
}
-
-
private function makeBalls():void
-
{
-
_balls = new Vector.<DisplayObject>(_numBalls);
-
for(var i:int = 0; i < _numBalls; i++)
-
{
-
var circle:Circle = new Circle(RADIUS);
-
circle.x = Math.random() * stage.stageWidth;
-
circle.y = Math.random() * stage.stageHeight;
-
circle.vx = Math.random() * 10 - 5;
-
circle.vy = Math.random() * 10 - 5;
-
_ballContainer.addChild(circle);
-
_balls[i] = circle;
-
}
-
-
_ballContainer.visible = false;
-
}
-
-
private function updateBalls():void
-
{
-
for(var i:int = 0; i < _numBalls; i++)
-
{
-
var circle:Circle = _balls[i] as Circle;
-
circle.update();
-
-
circle.vx = Math.random() * 10 - 5;
-
circle.vy = Math.random() * 10 - 5;
-
-
if(circle.x < RADIUS)
-
{
-
circle.x = RADIUS;
-
circle.vx *= -1;
-
}
-
else if(circle.x > stage.stageWidth - RADIUS)
-
{
-
circle.x = stage.stageWidth - RADIUS;
-
circle.vx *= -1;
-
}
-
if(circle.y < RADIUS)
-
{
-
circle.y = RADIUS;
-
circle.vy *= -1;
-
}
-
else if(circle.y > stage.stageHeight - RADIUS)
-
{
-
circle.y = stage.stageHeight - RADIUS;
-
circle.vy *= -1;
-
}
-
circle.color = 0xffffff;
-
}
-
}
-
-
private function checkCollision(circleA:Circle, circleB:Circle):void
-
{
-
var dx:Number = circleB.x - circleA.x;
-
var dy:Number = circleB.y - circleA.y;
-
var dist:Number = Math.sqrt(dx * dx + dy * dy);
-
if(dist < circleA.radius + circleB.radius)
-
{
-
circleA.color = 0×7DC202;
-
circleB.color = 0×7DC202;
-
}
-
}
-
}
-
}
CollisionGrid Class:
-
package
-
{
-
import flash.display.DisplayObject;
-
import flash.display.Graphics;
-
import flash.events.EventDispatcher;
-
-
public class CollisionGrid extends EventDispatcher
-
{
-
private var _checks:Vector.<DisplayObject>;
-
private var _grid:Vector.<Vector.<DisplayObject>>;
-
private var _gridSize:Number;
-
private var _height:Number;
-
private var _width:Number;
-
private var _numCells:int;
-
private var _numCols:int;
-
private var _numRows:int;
-
-
public function CollisionGrid(width:Number, height:Number, gridSize:Number)
-
{
-
_width = width;
-
_height = height;
-
_gridSize = gridSize;
-
_numCols = Math.ceil(_width / _gridSize);
-
_numRows = Math.ceil(_height / _gridSize);
-
_numCells = _numCols * _numRows;
-
}
-
-
public function drawGrid(graphics:Graphics, color:int = 0×333333, alpha:Number = 1):void
-
{
-
graphics.lineStyle(0, color, alpha);
-
for (var i:int = 0; i < _width; i += _gridSize)
-
{
-
graphics.moveTo(i, 0);
-
graphics.lineTo(i, _height);
-
}
-
-
for (var j:int = 0; j < _height; j += _gridSize)
-
{
-
graphics.moveTo(0, j);
-
graphics.lineTo(_width, j);
-
}
-
}
-
-
public function check(objects:Vector.<DisplayObject>):void
-
{
-
var numObjects:int = objects.length;
-
_grid = new Vector.<Vector.<DisplayObject>>(_numCells);
-
_checks = new Vector.<DisplayObject>();
-
for(var i:int = 0; i < numObjects; i++)
-
{
-
var obj:DisplayObject = objects[i];
-
var index:int = Math.floor(obj.y / _gridSize) * _numCols + Math.floor(obj.x / _gridSize);
-
if(_grid[index] == null) _grid[index] = new Vector.<DisplayObject>;
-
_grid[index].push(obj);
-
}
-
-
checkGrid();
-
}
-
-
private function checkGrid():void
-
{
-
for (var i:int = 0; i <_numCols; i++)
-
{
-
for (var j:int = 0; j < _numRows; j++)
-
{
-
checkOneCell(i,j);
-
checkTwoCells(i, j, i + 1, j); // right
-
checkTwoCells(i, j, i - 1, j + 1); // lower left
-
checkTwoCells(i, j, i , j + 1); // lower
-
checkTwoCells(i, j, i + 1, j + 1); // lower right
-
}
-
}
-
}
-
-
private function checkOneCell(x:int, y:int):void
-
{
-
var cell:Vector.<DisplayObject> = _grid[y * _numCols + x];
-
if (cell == null) return;
-
-
var cellLength:int = cell.length;
-
for (var i:int = 0; i < cellLength - 1; i++)
-
{
-
var objA:DisplayObject = cell[i];
-
-
for (var j:int = i + 1; j < cellLength; j++)
-
{
-
var objB:DisplayObject = cell[j];
-
_checks.push(objA, objB);
-
}
-
}
-
}
-
-
private function checkTwoCells(x1:int, y1:int, x2:int, y2:int):void
-
{
-
// make sure cell exists
-
if (x2 >= _numCols || x2 < 0 || y2 >= _numRows) return;
-
-
var cellA:Vector.<DisplayObject> = _grid[y1 * _numCols + x1];
-
var cellB:Vector.<DisplayObject> = _grid[y2 * _numCols + x2];
-
if (cellA == null || cellB == null) return;
-
-
var cellALength:int = cellA.length;
-
var cellBLength:int = cellB.length;
-
-
for (var i:int = 0; i < cellALength; i++)
-
{
-
var objA:DisplayObject = cellA[i];
-
-
for(var j:int = 0; j < cellBLength; j++)
-
{
-
var objB:DisplayObject = cellB[j];
-
_checks.push(objA, objB);
-
}
-
}
-
}
-
-
public function get checks():Vector.<DisplayObject>
-
{
-
return _checks;
-
}
-
}
-
}
Cartelle, a new interactive studio
Posted on February 27, 2009
Filed Under companies | 1 Comment
We have a new Interactive studio amongst us! Stevijn van Olst & Johnny Slack have joined forces and have called their baby Cartelle. Go check it out, have some fun with all the toys they have put up and don’t forget to check out their work aswell!
keep looking »
View experiment. 