影片剪辑重叠 [英] Movieclips Overlapping

查看:185
本文介绍了影片剪辑重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习AS3约2周

我试图使个人使用组合发生器

的问题是,如果在阵列内的相同的MovieClip显示两次或更多次,它只是overlapps它

有关时显示肘部第二次的例子,它只是重叠第一肘影片剪辑! http://imageshack.us/scaled/landing/208/17797019.png

下面是我的code

  VAR打孔:打孔=新冲床();
VAR踢:踢=新踢();
VAR膝:膝关节=新拐点();
VAR弯头:弯头=新弯头();
VAR持有人:影片剪辑; //用于显示目的
VAR位置:数= 100;

公共函数main()
{
    VAR组合:数组= [一拳,踢,膝,肘]。
    对于(VAR我:数量= 0;我2;我++)
    {
        支架=组合[randomNumber()]
        holder.y = 200;
        holder.x =位置;
        的addChild(保持器);
        位置=位置+ 100;
    }


}
功能randomNumber():数
{
    返程(Math.floor(的Math.random()*(4  -  1)+1));
}
 

解决方案

试着改变你的code是这样的:

 公共函数main()
{
    VAR组合:数组= [打孔,踢,膝,肘]。
    对于(VAR我:数量= 0;我2;我++)
    {
        VAR运动:影片剪辑=新组合[randomNumber()();
        motion.y = 200;
        motion.x = I * 100;
        的addChild(运动);
    }
}
功能randomNumber():数
{
    返程(Math.floor(的Math.random()*(4  -  1)+1));
}
 

I've been learning as3 for about 2 weeks

I'm trying to make a combo generator for personal uses

The problem is that if the same MovieClip inside the array is displayed twice or more it just overlapps it.

for example when the elbow is displayed a second time ,it just overlaps the 1st elbow movieclip! http://imageshack.us/scaled/landing/208/17797019.png

Here's my code

var punch:Punch = new Punch();
var kick:Kick = new Kick();
var knee:Knee = new Knee();
var elbow:Elbow = new Elbow();
var holder:MovieClip; // for displaying purposes 
var position:Number = 100;

public function Main()
{
    var combo:Array = [punch, kick, knee, elbow];
    for(var i:Number = 0;i < 2;i++ )
    {
        holder = combo[randomNumber()]
        holder.y = 200;
        holder.x = position;        
        addChild(holder);
        position = position + 100;
    }


}
function randomNumber():Number
{
    return(Math.floor(Math.random() * (4 - 1 )+1));
}

解决方案

Try to change your code like this:

public function Main()
{
    var combo:Array = [Punch, Kick, Knee, Elbow];
    for(var i:Number = 0;i < 2;i++ )
    {
        var motion:MovieClip = new combo[randomNumber()]();           
        motion.y = 200;
        motion.x = i*100;        
        addChild(motion);
    }    
}
function randomNumber():Number
{
    return(Math.floor(Math.random() * (4 - 1 )+1));
}

这篇关于影片剪辑重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆