- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
Sprite2D,应该怎么解释呢。 Sprite【精灵、雪碧、还是子画面】
我理解的是场景中的平面元素,就像是纸片的效果。
接下来用到两个新的类,涉及到Sandy的行为了。
import sandy.util.*;
import sandy.events.*;
//控制镜头的前进与后退。
camera.moveForward() ;
//控制镜头的平移
camera.pan
camera.tilt
看看效果,怎么样,有点打CS时的感觉了吧!!
代码:
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.ui.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import sandy.core.Scene3D;
import sandy.core.scenegraph.*;
import sandy.primitive.*;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.core.data.*;
import sandy.util.*;
import sandy.events.*;
/**
* ...
* @author ever5u
*/
public class fuxi extends Sprite
{
private var scene:Scene3D;
private var camera:Camera3D;
private var queueoaderQueue;
private var numTree:Number = 50;
public function fuxi() {
queue = new LoaderQueue();
queue.add( "tree", new URLRequest("tree.gif") );
queue.addEventListener(SandyEvent.QUEUE_COMPLETE, loadComplete );
queue.start();
}
public function loadComplete(eventueueEvent ):void {
//先创建摄像机
camera = new Camera3D( 600, 300 );
camera.y = 10;
camera.z = -300;
//创建 Group
var root:Group = createScene();
//创建场景
scene = new Scene3D( "scene", this, camera, root );
scene.rectClipping = ***e;
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMovedHandler);
}
private function createScene():Group {
var g:Group = new Group();
for(var i:Number=0; i<numTree; i++){
var bit:Bitmap = new Bitmap(queue.data["tree"].bitmapData);
var s:Sprite2D = new Sprite2D("tree"+i,bit,1);
s.x = Math.random()*600 - 300;
s.z = Math.random()*600;
s.y = 0;
g.addChild(s);
}
return g;
}
private function enterFrameHandler( event : Event ) : void {
scene.render();
}
private function keyPressedHandler(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.UP:
camera.moveForward(5);
break;
case Keyboard.DOWN:
camera.moveForward(-5);
break;
}
}
private function mouseMovedHandler(event:MouseEvent):void {
camera.pan=(event.stageX-300/2)/10;
camera.tilt=(event.stageY-300/2)/20;
}
}
}
效果:(图片和Swf要放在同一目录下)
|
|