Dynamic sprite difficulty

Started by FortressCaulfield, Sat 20/07/2024 20:48:35

Previous topic - Next topic

FortressCaulfield

Trying to use dynamic sprites to create a space window with stars and such whizzing by and none of it is working. I copied the code from the 2nd reply here:

https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/round-gui-for-a-minimap/msg636663807/

Code: ags
DynamicSprite* space;
int spacex = 0;

void repeatedly_execute_always()
{
  space = DynamicSprite.CreateFromExistingSprite(946);
  space.Crop(spacex, 0, Game.SpriteWidth[948] + spacex, Game.SpriteHeight[948]);
  space.CopyTransparencyMask(948);
  oSpace.Graphic = space.Graphic;
  spacex += 1;
}

946 is a long image of stars. 948 is the mask for the window.

When the room loads, it immediately crashes, complaining the transparency mask is not the same size. That's sprite 948. I tried putting in the height and width values directly, referincing them from 948's dimensions, modifying by -1, +1, nothing made it happy.

If I comment out that line, then the image loads but never updates even once. The repeatedly execute and spacex increment is working, it just never ever recrops the image.

EDIT: Turns out the redraw was working, but 1 pixel per cycle was too slow to notice. So that problem is solved. Still having the crop problem, and now a new one:

How do I make the image loop?
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

Khris

#1
The Crop command's 3rd and 4th parameters are width and height, not x2 and y2.
I.e. you need to remove " + spacex" when you pass the width.

As for looping, replace "spacex += 1;" with:
Code: ags
  spacex = (spacex + 1) % (Game.SpriteWidth[946] - Game.SpriteWidth[948]);

The mod operator calculates the reminder, meaning it's the shorter way of doing:
Code: ags
  spacex++;
  if (spacex == SMALLEST_INVALID_VALUE) spacex = 0;

Btw: you can do this without cropping / copying the transparency mask: put the room background including holes for the windows in a sprite, then simply draw the stars followed by the room sprite to the room background's DrawingSurface.

FortressCaulfield

Thank you, that was driving me bananas.

> spacex = (spacex + 1) % (Game.SpriteWidth[946] - Game.SpriteWidth[948]);

This works also, thanks, just had to add a repeated section to the end of the graphic so that restarts are seamless. I'm familiar with mod but I rarely think to use it like this where you're making use of the return of the first operator if the 2nd one is bigger.
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

SMF spam blocked by CleanTalk