Papervision3D: understanding Plane object – part 5

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:

Download the source code and enjoy… next time: bending the card to make it look a bit more realistic.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers