Hi,
I made a simple example of a rolling ball, and it works fine (60fps) in normal mode, but when i switch it to fullscreen, frame rate drops to 30-40. Why is this happening, I have only one sphere and one plane on the scene(AwayStats: 484poly), even without lighting and shadows.
package{
import away3d.cameras.Camera3D;
import away3d.cameras.lenses.PerspectiveLens;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.core.managers.Stage3DManager;
import away3d.core.managers.Stage3DProxy;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.events.Stage3DEvent;
import away3d.materials.TextureMaterial;
import away3d.primitives.PlaneGeometry;
import away3d.primitives.SphereGeometry;
import away3d.utils.Cast;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
[SWF(width="1024", height="512", frameRate="60")]
public class OneBallTest extends Sprite{
[Embed(source='eight.png')]
private var BallTexture:Class;
[Embed(source='ballShadow.png')]
private var ShadowTexture:Class;
private var stage3DManager:Stage3DManager;
private var stage3DProxy:Stage3DProxy;
private var view:View3D;
private var shadowMaterial:TextureMaterial;
private var sphereMaterial:TextureMaterial;
private var shadow:Mesh;
private var sphere:Mesh;
private var oldX:Number=0;
private var oldY:Number=0;
private var curX:Number=0;
private var curY:Number=0;
private var angle:Number=0;
public function OneBallTest(){
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage3DManager = Stage3DManager.getInstance(stage);
stage3DProxy = stage3DManager.getFreeStage3DProxy();
stage3DProxy.addEventListener(Stage3DEvent.CONTEXT3D_CREATED, onCreate);
}
private function onCreate(e:Stage3DEvent):void{
view = new View3D();
view.stage3DProxy = stage3DProxy;
view.shareContext = true;
view.antiAlias = 4;
view.width = 1024;
view.height = 512;
view.camera = new Camera3D();
view.scene = new Scene3D();
view.stage3DProxy.color = 0xFFFFFF;
shadowMaterial = new TextureMaterial(Cast.bitmapTexture(new ShadowTexture()), true, false, false);
shadowMaterial.alphaBlending = true;
shadow = new Mesh(new PlaneGeometry(32, 32, 1, 1, true, true), shadowMaterial);
shadow.position = new Vector3D(0, 0, 9);
shadow.rotationX = 90;
view.scene.addChild(shadow);
sphereMaterial = new TextureMaterial(Cast.bitmapTexture(new BallTexture()), true, false, false);
sphere = new Mesh(new SphereGeometry(9, 16, 16), sphereMaterial);
sphere.position = new Vector3D(0, 0, 0);
view.scene.addChild(sphere);
var dist:Number = Vector3D.distance(new Vector3D(0,0,0), view.camera.position );
var fieldOfView:Number = (360 / Math.PI) * Math.atan(512 / (2 * dist));
(view.camera.lens as PerspectiveLens).fieldOfView = fieldOfView;
addChild(new AwayStats(view));
addChild(view);
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
stage.addEventListener(MouseEvent.DOUBLE_CLICK, clickHandler);
}
private function clickHandler(e:MouseEvent):void{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
private function enterFrameHandler(e:Event):void{
stage3DProxy.clear();
moveBall();
view.render();
stage3DProxy.present();
}
private function moveBall():void{
oldX = curX;
oldY = curY;
angle+=0.1;
if(angle>360) angle = 0;
curX = 100*Math.sin(angle);
curY =-100*(1-Math.cos(angle));
shadow.x=curX;
shadow.y=curY;
sphere.x=curX;
sphere.y=curY;
var matrix:Matrix3D = sphere.transform.clone();
matrix.appendRotation(-(curX-oldX)*2, Vector3D.Y_AXIS, matrix.position);
matrix.appendRotation((curY-oldY)*2, Vector3D.X_AXIS, matrix.position);
matrix.appendRotation(0, Vector3D.Z_AXIS, matrix.position);
sphere.transform = matrix;
}
private function resizeHandler(e:Event):void{
stage3DProxy.width = stage.stageWidth;
stage3DProxy.height = stage.stageHeight;
view.width = Math.ceil(stage.stageWidth*0.8);
view.height = Math.ceil(stage.stageHeight*0.8);
view.x = Math.ceil(stage.stageWidth/2-view.width/2);
view.y = Math.ceil(stage.stageHeight/2-view.height/2);
}
}
}
any ideas?
Many thanks for considering my request,
p.s. sorry for my english