Papervision3D: understanding Plane object – part 5
- June 9, 2009 by Emanuele Feronato
- Filed under Actionscript 3, Flash | 10 Comments
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 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.
Download the source code and enjoy… next time: bending the card to make it look a bit more realistic.
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
They can be easily customized to meet the unique requirements of your project.
10 Responses
Leave a Reply
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online
- Giochi casino

(10 votes, average: 4.90 out of 5)



thanks for the tutorial!!!
my_card.forceSmoothing = true;
Thank you for your awsome job, but I can’t open the .fla file from this tutorial, I have a message: Unexpected file format. I work with Flash CS3 version. Could you help me? Thanks!
Thank you for your awsome job, but I can’t open the .fla file from this tutorial. I have the message: Unexpected file format. I’m working with Flash CS3. Could you help me please? Thanks!
it works in flash cs4
I need smooth the card, I try with “my_card.forceSmoothing = true;” but its not working.
“and please notice I NEVER add the card clip on the stage using addChild”
why?
[...] part 5 we created a playing [...]
can you just send us the movieclip of the card?
other than that all is just excellant and fantastic!
very helpful so far! :)
Great tutorial, however, why use an enter frame handler rather than one of the excellent tween engines that are available, like tweenmax/tweenlite?