2D Shadows

Posted By: hopfel

2D Shadows - 06/03/11 16:07

Hey guys. ^-^

I'm programming a little 2D-RPG and want my 2D-objects to throw a shadow.
This shadow should be rotatable and dilatable, so I need the position of every pixel.



I think, the best way for that is to save the shadow-information into structs and every pixel-position into an array of it,
but the shadows have different sizes, so the arrays would not have the same lenghts.

Well, I could define giant arrays which could save every size of shadow, but there are many shadows, so there would be thousands of not used variables.

Also Bitmaps are very slow to read pixels out, so changing the lenght of the array would be the smartest way,
but the manual says, I can't change them at runtime, so is there a way, to define every struct with an other array-lenght?
Or do you have an other idea how to solve that?

Some tips would be very nice. :3
~greets
Posted By: TheShooter

Re: 2D Shadows - 06/03/11 16:50

What about to create an image with a shadow already thrown. Should save performance. : )
Posted By: hopfel

Re: 2D Shadows - 06/03/11 17:05

Quote:
This shadow should be rotatable and dilatable

I want to rotate the shadow depending on the sun, so I have to create it at runtime.

But thx. ^^
Posted By: TheShooter

Re: 2D Shadows - 06/03/11 17:38

Dynamic? First, you need 2 Images. The normal tree, and the grey. Then create a script, which lock the grey tree to the normal tree, and which rotate the shadow addicted to the sun angle. I'm not the master scripter, but logical, it should work. : )

regards, The Shooter
Posted By: hopfel

Re: 2D Shadows - 06/03/11 18:23

No no, rotating and expansion is really not the problem, I want to save the several pixel-positions of the shadow in an array so I can write my own functions for expansion and rotating (I have my reasons doing that), so I need dynamic arrays for different shadow-sizes.
Posted By: Slin

Re: 2D Shadows - 06/03/11 18:49

You can dynamically allocate memory using sys_malloc. But as you most probably want a texture as result, I would just manipulate the textures directly.
Depending on what kind of changes you need to do you can also speed the texture manipulation up a bit using some directx magic to "directly" (in "" as in reality it will just be a copy) access the textures memory without the gamestudio stuff wrapped around it.
Posted By: hopfel

Re: 2D Shadows - 06/03/11 19:35

I want the shadow to overlap other objects (with the same layer as the own one), but not the own one itself,
and for rotating and expanding I have to calculate every pixel,
so I think it's easier to have all pixelpositions saved in an array.
Code:
You can dynamically allocate memory using sys_malloc.


That's the part I need. ^-^
I just don't know how to code that for arrays. I think a little example should do the job. laugh
Posted By: Slin

Re: 2D Shadows - 06/03/11 19:54

http://tinyurl.com/42jzmde
I think I mention all you need there. An example would probably help you faster, but won´t make you understand why it works the way it does...
And still, I would recomment just manipulating the textures.
Overlapping of things can btw be done by a different depthorder for example...
Posted By: hopfel

Re: 2D Shadows - 06/03/11 21:45

I know the basics already, I lerned them 4 years ago. I was looking for a way to change the size of an array at runtime, and...

...well, like always I ask something in this forum, I found the solution in the manual myself. And like always I feel like a total jerk. Argh... o.-'

The perfect answer to my question was in the example to sys_malloc, but I always just looked for malloc, where I, of course, found nothing helpful.
Now I understand and it works.

Thx for helping.
Posted By: WretchedSid

Re: 2D Shadows - 06/03/11 21:59

Originally Posted By: hopfel
I know the basics already, I lerned them 4 years ago. I was looking for a way to change the size of an array at runtime, and...

You can't say you know the basics without knowing how to allocate and re-allocate memory at runtime oO
Posted By: hopfel

Re: 2D Shadows - 06/03/11 22:13

I saw sys_malloc neither in your tutorial nor in the GS workshops.
To be exact, I saw them the first time I worked with my own structs.
Srsly, what basics are that hidden? xD
Posted By: Hummel

Re: 2D Shadows - 06/03/11 22:15

'basics' is a relative term, Sid. I dont think that runtime memo alloc stuff necessarily belongs to the 'GS-basic', especially to 4 years old GS-basics-knowledge.
© 2024 lite-C Forums