WEB开发网
开发学院图形图像Flash Papervision3D: understanding Plane object – p... 阅读

Papervision3D: understanding Plane object – part 5

 2009-10-21 00:00:00 来源:WEB开发网   
核心提示:This is the time to add textures to our plane from a movieclip.Since I am making a card game, I want to store all cards in a single movieclip and assign each fr

This is the time to add textures to our plane from a movieclip.

Since I am making a card game, I want to store all cards in a single movieclip and assign each frame to a different plane.

At the moment I have only two frames, one with the front and one with the back of the card, because the creation of the “perfect card” is not over yet…

I am attaching the commented code, and please notice I NEVER add the card clip on the stage using addChild

All the uncommented code has been explained from part 1 to 4

package {
 import flash.display.Sprite;
 import flash.events.Event;
 import org.papervision3d.cameras.Camera3D;
 import org.papervision3d.render.BasicRenderEngine;
 import org.papervision3d.scenes.Scene3D;
 import org.papervision3d.view.Viewport3D;
 import org.papervision3d.objects.primitives.Plane;
 import org.papervision3d.materials.MovieMaterial;
 import org.papervision3d.events.InteractiveScene3DEvent;
 public class papervision extends Sprite {
  // this is the movieclip with the cards... currently it holds
  // only two cards... the back and the 10 of hearts
  public var my_card:card = new card();
  public var viewport:Viewport3D=new Viewport3D(500,400,false,true);
  public var scene:Scene3D = new Scene3D();
  public var camera:Camera3D = new Camera3D();
  public var renderer:BasicRenderEngine = new BasicRenderEngine();
  // now it's time to use Movie Materials... we can use a movieclip as a material
  public var front_material:MovieMaterial;
  public var back_material:MovieMaterial;
  public var front_plane:Plane;
  public var back_plane:Plane;
  public var rotation_speed=0;
  public var steps=0;
  public function papervision() {
   // going to frame 2
   my_card.gotoAndStop(2);
   // assigning the 2nd frame to front_material material
   front_material=new MovieMaterial(my_card);
   // going to frame 1...
   my_card.gotoAndStop(1);
   // and assign the 1st frame as material of the back_material material
   back_material=new MovieMaterial(my_card);
   front_plane=new Plane(front_material,200,250,4,5);
   back_plane=new Plane(back_material,200,250,4,5);
   addChild(viewport);
   camera.focus=100;
   camera.zoom=10;
   back_plane.rotationY=180;
   front_material.interactive=true;
   back_material.interactive=true;
   scene.addChild(front_plane);
   scene.addChild(back_plane);
   back_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
   front_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
   addEventListener(Event.ENTER_FRAME, render);
  }
  public function render(e:Event) {
   if (rotation_speed) {
    steps++;
    front_plane.yaw(rotation_speed);
    back_plane.yaw(rotation_speed);
   }
   if (steps==180/rotation_speed) {
    steps=0;
    rotation_speed=0;
   }
   renderer.renderScene(scene, camera, viewport);
  }
  public function on_plane_clicked(e:InteractiveScene3DEvent) {
   if (steps==0) {
    rotation_speed=4;
   }
  }
 }
}

And this is the result:

Click on the card to flip it.

Tags:PapervisionD understanding Plane

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接