We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there! I was trying to make different platforms to move in x at the screen. I cannot find out how to do it with an array list... Platforms must be different each other about sizes.
Thanks in advance :)
Answers
I don't see an ArrayList at all in your code. Have you even tried to create one based on the examples?
Even then, you would only use an ArrayList if you want to have platforms that start and stop existing a lot. I think what you should really do first is to not worry about ArrayLists at all, and instead just write a MovingPlatform class.
Hey there, good morning! Here's my code! Now platform (terra) is moving from one point, what should I do if I want that different platforms appear and move in x? (maybe using an array list?)
I know how ArrayList works, but I don't know how to apply at my code...
@TfGuy44 I've written a void terra (platform) to be moved in the x... any help?
Thanks! :)
@jeremydouglass I've tried and I don't know how to use it. I understand how it works but I don't know how to apply in my code... Thanks
If you have class Platform you can have an ArrayList of that class
See tutorial objects
ArrayList platforms = new ArrayList ();
see class would know position and size
Class = cookie maker
Object = cookies
Okay! Now I've created the Array! But why it only appear one single platform? If I declared that n = 50 (number of platforms)... Can anyone help me please?
Thanks in advance guys! I'm reaching what I was searching for! :) [-O<
They are presumably all on top of each other
Make vx_terra an array too, type float
Fill it with different random values between 1 and 4 in setup
I don't understand you, I've changed the code but when I play it don't change anything... :( vx_terra it's a float already
PLEASE PLEASE HELP! I want to understand it @Chrisir / @TfGuy44
as said make vx_terra a float array, not a float variable
posx_terra is an array
Make the same for vx_terra
Post your entire code after the changes - how can we see what is wrong when you don’t show your current code ...?
Here, I wrote you a Platform class.
See how there is just one Platform object, called
p0
? Well now your goal is to have an ArrayList of Platforms.It doesn't matter if you have code in many tabs. Post it all here in one chunk of code.
I've since gone platform-crazy!
So this is what i'm working at, don't know why the ball do not appear when I play.. (ball is the void personatge line 178 )
PICTURES: "FONDO.png" "INSTRUCCIONS.png" "MENU.png" "NIVELLS .png"
I've changed the code a bit so the ball jumps, but it seems it goes veeeeery fast!
can you make it go slower?
add less
@chrisir i’ve tried but I don’t know how and why it goes so fast... if anyone knows how to please tell me
Do you mean the speed of posx_personatge ?
That’s
posx_personatge ++;
try
posx_personatge += 0.2;
Make sure posx_personatge is a float
But what posx_personatge ++; is making is increassing / moving the ball in x, I want the velocity in y to be slower
Yeah both lines are next to each other
For x and for y
So what should I change in the code? :-S
Okay @Chrisir & @TfGuy44! Trying to understand I simplified the code. This code makes the ball bounce correctly in a good velocity in y. But the array --> Obstacles plataformes [] = new Obstacles [100];
isn't working... why? :-/
thanks for all your time! :)
This
Obstacles plataformes [] = new Obstacles [100];
belongs in setup not draw
It’s
Obstacles[[ plataformes = new Obstacles [100];
By the way.
I also suggest to Make this global
Before setup
Obstacles[] plataformes ;
in setup
plataformes = new Obstacles [100];
Tried and didn't work either.. :(
What happens now and what do you want to happen ?
Post your entire code
Thanks so much @Chrisir, what I want to happen is that the ball bounce as it does in the code you shared and the background (black platforms) moves in the x direction. But I want the background to be different every time. Thats why I want it with an array...
Yes I didn’t want to spoil the fun for you
In programming this for yourself
I just showed you how to get started
Start by passing more parameters to the obstacles in line 42 and 159:
eg pos x and y and width and height for each platform
And a speed
Make sure you fully understand the code (there is a tutorial on objects and classes) and then enrich it with your wishes
Okay @Chrisir! I've changed the parameters and now its closer to my objective than then! Thanks so much !! But there's something I cannot understand..
Why the number of platforms [x] changes the ball conditions??
I don't know why :(
I'm confused. Why is your player movement happening inside your Obstacle class?
Uhmmm where would you place it @TfGuy44? At void draw? But if I change the player movement the player don’t interact with platforms..
How would you do it? @TfGuy44 & @Chrisir Please show me! [-O<
??
just try it out for yourself
Adress and call the player class from function draw()
Check distance to platforms inside player class?
what do you mean by
what do you mean by