我需要多少图片才能有更流利的动画(Actionscript);
问题描述:
我有一个onEnterFrame事件:我需要多少图片才能有更流利的动画(Actionscript);
package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.errors.IOError;
public class Ball extends MovieClip {
private var images:Array;
private var frames:Array;
var i:int = 0;
public function Ball(images:Array) {
this.images = images
frames = new Array();
images.forEach(function(current){
trace(current);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadCompleted);
loader.load(new URLRequest(current));
});
}
private function onLoadCompleted(e:Event):void{
frames.push(e.currentTarget.content);
i++;
if(i == images.length)
{
ready();
}
}
private function ready():void{
i = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
graphics.clear();
var bitmapData:BitmapData = frames[i].bitmapData;
graphics.beginBitmapFill(bitmapData, new Matrix(), false, true);
graphics.drawRect(0, 0, 100, 100);
graphics.endFill();
i++;
if(i == frames.length)
{
i = 0;
}
}
}
}
这个类是获取图像的数组,然后蓬勃生机,这是我的主类:
public class Test extends MovieClip {
private var ball:Ball;
public function Test()
{
var images:Array = new Array();
for(var i:int = 1; i < 21; i++)
{
images.push('ball' + i.toString(10) + '.png');
}
ball = new Ball(images);
addChild(ball);
}
}
所以你看我传递一个20个图像的阵列,所以问题是我需要多少图像才能制作出一个好的动画,而不是粗略地但顺利地创建每个新图像,例如ball1.png,ball2.png,ball3.png,ball4.png - I需要通过像素移动球像素来制作一个好的动画?还是有更好的方法来做到这一点?
答
这取决于您的感知和设备以及您想要从内容中形象化的内容。 请参阅本网站
http://www.mathworks.com/help/toolbox/mupad/plot/INTRO_FramesAndTimeRange.html
答
我会考虑的第一件事是帧率。将更多图像作为帧率没有意义。
基本上对于一个平滑的动画30 fps应该没问题。另外,如果你考虑这个移动设备,我认为你不应该高于30fps,以获得良好的性能。
关于图像的数量,以及如何设置它们的动画,我建议你看看这个游戏教程(饥饿的英雄)
http://www.hsharma.com/tutorials/starting-with-starling-ep-3-sprite-sheets/ http://www.hsharma.com/tutorials/starting-with-starling-ep-5-parallax-background/
或什么是更好的使用显卡内置对象和他的功能还是通过创建图像?我是新来的,我不知道如何做得更好,绘制圆圈和线条,我将不得不制作graphics.clear(),并且在每个方法中复制/粘贴代码以绘制越来越多的某个人或火柴人的动作)或创建30-50图像)) – 2012-08-14 07:38:34
有很多阅读=),你能给我一个小问题吗?) – 2012-08-14 07:53:14
它是一个项目的工作? – sam 2012-08-14 09:22:00