away3d 4x中的VideoTexture好用吗

能将视频等动画内容贴在我们的模型上调整好UV的话,很多游戏内常见的特效也就可以轻松搞定啦。好在away3d提供了VideoTexture,让我们轻松完成这个工作。从而免于和繁琐的序列文件打交道。
如下所示,使用VideoTexture很容易:

import away3d.containers.View3D;
import away3d.materials.TextureMaterial;
import away3d.textures.VideoTexture;
import away3d.entities.Mesh;
import away3d.primitives.PlaneGeometry;
import away3d.events.Stage3DEvent;
import away3d.materials.ColorMaterial;
var v3D:View3D=new View3D();
var vt:VideoTexture=new VideoTexture("你的.flv");
vt.autoUpdate=true;//如果设置自动更新为false需要手工调用update方法刷新视频结果
vt.autoPlay=true;//即使设置自动播放也没用
vt.player.play();//手工启动播放
var mesh:Mesh=new Mesh(new PlaneGeometry(200,200,1,1,true,true),new TextureMaterial(vt));//new ColorMaterial(0xFF0000)
v3D.scene.addChild(mesh);
v3D.camera.z=-200;
addChild(v3D);
v3D.stage3DProxy.addEventListener(Stage3DEvent.CONTEXT3D_CREATED,v3D_com);
function v3D_com(e:Stage3DEvent){
	addEventListener(Event.ENTER_FRAME,run);
}
function run(e:Event){
	mesh.rotationX+=1;
	if(mesh.rotationX>360){
		mesh.rotationX-=360;
	}
	mesh.rotationY+=1;
	if(mesh.rotationY>360){
		mesh.rotationY-=360;
	}
	v3D.render();
} 

经过测试,视频流畅的转换为了纹理,运行稳定;
需要注意的是,创建VideoTexture时需要在构造方法中设置autoPlay属性为true才能立即开启视频的刷新功能;否则即使显示设置这个属性也不会对视频进行更新,原因是这个类内置的SimpleVideoPlayer并没有和autoPlay属性关联,所以还需要手动调用VideoTexture.player的play方法;同时VideoTexture.play属性是只读的,所以一个纹理只能对应一个视频。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值