I'm makeing game for mobile devices. In the game you "drive" spaceship and try to collect as many stars as possible and avoid obstacles. The game is based on Starling framework. I have now made the background and the spaceship. Background is scrolling to opposite direction what give feeling that the spaceship is moving. And then I'm able to move spaceship with touchevents.
Next thing is that I should add obstacles. I have four types of obstacles. Before they spawn, I would like that watchout image would appears before the obstacles apperas from up. The obstacles should spawn randomly on X-axis and spaceship should avoid to crashing them.
After that I should add stars what the spaceship should collect.
Could somebody please give me some code snippets or ideas how should should I do this, I'm very newbie?
I have tried to follow "Starting with starling series, but the game is so different in certain things and now I'm stuck with adding these obstacles.
If you want things to happen randomly, become familiar with using the Math.random() method. Figure out how to randomly select an obtacle from an array of the four of them. Figure out how to randoimly select an x value for placement of the different things using the width of the stage to determine your limits.
I have now mangaed to get sme Obstacle multiple time in same place. However, I should have four types of obstacles in my spritesheet. And also I'm not able to get those moveing down. Also every tips for optimizing are welcome.
Here's piece of my InGame:
private function moveObstacles():void
for (var i:int =obstacles.length-1; i>=0; i--)
tempEnemy = obstacles[i];
tempEnemy.y += timeCurrent*0.05 ;
private function makeEnemies():void
obstacles = new Array();
tempEnemy = new Obstacle;
tempEnemy.x = Math.round(Math.random()*480);
I have been thinking that should I use event.ENTER_FRAME to move them...?
Yes, you could sould probably use ENTER_FRAME to drive movingthe objects. I do not know what "currentTime" involves... I would just increment the y property, as in: tempEnemy.y += 1;
In your makeEnemies function you should be selecting one of the obstacle classes (you appear to only have one class named Obstacle). Have an array with the different class names as String values and use something like the following to instantiate whichever one you select randomly...
var ClassRef:Class = Class(getDefinitionByName(randomClassName));
var classInstance:* = new ClassRef();
In the code above, randomClassName is whichever string you selected from the obstacle classes array.
You should not be reinstantiating the obstacles array each time you make an enemy - you lose any you have i it that way.
Thanks again for these tips. Somhow I don't know what was the problem, because I wasn't able to get Obstacle from Array... I managed to get the type of the obstacle whit Math.ransdom...
Anyway next thing is to add Look Out -txt before the obstacles appears and then add collision detect.
Europe, Middle East and Africa