Dynamic sprite from player current frame in RepExecAlways function

Started by Giacomo, Sun 04/07/2021 15:08:21

Previous topic - Next topic

Giacomo

Hi everyone!

I am trying to create a Dynamic Sprite from a character's current frame
to make a shadow effect.

I am a newbie and searched for answers both in manual and threads, but I am sorry to say that I'm stuck already.

So, created a dummy character that follow the player like a water reflection.
This character's animation frames are bitmap files taken by editing the player
sprites to appear black and vertically mirrored (I modified Roger's sprites in sprite editor),
then uploaded to AGS, assigned to dummy character view and loops and made semi-transparent via script.
Can this be a good start point?

Futhermore, I'd like to modify these dark bitmaps calling Dynamic Sprite in RepExecAlways function and applying maths operations on them; I wonder if it is possible to do it on the current game frame, I mean, loading a modified bitmap sprite as Dynamic sprite of the chatacter frame.

The following instructions work as they should: create a copy of Roger's current frame, loop and view and draw it on room background, copying is walk animation at  his every step. I left the dummy character out of instructions for the moment, because I'd like to work directly on Roger
frame to do my tests.

But I have problems in deleting Dynamic sprite drawn on background surface,
so I ask you guys if it is possible to clean the background every time i draw a new frame
from Roger's animation.

Thank you all in advance,
Giacomo
https://ko-fi.com/giacomo97557 To support Falco's adventures

Giacomo

I solved using Overlay, yet I wonder if a manipulation of the sprite is possible
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

You can use DynamicSprites for a character's walking frames, yes. The DynamicSprites need to exist in the global scope (i.e. not be declared inside a function) and you can assign them to a character using the ViewFrame commands.

Using the "draw on background" approach, I did this: https://www.youtube.com/watch?v=tH-pPFi-WUM

This requires to create a backup of the room background and restore it each frame, before drawing the shadows onto it.

bx83


Khris

Not really, and it's really old code so probably not useable as-is anyway.

Vincent

Quote from: Khris on Mon 05/07/2021 11:24:07
Not really, and it's really old code so probably not useable as-is anyway.

I always wanted to have what you have done in that video into a module, I hope you will do it one day or a revisited version for the new ags. Plus it remind me that I always wanted to have your 3D rain into a module :( I hope you will one day. A sure thing is that every game I do has at least one of your modules.

bx83

Khris, could you... show us the code? If only for educational purposes about how to make a dynamic sprite out of a sprite. That is amazing; I was planning to just use a translucent circle under a character as a shadow, that's it.


Giacomo

Hi Khris,
it's a great pleasure to meet you.

I learned the basics of  AGS mostly thanks to your replies in threads, so thank you very much, you are a superstar!

I have already seen your video and I was happy to know that a dynamic shadow effect is possible,
and thanks to that video I decided to give it a try myself.

Maybe the discussion should be moved in the dynamic shadow thread, so
please let me know if I should post there. The fact is that so far my doubts concern with background cleaning from drawing surface.

Here's the thread:

https://www.adventuregamestudio.co.uk/forums/index.php?topic=57760.msg636615771#msg636615771

[EDIT: I removed this part because it is full of errors. Sorry ]

About Dynamic Sprite drawn by player frame, please tell me something more.

I did as it follows:

I define Roger's View Frame, Dynamic Sprite Drawing Surface outside functions.

I am working in room script and not in global just because I am doing my tests in a single room but
wonder if I can do the same in a RepExecAlways function in global script and how that should work. The fact is
that every room having a light source requests it is own useful coordinates point.

When I call RepExecAlways room function I copy Roger's current frame and draw it on BG. How can I clean the BG?

Can you please show me the code you use to clean the background at every game cycle?

Thank you very much!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Khris

Hi Giacomo,

sorry I don't have time right now to read all that, but as for restoring the room background:

Code: ags
DynamicSprite* bgBackup; // declare in room scope

// "enters room before fadein" room event linkage required!
function room_Load() {
  // create backup of room background graphic
  bgBackup = DynamicSprite.CreateFromBackground(); // will use first frame (0)
}

// custom function so rep_exe isn't cluttered
function DrawShadows() {
  DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  ds.DrawImage(0, 0, bgBackup.Graphic); // restore room background
  // draw shadows here
  // ...
  ds.Release();
}

// no event linkage required
function repeatedly_execute() {
  DrawShadows();
}

Giacomo

Khris, thank you so much!!

For what concern the rest of my post, please take your time and let me know
once you can. I hope I explained myself well enough.

So, the function as you wrote it can be used also for water reflections and vertical mirrors (I know I also need baselines),
am I right?

My first mirror test almost worked good and the script was much more messy....This is simply great!

Thank you again!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Giacomo

Excuse me guys, I made an error in my draw.

I will solve it and post new results in the right thread.

Khris answered my question so, we are done here!

Thank you again!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Giacomo

Quote from: Khris on Tue 06/07/2021 13:27:38
Hi Giacomo,

sorry I don't have time right now to read all that, but as for restoring the room background:

Code: ags
DynamicSprite* bgBackup; // declare in room scope

// "enters room before fadein" room event linkage required!
function room_Load() {
  // create backup of room background graphic
  bgBackup = DynamicSprite.CreateFromBackground(); // will use first frame (0)
}

// custom function so rep_exe isn't cluttered
function DrawShadows() {
  DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  ds.DrawImage(0, 0, bgBackup.Graphic); // restore room background
  // draw shadows here
  // ...
  ds.Release();
}

// no event linkage required
function repeatedly_execute() {
  DrawShadows();
}

https://ko-fi.com/giacomo97557 To support Falco's adventures

SMF spam blocked by CleanTalk