|
as3isolib_tutorial_007
prerequisites This example makes use of Grant Skinner's GTween. You can download the source code here - link. tutorialMost developers will seek some level of interactivity with the as3isolib and the content created with it. Here is a quick example on how to make a simple interactive scene using a grid and a box. By clicking on the any of the cells in the grid, the box is tweened to that location. code package
{
import as3isolib.core.IIsoDisplayObject;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.scene.IsoScene;
import as3isolib.geom.IsoMath;
import as3isolib.geom.Pt;
import com.gskinner.motion.GTween;
import eDpLib.events.ProxyEvent;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class IsoApplication extends Sprite
{
private var box:IIsoDisplayObject;
private var scene:IsoScene;
public function IsoApplication ()
{
scene = new IsoScene();
var g:IsoGrid = new IsoGrid();
g.showOrigin = false;
g.addEventListener(MouseEvent.CLICK, grid_mouseHandler);
scene.addChild(g);
box = new IsoBox();
box.setSize(25, 25, 25);
scene.addChild(box);
var view:IsoView = new IsoView();
view.clipContent = false;
view.y = 50;
view.setSize(150, 100);
view.scene = scene; //look in the future to be able to add more scenes
addChild(view);
scene.render();
}
private var gt:GTween;
private function grid_mouseHandler (evt:ProxyEvent):void
{
var mEvt:MouseEvent = MouseEvent(evt.targetEvent);
var pt:Pt = new Pt(mEvt.localX, mEvt.localY);
IsoMath.screenToIso(pt);
if (gt)
gt.end();
else
{
gt = new GTween();
gt.addEventListener(Event.COMPLETE, gt_completeHandler);
}
gt.target = box;
gt.duration = 0.5;
gt.setProperties({x:pt.x, y:pt.y});
gt.play();
if (!hasEventListener(Event.ENTER_FRAME))
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function gt_completeHandler (evt:Event):void
{
this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler (evt:Event):void
{
scene.render();
}
}
}
|
► Sign in to add a comment
The line: view.scene = scene; //look in the future to be able to add more scenes Should be changed to: view.addScene(scene);
With the latest version.
I just have couple of questions: In case i put IsoSprites? on top of the grid , how can i still get click events? i tried to define the listener on the scene an it works, but localx and localy cordinates are wrong. The only thing i want is to be able to calculate X and Y of the tail was clicked ( even if some ISOObject is on it...).
IsoApplication?.as(41): col: 30 Error: Access of possibly undefined property scene through a reference with static type as3isolib.display:IsoView?.
I got this error:
iNode.as, Line 34 | 1045: Interface IEventDispatcherProxy was not found
Any help?
Don't download GTween's latest version, you have to download the beta2
The latest version of GTween 2.1 lines
I believe should be
To add a shadow add lines//<-
var factory:as3isolib.core.ClassFactory? = new as3isolib.core.ClassFactory?(DefaultShadowRenderer?); //<- factory.properties = {shadowColor:0x000000, shadowAlpha:0.15, drawAll:false};//<- and add importswhy add IsoView??
Error: Type was not found or was not a compile-time constant: ProxyEvent?.
any help?
I have used TweenLite? to animate it :
source codes :
package {
link: http://blog.csdn.net/hu36978/archive/2010/03/22/5405556.aspx
}
I think I improved the effect by replacing gt.end(); with gt.nextTween; (with 2.1) I havnt read any GTween docs so I dont really know if its a good thing :).
Anyway, Ive been reading through the as3isolib tuts and dropping them into a flex app. I like what I see very very much. cant wait to attempt to make something really cool using it.
If you want to use TweenMax? instead, replace all of the GTween lines with
TweenMax.to(box, 0.5, {x:pt.x, y:pt.y, onComplete:gt_completeHandler});and it will work just the same.
import as3isolib.core.IIsoDisplayObject; import as3isolib.display.IsoView; import as3isolib.display.primitive.IsoBox; import as3isolib.display.scene.IsoGrid; import as3isolib.display.scene.IsoScene; import as3isolib.geom.IsoMath; import as3isolib.geom.Pt; import eDpLib.events.ProxyEvent; import com.greensock.TweenMax; var box:IIsoDisplayObject; var scene:IsoScene; var tm:TweenMax; scene = new IsoScene(); var g:IsoGrid = new IsoGrid(); g.showOrigin = false; g.addEventListener(MouseEvent.CLICK, grid_mouseHandler); scene.addChild(g); box = new IsoBox(); box.setSize(25, 25, 25); scene.addChild(box); var view:IsoView = new IsoView(); view.clipContent = false; view.setSize(stage.stageWidth, stage.stageHeight); view.addScene(scene); addChild(view); scene.render(); function grid_mouseHandler (evt:ProxyEvent):void { var mEvt:MouseEvent = MouseEvent(evt.targetEvent); var pt:Pt = new Pt(mEvt.localX, mEvt.localY); IsoMath.screenToIso(pt); TweenMax.to(box, 0.5, {x:pt.x, y:pt.y, onComplete:completeCallback}) if (!hasEventListener(Event.ENTER_FRAME)) this.addEventListener(Event.ENTER_FRAME, enterFrameHandler); } function completeCallback():void { this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); } function enterFrameHandler (evt:Event):void { scene.render(); }The above code is updated as of July 13, 2010 and intended to work with greensock’s TweenMax?.
That file does not exist.
Click here to go to the home page.
the SWF file link is no longer valid, please update!
Siaukia's code works; I just searched for TweenMax? and grabbed the latest version of it.
Anybody else getting an issue where the box animates to a non-grid position? Looks as if there's some error in the IsoMath?.screenToIso calculation going on??
My bad. Just realized that the example allows you to click anywhere on the grid and the box will move to that pixel location. In order to move to specific grid squares, use rounding thus:
var squareSize:int = 25; // var gridX:int = Math.floor( pt.x / squareSize ); var gridY:int = Math.floor( pt.y / squareSize ); ... TweenMax.to(box, 0.5, {x:gridX * squareSize, y:gridY * squareSize, onComplete:completeCallback});@rich...: Thanks a lot. Works like a charm.
example.swf is unavailable