rulator
04-19-2009, 11:09 AM
Hi
Im making a game where the goal is to shoot a character as far as possible.
By now its played by as longer u hold mousebutton down, the longer u shoot when u release.
I have made this powerbar "kraftBar".
I want it to go fast up and down, and the player has to press the mousebutton when the bar is at max to shoot the longest.
But my bar just keeps expanding in the x direction forever and ever and ever.
my questions are.. How do I get the bar to stop at its max (99.4 pixels) and go down to zero again and back up to 100, and so on...?
And how do I take out the bars x-value and make that decide how much power the shot gets?
This is what I got:
var startTid:int;
function fyr(evt:MouseEvent)
{
stage.addEventListener(Event.ENTER_FRAME,flyttFigu r);
var hastighet:int = (getTimer()-startTid)/250;
figur.dx= Math.cos((lop.rotation/360)*Math.PI*2)*hastighet;
figur.dy= Math.sin((lop.rotation/360)*Math.PI*2)*hastighet;
stage.removeEventListener(MouseEvent.MOUSE_MOVE,fl ytt);
stage.addEventListener(Event.ENTER_FRAME,bevegelse );
stage.removeEventListener(MouseEvent.MOUSE_UP,fyr) ;
}
//var maxKraft:Number = 4;
var totalKraft:Number = 0;
var kraft:Number = 1;
stage.addEventListener(Event.ENTER_FRAME, strlseBar);
function strlseBar(event:Event):void
{
totalKraft += kraft;
kraftBar.scaleX = totalKraft;
trace(totalKraft);
if(kraftBar.x > 100)
{
kraftBar.x = 100;
}
if(totalKraft == 100 || totalKraft == 0)
{
kraft *= -1;
trace("Skift kraft til " + kraft);
}
}
function startTidtaking(evt:MouseEvent)
{
startTid=getTimer();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN,start Tidtaking);
stage.addEventListener(MouseEvent.MOUSE_UP,fyr);
Im making a game where the goal is to shoot a character as far as possible.
By now its played by as longer u hold mousebutton down, the longer u shoot when u release.
I have made this powerbar "kraftBar".
I want it to go fast up and down, and the player has to press the mousebutton when the bar is at max to shoot the longest.
But my bar just keeps expanding in the x direction forever and ever and ever.
my questions are.. How do I get the bar to stop at its max (99.4 pixels) and go down to zero again and back up to 100, and so on...?
And how do I take out the bars x-value and make that decide how much power the shot gets?
This is what I got:
var startTid:int;
function fyr(evt:MouseEvent)
{
stage.addEventListener(Event.ENTER_FRAME,flyttFigu r);
var hastighet:int = (getTimer()-startTid)/250;
figur.dx= Math.cos((lop.rotation/360)*Math.PI*2)*hastighet;
figur.dy= Math.sin((lop.rotation/360)*Math.PI*2)*hastighet;
stage.removeEventListener(MouseEvent.MOUSE_MOVE,fl ytt);
stage.addEventListener(Event.ENTER_FRAME,bevegelse );
stage.removeEventListener(MouseEvent.MOUSE_UP,fyr) ;
}
//var maxKraft:Number = 4;
var totalKraft:Number = 0;
var kraft:Number = 1;
stage.addEventListener(Event.ENTER_FRAME, strlseBar);
function strlseBar(event:Event):void
{
totalKraft += kraft;
kraftBar.scaleX = totalKraft;
trace(totalKraft);
if(kraftBar.x > 100)
{
kraftBar.x = 100;
}
if(totalKraft == 100 || totalKraft == 0)
{
kraft *= -1;
trace("Skift kraft til " + kraft);
}
}
function startTidtaking(evt:MouseEvent)
{
startTid=getTimer();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN,start Tidtaking);
stage.addEventListener(MouseEvent.MOUSE_UP,fyr);