对于上课,我必须制作as3自上而下的观看游戏。
在level1中似乎一切正常但在level2上有一个声音延迟。当角色与level2中的手发生碰撞并且声音对象被调用时,声音不会立即播放,它会延迟直到碰撞不成立,并且只有在角色没有从发生碰撞的地方移动时才会播放。
目前,角色在第1级运行,同时正确地在与其.cc_mc对撞机对象和手的hc_mc对撞机对象发生碰撞时进行声音播放......但是在level2角色上碰撞新手并且声音直到level2才会播放。 hand.grabbing_mc消失了。定时手首先摇摆一个参数进入摇摆实例,然后进入标记为“grabbing_mc”的抓取实例。 hc_mc对撞机对象在grabbing_mc中。奇怪的是,镰刀尖叫声在整个游戏中运行良好,没有滞后。
下面我有一个我的screengame类的剥离版本,可以完成游戏的大部分工作;大部分只是声音相关的部分。有谁知道如何在碰撞后消除2级的延迟?提前谢谢。
package
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import flash.net.URLRequest;
public class ScreenGame extends Screen
{
public var character:Character;// Uses the AS Linkage
public var handScream:Sound = new Sound(new URLRequest("handScream.mp3"));
public var channel2:SoundChannel;
public var handNow:Boolean = false;
// Declare a level1 object to use in the game
public var level1:Level1;
public var level2:Level2;
//out of time timer
private var OTimer1:Timer;
private var OTimer2:Timer;
public function ScreenGame()
{
addEventListener(Event.ADDED_TO_STAGE,onStage);
}
public function onStage(e:Event)
{
removeEventListener(Event.ADDED_TO_STAGE,onStage);
// Creates character object
// character can now be used, which means positioning, animating, etc...
character = new Character(stage.stageWidth * 0.04,stage.stageHeight * 0.47,5);//x,y,speed
// make level object exist
level1 = new Level1();
// place level1 on screen
addChild(level1);
// place character on screen
addChild(character);
// listen for movements and animations
addEventListener(Event.ENTER_FRAME,gameLoop);
OTimer1 = new Timer(30000);
OTimer1.addEventListener(TimerEvent.TIMER, timeOver);
OTimer1.start();
}
// Handle game related stuff
public function gameLoop(e:Event)
{
//hand and scythe sound play
if (handNow)
{
channel2 = handScream.play(0,0);
handNow = !handNow;
}
if (scytheNow)
{
channel3 = scytheScream.play(0,0);
scytheNow = !scytheNow;
}
if (character && character.cc_mc && level1)
{
if (level1.hand.grabbing_mc && level1.hand.grabbing_mc.hc_mc && character.cc_mc.hitTestObject(level1.hand.grabbing_mc.hc_mc))
{
if (level1.hand.grabbing_mc.currentFrame == 1)
{
handNow = true;
}
trace("caught by hand");
}
else if (level1.scythe.sc_mc && character.cc_mc.hitTestObject(level1.scythe.sc_mc))
{
if (level1.scythe.currentFrame == 1)
{
scytheNow = true;
}
trace("hurt by blade");
}
else if (level1.treeMonkey.swing_mc || level1.treeMonkey.static_mc)
{
if (level1.treeMonkey.swing_mc && level1.treeMonkey.swing_mc.tmc_mc && character.cc_mc.hitTestObject(level1.treeMonkey.swing_mc.tmc_mc))
{
character.gotoAndStop("Swing");
}
else if (level1.treeMonkey.static_mc && level1.treeMonkey.static_mc.missDeath_mc && character.cc_mc.hitTestObject(level1.treeMonkey.static_mc.missDeath_mc))
{
trace("fell in crack");
}
}
}
else if (character && character.cc_mc && level2)
{
//handNow = false;
if (level2.hand.grabbing_mc && level2.hand.grabbing_mc.hc_mc && character.cc_mc.hitTestObject(level2.hand.grabbing_mc.hc_mc))
{
if (level2.hand.grabbing_mc.currentFrame == 1)
{
handNow = true;
}
trace("caught by hand");
}
else if (level2.scythe.sc_mc && character.cc_mc.hitTestObject(level2.scythe.sc_mc))
{
if (level2.scythe.currentFrame == 1)
{
scytheNow = true;
}
trace("hurt by blade");
}
}
// check if the player collides with levelProgression box
if ( character && level1 && level1.levelProgression_mc && character.hitTestObject( level1.levelProgression_mc ))
{
// player collides with levelProgression box
removeChild(level1);// remove level 1
level1 = null;// set to null
//cancel amd reset first timer
OTimer1.removeEventListener(TimerEvent.TIMER, timeOver);
OTimer1.reset();
level2 = new Level2();
loadLevelCollision(level2);
addChild(level2);
//change z order
swapChildren(level2,character);
character.x = stage.stageWidth * 0.04,character.y = stage.stageHeight * 0.1;
//start second timer
OTimer2 = new Timer(25000);
OTimer2.addEventListener(TimerEvent.TIMER, timeOver);
OTimer2.start();
//health text to front
this.setChildIndex(health_txt,this.numChildren - 1);
}
}//closes gameLoop
}//closes class screengame
}//closes package