我正在制作一款以鸟为头像的Flash游戏。当这只鸟拿起铁鸟皮卡时,会播放钢铁侠的歌曲。但问题是:它不断创建这个音频的新实例。所以我有十万个Ozzy在唱这首歌。但他们彼此之间有一秒钟的延迟。是否有一定的功能只能播放一次这首歌?还是一个小脚本来完成这个?
这是我的剧本:
var IronManMusic:Sound = new IronManSong();
var IronManChannel:SoundChannel = new SoundChannel();
var backgroundMusic:Sound = new BackgroundMusic();
var myChannel:SoundChannel = new SoundChannel();
myChannel = backgroundMusic.play();
if(ironbird==true){
laatstejump = 9;
myChannel.stop();
IronManChannel = IronManMusic.play();
}
在更新屏幕功能中可以找到ironbird布尔值。我认为这是问题,但我不确定。非常感谢帮助! :)
答案 0 :(得分:0)
嗯...看起来应该是:
if(ironbird==true) {
[...]
ironbird = false;
}
或者至少你提到的Updatescreen功能应该在一次滴答/迭代后将ironbird
设置回false
。
编辑:查看您发布的代码作为答案,它更容易:
你正在做
if(birdie.hitTestPoint(ironbirdpickup.x,ironbirdpickup.y,true)){
ironbird = true;
ironbirdpickup = Null;
}
if(ironbird==true){
laatstejump = 9;
myChannel.stop();
IronManChannel = IronManMusic.play();
}
并将ironbird
变量用于动画和其他内容。移动声音触发器应该只触发一次声音(或者触发hitTestPoint的频率)。
if(birdie.hitTestPoint(ironbirdpickup.x,ironbirdpickup.y,true)){
ironbird = true;
ironbirdpickup = Null;
myChannel.stop();
IronManChannel = IronManMusic.play();
}
if(ironbird==true){
laatstejump = 9;
}
您仍应将ironbird
重置为false
某处,即f.e。当动画完成时。
答案 1 :(得分:0)
不知道你对音频和动画部分的确切含义,但这是我的脚本。
//loads keyboard events
import flash.events.KeyboardEvent
var laatstelook:int = 1;
var ironbird:Boolean = false;
var laatstejump = 1;
var movebirdie:int = 2;
var birdfatigue : Boolean = false;
var birdtellery:int = 0;
var birdtelleryvertrager = 0;
var vy:Number=0;
var movement:Boolean=false;
var springen:Boolean=false;
var gv:Number=0.1;
var keyArray:Array = new Array();
var i:Number;
var leftOrrightpressed:Number=0;
var platformraak=false;
var PlatformArray:Array = new Array();
var IronManMusic:Sound = new IronManSong();
var IronManChannel:SoundChannel = new SoundChannel();
var backgroundMusic:Sound = new BackgroundMusic();
var myChannel:SoundChannel = new SoundChannel();
myChannel = backgroundMusic.play();
for(i=0;i<222;i++){
keyArray.push([i,false]);
}
//creating multiple objects from 1 object
for (var a:int = numChildren - 1; a >= 0; a--){
var child:DisplayObject = getChildAt(a);
if (child.name == "platform"){
PlatformArray.push(child);
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,checkKeysUp);
this.addEventListener(Event.ENTER_FRAME, UpdateScreen);
function UpdateScreen(event:Event):void{
//No multiple jumps in air
if(springen==true){
birdie.gotoAndStop(laatstejump);
birdtelleryvertrager+=0.2;
birdie.y-=15;
birdie.y+=birdtelleryvertrager;
birdtellery++;
if(isKeyDown(39)==true){
birdie.x += 5;
background.x += 1;
vcam.x += 5;
if(birdie.x <= 261.95){
vcam.x = 275.5;
background.x -= 1;
}
if(ironbird != true){
birdie.gotoAndStop(5);
}else{birdie.gotoAndStop(13);}
}
if(isKeyDown(37)==true){
birdie.x-=5;
vcam.x -= 5;
background.x -= 1;
if(birdie.x <= 261.95){
vcam.x = 275.5;
background.x += 1;
}
birdie.gotoAndStop(6);
}
//bird falls down
if(birdtellery>25){
birdfatigue == true;
if(isKeyDown(39)==true){
birdie.x-=4;
vcam.x -= 4;
}
if(isKeyDown(37)==true){
birdie.x += 4;
vcam.x += 4;
}
birdtelleryvertrager+=0.8;
}
//bird can jump again (when on platform)
if(birdtellery>30){
springen=false;
}
}else{
if(birdfatigue == true){
birdie.gotoAndStop(7);
}
//if right arrow button is pressed
if(isKeyDown(39)==true){
birdie.x += movebirdie;
if(birdie.x >= 261.95){
vcam.x += movebirdie;
background.x += 0.5;
}
if(ironbird != true){
birdie.gotoAndStop(2);
laatstelook =1;
}else{birdie.gotoAndStop(11);
laatstelook =9;
}
laatstejump =5;
leftOrrightpressed =1;
}
if(isKeyDown(39)==false){
if (leftOrrightpressed ==1){
birdie.gotoAndStop(laatstelook);
}
}
//if left arrow button is pressed
if(isKeyDown(37)==true){
birdie.x -= movebirdie;
background.x -= 0.5;
vcam.x -= movebirdie;
if(birdie.x <= 261.95){
vcam.x = 275.5;
background.x += 0.5;
}
if(ironbird != true){
birdie.gotoAndStop(3);
laatstelook =4;
}else{birdie.gotoAndStop(12);
laatstelook = 10;
}
laatstejump=6;
leftOrrightpressed =2;
}
if(isKeyDown(37)==false){
if (leftOrrightpressed ==2){
birdie.gotoAndStop(laatstelook);
}
}
//if space button is pressed
if(isKeyDown(32)==true && springen==false){
springen=true;
}
}
if(birdie.hitTestPoint(ironbirdpickup.x,ironbirdpickup.y,true)){
ironbird = true;
ironbirdpickup = Null;
}
if(ironbird==true){
laatstejump = 9;
myChannel.stop();
IronManChannel = IronManMusic.play();
}
addEventListener(Event.ENTER_FRAME,ctrl_birdie);
function ctrl_birdie(e:Event){
//when bird touches one of the platforms, bird stops falling
for(var a in PlatformArray){
if(PlatformArray[a].hitTestPoint(birdie.x,birdie.y,true)){
birdtelleryvertrager=0;
birdtellery = 0;
birdie.y-=1;
}
}
}
if(birdie.hitTestPoint(platform.platformboundingbox.x,platform.platformboundingbox.y,true)){
trace("hit");
}
//gravity
vy = 10;
birdie.y+=vy;
}
//checks if certain key is pressed
function checkKeysDown(event:KeyboardEvent):void{
keyArray[event.keyCode][1]=true;
}
function checkKeysUp(event:KeyboardEvent):void{
keyArray[event.keyCode][1]=false;
}
function isKeyDown(X){
return keyArray[X][1];
}
我是荷兰人,所以有些变数很奇怪。 xD只要问你是不是得到它!