Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
quiz master
16
Years of Service
User Offline
Joined: 4th Jul 2008
Location:
Posted: 11th Jul 2008 10:34
so I have a general idea of what an array does but I don't know how to use them.

so lets say I wanted to create two rows of 20 tiles at the top of the screen using a bitmap called "tile.bmp"

how would I do that using an array rather than creating an individual sprite for each tile?
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 11th Jul 2008 13:36
You need more than an array. You need an equation in a for/next function to space out the tiles, with the image's x and y coordinates mathematically predetermined and stored in arrays.

DIM Array(Integer)
for P = 1 to Integer
Array(P) = xvalue*P
next P

This stores xvalue*P into an array. They are easily called upon in different portions of the code

for P = 1 to Integer
sprite 1+p,Array(P),yvalue,image#
next P

Or use paste image or whatever.
quiz master
16
Years of Service
User Offline
Joined: 4th Jul 2008
Location:
Posted: 12th Jul 2008 09:38
I made an array! ...sort of. I got it to make bricks. the problem is it won't stop making bricks. I obviously still don't understand what is going on here. heres my code so far. Maybe someone can see what I'm doing wrong.

Nano brain
16
Years of Service
User Offline
Joined: 7th May 2008
Location:
Posted: 12th Jul 2008 23:40 Edited at: 12th Jul 2008 23:43
The for loop is within the do loop, and without a flag. So, this causes the program to continually make bricks using the for loop, without anything to stop it.

So setup your code with a brick function, which is called only when you wish it to be called. Or place the for loop above the do statement.

Function:


Now place this function below your main program loop(your do loop. Then call it when necessary, passing it the variables needed. This function itself will allow for very dynamic block creation.

EX:


I hope this helps. I don't know your knowledge of functions, so ask if you don't understand. For now, try to understand that placing the block making for loop within you do loop was causing the blocks to be made every single frame of the game.
quiz master
16
Years of Service
User Offline
Joined: 4th Jul 2008
Location:
Posted: 13th Jul 2008 10:54
thanks! I figured it out! It didn't work at first and it took my brain for a loop, but I figured out "block" also needed to be incremented by one during the for loop in order to create more than one sprite.

Login to post a reply

Server time is: 2024-11-25 02:08:36
Your offset time is: 2024-11-25 02:08:36