PDA

View Full Version : [AS3] Scoring Graph?


hellomoto
10-22-2010, 08:42 PM
I'm working on an interactive game and need to show 2 teams score's in real time in graphical form. For now I'm just going to use the keyboard as input, but eventually it will be something else.

What I need is for there to be a vertical bar graph that goes up each time a certain key is clicked. So if team 1 is the A key and team 2 is the L key, I need two bar graphs to go up each time A or L is pushed. If no key is pushed for a period of time (3 seconds or so) I need the graphs to slowly go back down. The point is that the teams must continually push their key to fill the graph, get to the top and win. If they stop pushing, their score goes back down.

I hope this makes sense.

I'm pretty new at actionscript, so any ideas or help or other things to look at is very appreciated! thanks in advance!

Eralmidia
10-24-2010, 02:11 AM
Well, to raise the bar on a key press shouldn't be harder than changing the .y property of the bar:

mcBar.y -= 5 ie to move it 5 px up on key press. Then you would prob need an instance of the Timer class to control when to lower the bar.

bluemagica
10-24-2010, 06:34 AM
to me, it sounds like you are making a "key smasher" game, and I don't see the "graph" part in your description of the gameplay, but in any case, I would suggest using the graphics api to draw the bar.

function updateBar(range:Number):void
{
graphSprite.graphics.clear();
graphSprite.graphics.lineStyle(2,0x80000F);
graphSprite.graphics.beginFill(0xB50000);
graphSprite.graphics.drawRect(30,100,20,-range); // 30, 100 are the coordinates of where the bar is supposed to start, change it to what you want.
graphSprite.graphics.endFill();
}


//you call the function like
// updateBar(45);
// or
// updateBar(p1_barHeight); where p1_barHeight is assumed to be a simple variable which increases on keypress.



For the slowly decreasing part, you can use a timer, or simply subtract a small value from the height variable in an enter_frame event, as long as it is greater than 0.