Paralex Starfield Thingy!

BlitzMax Forums/BlitzMax Beginners Area/Paralex Starfield Thingy!

Blitz Is Kool(Posted 2006) [#1]
Hi,

Can anyone help me with the creation of a paralex star field for a backdrop to my 2D game?

My idea was to craste two bit maps; one black as the lower layer, and one transparent to draw over the top.

Next I would shift them both (drawimage whatever,x,y) down one pixel, with the lower layer moving down every other step.

Of course I would need to redraw part of the image off the top of the screen to create a wrap around thingy - thus I would need 4 drawimages... two for the scroll and two for the followthrough.

I hope you can get my drift.
I can draw my main image over this then to create a floating-through-space ... thing!

Is this way too complex, or is their another way to do this?

Many thanks


H&K(Posted 2006) [#2]
That would probably work, but would just be for this game. Why not try to write a small particle engine, that just does stars atm.

Make a type, global image, (less you just want to plot), x,y corrods, and velocity multiplyer, (That is speed of ship, one and a half times etc). Then each frame draw the image, (or plot), before you draw the foreground. When the image/plot leaves the screen, destory it. (Well make a new one at the screen start)


Blitz Is Kool(Posted 2006) [#3]
Hi,

Many thanks.

The Global idea does seem to be getting a bit complicated!!! It was just an idea I had which to be quite honest, I don't really know how well it will work.

I'm not too well up on how to use Types ... I'm so used to Dim arrays.

Thanks again for your help - I really appreciate your reply.


SillyPutty(Posted 2006) [#4]


Knocked this up quick, it is a crude example, but you will get the idea.


Grey Alien(Posted 2006) [#5]
drawing that many giant bitmaps seems a bit overkill, though quite a novel use of modern 3D card power. Go old school with an array of stars moving at varying speeds.


SillyPutty(Posted 2006) [#6]
Go old school with an array of stars moving at varying speeds.


Pretty much what I did above.


Grey Alien(Posted 2006) [#7]
yeah exactly, just backing you up.


ImaginaryHuman(Posted 2006) [#8]
You sure should not be using a custom type with a linked list to store stars. That's OOO! (object oriented overkill) All you need is one array of floats using two floats per star, X,Y coordinates. Then you need one other array of `add values` to add to each pair to move them. That's all.

Beyond that, it is a good idea to use the hardware, paste a bunch of stars on an image and then render the images moving at different speeds - although there are quite a lot of pixel unused so it's a little wasteful. The better thing would be a vertex array or an alpha texture.


Amon(Posted 2006) [#9]
Regarding SillyPutty's code, there's no need to remove the stars after they leave the screen. What I do is have a maximum amount of stars to create and when they leave the screen area I just recycle them by shifting them to the top again.

This saves a lot of objects being created and stops a lot of access to the list.


Grey Alien(Posted 2006) [#10]
I never looked at Putty's code in detail, but if that's what it does, then I agree with Amon. Recycling is where it's at man!


Booticus(Posted 2006) [#11]
Dude. This post has it all. of course, remove "Flushmem" and fix a miscommented bug or two, but its all there. 3d, 2d, OOPified, its pretty killer.

http://www.blitzmax.com/Community/posts.php?topic=48143#535778


OH Bear in mind that tesuji's code is pretty killer, even has directional and speed scrolling relative to where you click the mouse. I didn't notice that functionality right away till I actually moved the mouse and clicked places! Its pretty neat!


SillyPutty(Posted 2006) [#12]
Bear in mind, my code was a quick knock-up, based merely to give an example, I stated so in the post, ofcourse it could be optimised.

I agree with star recycling, and yes, arrays would be better suited. Simplicity is key, I need to re-evaluate my want to overcomplicate things , so yes, my code above is probably overkill :)

One nice thing though is that the starfield could be inherited from to provide diff types of starfield behavior.


H&K(Posted 2006) [#13]
should not be using a custom type with a linked list to store stars. That's OOO!


I dont think its overkill, but then It isnt the first time ive been accused. But I would almost certainly make a type.
(As Ive Said before, I have a type of Int Pairs)


Blitz Is Kool(Posted 2006) [#14]
Hi,

I just wanna say a really big thank you to you all for helping me with this issue.

So - what did I go for in the end?

I decided my initial idea of the Bitmaps was a little OTT.

The Types routine above was ok - much appreciate it dude for you taking the time out to do that for me, however, the array idea appealed to me more, due to the fact that I've worked with them for so long.

In the end it really was a doddle to write - just throw some floting pixels about and use the Millisecs() timer to shift them.

Instead of recycling them back to the top in their initial positions, I totally generated a new pixel so the starfield would look more random.

I also settled on three levels - I gave each pixel a code (1-level 1; 2-level 2; 3- level 3), each level drwn at a different shade and moved at a different time, thus creating a very cool scrolling starfield.

Implementing it into my game took a few hours as I needed to do a bit of screen flipping - something I haven't worked with before.

All up - a very beautiful and very nice touch to my game.

Once again, a big thanks to you all.