How to create infinite platforms like in game "Doodle Jump"

How to create infinite platforms like in game "Doodle Jump"

Postby NiceBoy » Sat Apr 29, 2017 7:04 pm

Hi, I want to create 3 platforms, that changes own places when ball is jumping. I think i should use Array, but I don't know how?

This is my code where I didn't used Array, just loop "for":

Creating "platform":

Code: Select all
public void createBuckets(float x, float y){
        bdef.type = BodyDef.BodyType.KinematicBody;
        bdef.position.set(x/ PPM ,y / PPM);

        bucket = world.createBody(bdef);

        box.setAsBox(60 / PPM, 20 / PPM);

        fdef.shape = box;
        fdef.density = 5;

        bucket.createFixture(fdef).setUserData("bucket");
    }


and in "create()":
Code: Select all
for(int i=0;i<=PLATFORM_COUNT;i++){
            createBuckets(rand.nextInt(Gdx.graphics.getWidth()),PLATFORM_MARGIN*i);
        }




But It doesn't work :| :|
NiceBoy
 
Posts: 1
Joined: Sat Apr 29, 2017 6:56 pm

Re: How to create infinite platforms like in game "Doodle Ju

Postby maosk21 » Sun Jun 11, 2017 1:38 pm

hi. i can see that you're using box2D.

Anyway...

I don't really understand your question. Tough, it's easy to make never ending games.

Tip:

For items to spawn on your map use an Array with the type Rectangle.

Array <Rectangle> list_full_of_items;
this.list_full_of_items = new Array<Rectangle>();

Now if you would like items to spawn, simply create items and add them to the array.

in your render function you can now draw all the items added to the array:

for(Rectangle items : list_full_of_items) {
Drawbatch.begin();

your_sprite.setposition(items.x, items.y);
your_sprite.draw(Drawbatch);

Drawbatch.end();
{

For the camera to follow the player. you will have to transfer the player positions to your camera.
maosk21
 
Posts: 6
Joined: Sun Jun 11, 2017 1:24 pm


Return to Newton

Who is online

Users browsing this forum: No registered users and 1 guest