Hey,
I have been having a problem with the below script.The script assumes that there is a MovieClip with the instance name “char”(I used a 32x32 square) and a MovieClip with the instance name BG on stage(I used the brush tool to create a bumpy fill/landscape roughly 1000x300.)As the script stands at the moment it moves the “BG” to create the effect that the “char” is moving along a scrolling landscape, the problem that I have is with the ‘while’ statement instead of stopping adding to the y value when the points are no longer touching it continues until the char is at the edge of it’s hit box.If I change it so that the “char” is moving and the “BG” is stationary the script runs as expected.Can anyone tell me why this is happening and possibly offer a soloution to my problem?Many thanks!
const gravity:Number = 1;
var yspeed:Number = 0;
BG.addEventListener(Event.ENTER_FRAME, begin);
function begin(event:Event):void {
BG.y -= yspeed;
while (BG.hitTestPoint(char.x, char.y-1, true)) {
BG.y++
yspeed=0;
}
if (! BG.hitTestPoint(char.x,char.y+1,true) ) {
yspeed+=gravity;
}
}