【发布时间】:2016-01-13 19:38:34
【问题描述】:
我正在使用 Adobe Flash Professional CS6 来创建游戏。我会把代码贴在下面。请注意,我使用 Flash 创建的两个符号不是由代码创建的。这些符号是十字准线符号和 Hitbox 符号。基本上,游戏的目标是点击 Hitbox 符号。我的问题是我遇到了似乎是瓶颈的问题。当我使用快速计时器多次单击 Hitbox 符号时,分数不会记录。我认为这来自(可能)无效的运动算法。但我似乎真的找不到改进的余地。一些帮助将不胜感激。
请注意,我必须将计时器从 Timer(1) 更改为 Timer(30)。这让瓶颈问题稍微好一些,但游戏流畅度降低了。
啊,我使用directionCheckerY 和directionCheckerX 变量的原因是我稍后会在开发中添加随机运动。随机计时器会将它们更改为 0 和 1,从而产生随机运动。
import flash.events.MouseEvent;
import flash.events.TimerEvent;
// Variables
var directionCheckerX:int=0;
var directionCheckerY:int=0;
var pointChecker:int=0;
// Croshair
var crosshair:Crosshair = new Crosshair();
addChild(crosshair);
Mouse.hide();
function moveCrossEvent (evt: MouseEvent) {
crosshair.x = mouseX;
crosshair.y = mouseY;
evt.updateAfterEvent();
}
// Hitbox
var hitbox:Hitbox = new Hitbox();
addChild(hitbox);
hitbox.x=50;
hitbox.y=50;
// Timer
var myTimer:Timer = new Timer(30);
myTimer.addEventListener(TimerEvent.TIMER, timerEvent);
myTimer.start();
function timerEvent(evt:TimerEvent) {
// Border code (Keeps the Hitbox away from out of bounds)
if (hitbox.x <= 0) {
directionCheckerX = 1;
} else if (hitbox.x >= 550) {
directionCheckerX = 0;
}
if (directionCheckerX == 0) {
hitbox.x-=2;
} else {
hitbox.x+=2;
}
if (hitbox.y <= 0) {
directionCheckerY = 1;
} else if (hitbox.y >= 400) {
directionCheckerY = 0;
}
if (directionCheckerY == 0) {
hitbox.y-=2;
} else {
hitbox.y+=2;
}
}
// EventListeners
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCrossEvent);
hitbox.addEventListener(MouseEvent.CLICK, hitboxEvent);
stage.addEventListener(MouseEvent.CLICK, stageEvent);
function hitboxEvent (evt:MouseEvent) {
pointChecker+=1;
outputTxt.text = String(pointChecker);
evt.stopImmediatePropagation();
//evt.updateAfterEvent();
}
function stageEvent(evt:MouseEvent) {
pointChecker-=1;
outputTxt.text = String(pointChecker);
}
【问题讨论】:
标签: performance actionscript-3 flash