Student Learning-Hittesting
Hi everybody!
I'd Just like to say thankyou to everybody for taking a look at my post even if you dont reply! and Double thankyou to those that do reply!
Im working in classes something Ive never done before!
Currently the class creates a small bird object that moves in both X and y and when the character hits it its destroyed, makes the character jump and doubles the score.(plus some other junk!)
What I want is: when my character hits this object I want him to land on it like a platform and stay on it while it moves! Im changing it from a bird to a cloud!
I have posted the full class below but I know( i think i do) that the only really important part I need to change is this:
if(this.hitTestObject(_root.mcMain)){//if this touches the main character
_root.mainJumping = true;//make him jump
_root.jumpSpeed = _root.jumpSpeedLimit*-1;//reset the jumpSpeed
var scoreText:ScoreAdd = new ScoreAdd();
_root.bellHolder.addChild(scoreText);//add some text to the stage
scoreText.x = this.x;//set the coordinates for the text
scoreText.y = this.y;
scoreText.txtScore.text = 'Double Score';//show that the score was doubled
this.removeEventListener(Event.ENTER_FRAME, eFrame);//remove the listeners
_root.bellHolder.removeChild(this);//and finally remove him from the stage
_root.score *= 2;
_root.startedJumping = true;
}
What i think i need to achieve is:
Trying to narrow the hitest to the top of the platform
stop the player from falling any further
then set the players X and Y to follow that of the platform object untill I jump off it
so far all I have is:
if (_root.mcMain.hitTest(this._x, this._y-11, true) or _root.mcMain.hitTest(this._x+5, this._y-11, true) or _root.mcMain.hitTest(this._x-5, this._y-11, true)) {
_root.jumpSpeed = 0;
_root.mcMain._x += this._x;
_root.mcMain._y += this._y;
}
Can someone please help me figure this out! OR explain to me what I need to achieve the effect I want>?
I can post more of the code if that helps! I will be checking this over the next 48hrs!
Thanks again for taking a look I know its a long shot but I have nowhere else to ask!
cheers
Jackson
-----------------FULL CLASS CODE----------------------------------------------------------------------------------------------------------------------------------
package{
import flash.display.MovieClip;
import flash.events.*;
public class Bird extends MovieClip {
var _root:Object;//this will symbolize the main timeline
var speed:int = 5;//how fast this bird will move side to side
public function Bird() {
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, eFrame);
}
private function beginClass(e:Event):void{
_root = MovieClip(root);
this.x = -50;//setting x value off the stage
this.y = _root.bellTop;//set the y value off the stage
}
private function eFrame(e:Event):void{
this.y += 3;//move the bell slowly downwards
this.x += speed;//moving this guy based on it's speed
if(this.x >= 537.5){//if it goes too far right
speed = -5;//make it go backwards
scaleX = -1;//and turn it around
}
if(this.x <= 12.5){//same with too far left
speed = 5;
scaleX = 1;
}
if(this.hitTestObject(_root.mcMain)){//if this touches the main character
_root.mainJumping = true;//make him jump
_root.jumpSpeed = _root.jumpSpeedLimit*-1;//reset the jumpSpeed
var scoreText:ScoreAdd = new ScoreAdd();
_root.bellHolder.addChild(scoreText);//add some text to the stage
scoreText.x = this.x;//set the coordinates for the text
scoreText.y = this.y;
scoreText.txtScore.text = 'Double Score';//show that the score was doubled
this.removeEventListener(Event.ENTER_FRAME, eFrame);//remove the listeners
_root.bellHolder.removeChild(this);//and finally remove him from the stage
_root.score *= 2;
_root.startedJumping = true;
}
if(_root.gameOver){//if the game is over
this.removeEventListener(Event.ENTER_FRAME, eFrame);//remove the listeners
_root.bellHolder.removeChild(this);//and remove from stage
}
}
}
}