0
私は自分のゲームにライフバーを持っており、ミニオンがバナナを捕まえないときは、ライフバーが減少します。それは正常に動作しますが、問題は地面に触れる前にライフバーが減少することです。地面に別のhitTestを追加し、それを& &とする必要がありますか? 主なプログラム:AS3 hitTestObject == false
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.Event;
var leftKey:Boolean;
var rightKey:Boolean;
var upKey:Boolean;
var downKey:Boolean;
var jump:Boolean = false;
var xvelocity:int = 9;
var yvelocity:int = 3;
var gravity:Number = 7;
stage.addEventListener(Event.ENTER_FRAME, changeVelocity);
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyDown);
function changeVelocity(evt:Event){
moveMinion();
yvelocity += gravity;
}
function moveMinion(){
if (leftKey == true){
sideMinion.x -= xvelocity;
sideMinion.left();
}
if (rightKey == true){
sideMinion.x += xvelocity;
sideMinion.right();
}
}
function checkKeyDown(e:KeyboardEvent){
if (e.keyCode == Keyboard.LEFT){
leftKey = true;
}
else if (e.keyCode == Keyboard.RIGHT){
rightKey = true;
}
}
function checkKeyUp(e:KeyboardEvent){
if (e.keyCode == Keyboard.LEFT){
leftKey = false;
}
else if (e.keyCode == Keyboard.RIGHT){
rightKey = false;
}
}
btnStart.addEventListener(MouseEvent.CLICK, makeItFall);
function makeItFall(e:MouseEvent){
var numBananas = 6;
var theBananas: Array = new Array();
theBananas = [];
for (var i = 0; i < numBananas; i++) {
var aBanana: banana = new banana();
theBananas.push(aBanana);
btnStart.visible=false;
aBanana.y=100;
theBananas[i].setSpot(Math.random()*450,Math.random()*200);
theBananas[i].setSpeed((Math.random()), 1);
stage.addChild(aBanana);
}
var health: Number= 100;
var healthPercent: Number= 1;
addEventListener(Event.ENTER_FRAME, pickUpBananas);
function pickUpBananas(event:Event){
for (var i:int = theBananas.length-1; i>-1; i--){
if (sideMinion.hitTestObject(theBananas[i])){
stage.removeChild(theBananas[i]);
theBananas.splice(i,1);
}
else if (sideMinion.hitTestObject(theBananas[i])==false){
health=health-10;
healthPercent=health/100;
trace(healthPercent);
life.scaleX= healthPercent;
}
}
}
}
stop();
とバナナクラス:
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.Event;
public class banana extends MovieClip {
var velX: Number = 0;
var velY: Number = 0;
var falling: Boolean = false;
var gravity: Number = 2;
public function banana() {
var timing: Timer = new Timer(25, 0);
timing.addEventListener(TimerEvent.TIMER, moveMe);
timing.start();
}
private function moveMe(event: TimerEvent)
{
x += velX;
y += velY;
if (falling) velY += gravity;
/* trace("[BANANA] position:", x, y, "speed:", velX, velY);*/
}
public function setSpeed(dx,dy) {
velX = dx;
velY = dy;
}
public function setSpot(atX,atY){
this.x=atX;
this.y=atY;
}
public function makeItFall(){
falling=true;
}
}
}
問題は、同じ行には意味をなさない2つの構文エラーが発生していることです。行85の列51は等号の前に識別子を期待し、列102は右の括弧の前にセミコロンを待つ。 – Catalina
行は85です(else文を含む行)。 – Catalina
パーフェクト:)問題の一部は、私がまだステートメントに&&を入れていたことでした。ありがとうございました。 – Catalina