Random creation of balloons

  ... discussions about development with the GLES1 branch of AndEngine.

Random creation of balloons

Postby Alex.S » Tue Apr 24, 2012 6:59 pm

Hello everybody!

My name is Alex. I am new here and i have a question. I have two balloons: one red and one blue, the thing is how can i spawn them on random locations along the x-axis??
Alex.S
 
Posts: 9
Joined: Sun Apr 15, 2012 2:02 pm

Re: Random creation of balloons

Postby john2994 » Tue Apr 24, 2012 8:04 pm

i am also new to AndEngine and to programming but maybe i can help.
u cant do Random rnd = new Random();
after initialize your screen View with a name e.g GameView after print the balloon with balloon image and x considerations rnd.nextInt(GameView.getWidth()-balloon.getWidth) i think thats all
john2994
 
Posts: 13
Joined: Sat Jan 07, 2012 5:07 pm

Re: Random creation of balloons

Postby Alex.S » Tue Apr 24, 2012 8:52 pm

One more thing. I dont have just two balloons. I am planning that (many) balloons will be created at the bottom of the screen one by one and fly all the way up. This is something i dont know for sure how to code.
Alex.S
 
Posts: 9
Joined: Sun Apr 15, 2012 2:02 pm

Re: Random creation of balloons

Postby OzLark » Wed Apr 25, 2012 2:19 am

Alex.S wrote:bottom of the screen one by one and fly all the way up.


To make balloons fly, you need to apply a negative to gravity LinearVelocity or ApplyForce to the balloon bodies in your update loop - be careful though that your FPS does not effect your balloon speed.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Random creation of balloons

Postby Alex.S » Wed Apr 25, 2012 8:31 am

Cant i just use MoveYModifier to make them fly upwards along the y-axis?? Because i would like to dont use physics in my first game.
Alex.S
 
Posts: 9
Joined: Sun Apr 15, 2012 2:02 pm

Re: Random creation of balloons

Postby OzLark » Wed Apr 25, 2012 8:41 am

Yes, ignore my advice if you're not using physics.

It's much easier (as you suggest) if you don't need physics.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Random creation of balloons

Postby Alex.S » Wed Apr 25, 2012 9:45 am

But that doesnt solve my question about random spawn of balloons at the bottom of the screen.
Alex.S
 
Posts: 9
Joined: Sun Apr 15, 2012 2:02 pm

Re: Random creation of balloons

Postby OzLark » Wed Apr 25, 2012 10:23 am

You can calculate a random X location by using MathUtils.random(minX, maxX) and you can do this based on time using a registered update handler on your scene:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. registerUpdateHandler(new TimerHandler(3.0f, true, new ITimerCallback() {
  2.         @Override                                                            
  3.         public void onTimePassed(final TimerHandler pTimerHandler) {                                                                                  
  4.                 // do spawning here.    
  5.         }
  6. }));
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Random creation of balloons

Postby Alex.S » Sat Apr 28, 2012 8:57 pm

Can it look something like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. registerUpdateHandler(new TimerHandler(3.0f, true, new ITimerCallback() {
  2.  
  3.                 @Override                                                            
  4.  
  5.                 public void onTimePassed(final TimerHandler pTimerHandler) {                                                                                  
  6.  
  7.                         // do spawning here.    
  8.  
  9.                 }
  10.  
  11.         }));
  12.                 scene.attachChild(textScore);
  13.                 scene.attachChild(blue_baloon);
  14.                 scene.attachChild(red_baloon);
  15.                 scene.registerTouchArea(red_baloon);
  16.                 scene.registerTouchArea(blue_baloon);
  17.                 scene.setTouchAreaBindingEnabled(true);
  18.                 return scene;
  19.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Because thats giving me an error: the method registerUpdateHandler(TimeHandler) is undefined for the type BalloonpopActivity
Alex.S
 
Posts: 9
Joined: Sun Apr 15, 2012 2:02 pm

Re: Random creation of balloons

Postby OzLark » Sun Apr 29, 2012 4:11 am

Call registerUpdateHandler() on the scene like:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. scene.setTouchAreaBindingEnabled(true);
  2. scene.registerUpdateHandler(new TimerHandler(3.0f, true, new ITimerCallback() {
  3.                 @Override
  4.                 public void onTimePassed(final TimerHandler pTimerHandler) {
  5.                         //
  6.                         // put your code to do spawning here.
  7.                         //
  8.                         scene.attachChild(blue_baloon);
  9.                         scene.attachChild(red_baloon);
  10.                         scene.registerTouchArea(red_baloon);
  11.                         scene.registerTouchArea(blue_baloon);
  12.                 }
  13. }));
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am


Return to GLES1

Who is online

Users browsing this forum: No registered users and 13 guests