Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 712 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
2D Shadows #372689
06/03/11 16:07
06/03/11 16:07
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline OP
User
hopfel  Offline OP
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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


Hilf mir, dir zu helfen!
Re: 2D Shadows [Re: hopfel] #372693
06/03/11 16:50
06/03/11 16:50
Joined: Jul 2010
Posts: 974
United Arab Emirates, Dubai
TheShooter Offline
User
TheShooter  Offline
User

Joined: Jul 2010
Posts: 974
United Arab Emirates, Dubai
What about to create an image with a shadow already thrown. Should save performance. : )


Staub ist das neue Prime!!

Programming is like sex:
One mistake and you have to support it for the rest of your life.

Aktuelles Projekt: http://thisiswargame.bplaced.net/index.html

A8 Commercial *freu*
Re: 2D Shadows [Re: TheShooter] #372695
06/03/11 17:05
06/03/11 17:05
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline OP
User
hopfel  Offline OP
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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. ^^


Hilf mir, dir zu helfen!
Re: 2D Shadows [Re: hopfel] #372699
06/03/11 17:38
06/03/11 17:38
Joined: Jul 2010
Posts: 974
United Arab Emirates, Dubai
TheShooter Offline
User
TheShooter  Offline
User

Joined: Jul 2010
Posts: 974
United Arab Emirates, Dubai
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


Staub ist das neue Prime!!

Programming is like sex:
One mistake and you have to support it for the rest of your life.

Aktuelles Projekt: http://thisiswargame.bplaced.net/index.html

A8 Commercial *freu*
Re: 2D Shadows [Re: TheShooter] #372705
06/03/11 18:23
06/03/11 18:23
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline OP
User
hopfel  Offline OP
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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.


Hilf mir, dir zu helfen!
Re: 2D Shadows [Re: hopfel] #372708
06/03/11 18:49
06/03/11 18:49
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
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.

Re: 2D Shadows [Re: Slin] #372713
06/03/11 19:35
06/03/11 19:35
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline OP
User
hopfel  Offline OP
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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


Hilf mir, dir zu helfen!
Re: 2D Shadows [Re: hopfel] #372717
06/03/11 19:54
06/03/11 19:54
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
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...

Re: 2D Shadows [Re: Slin] #372738
06/03/11 21:45
06/03/11 21:45
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline OP
User
hopfel  Offline OP
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
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.


Hilf mir, dir zu helfen!
Re: 2D Shadows [Re: hopfel] #372741
06/03/11 21:59
06/03/11 21:59
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
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


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1