This site requires JavaScript, please enable it in your browser!
Greenfoot back
Joman2k
Joman2k wrote ...

2018/2/21

Infinite runner, scroller game. obstacle help

Joman2k Joman2k

2018/2/21

#
I have made a game similar to the game that you can play on google chrome when you have no connection where the objective is to jump over a load of cactus just by pressing the space bar. Well in my game i have managed to make a character that can jump and the background scrolls. All i need now is to make my wall spawn at random intervals and i don't know how i would go about that, any help would be appreciated, Thanks
Joman2k Joman2k

2018/2/21

#
Also i have tried using this piece of code for spawning random walls but it doesn't appear to work it says "method addObject in class greenfoot.World cannot be applied to given types; required: greenffot.Actor,int,int found:wall,int reason: actual and formal argument lists differ in length The code i tried is this: addObject(new wall(), Greenfoot.getRandomNumber(getWidth())); ps. im new to greenfoot and coding java in general
xbLank xbLank

2018/2/21

#
You want your walls to always spawn at the very end of the screen and they should not be flying in the air. So you have 2 constants for x and y where x = worldEdge - wallWidth and y = wallHeight You just want to modify the time in which each object spawns. Thats up to you. But Your spawning would look like this:
addObject(new wall(),x,y);
Joman2k Joman2k

2018/2/21

#
Thanks a lot! Just wondering if you know any loops i can use to constantly spawn them?
Super_Hippo Super_Hippo

2018/2/21

#
You don't need a loop. You will need a variable that you use as a timer in your world's act method.
Joman2k Joman2k

2018/2/21

#
oh ok thanks a lot man!
You need to login to post a reply.