Page 2 of 2

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 6:01 pm
by infratec
Ups ....

does not work with OpenScreen() :oops:

Sorry.

This is now obsolete, see further posts,

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 6:05 pm
by Kamarro
Thanks again infratec,

But no, it will not work at all.
Program is to big, I have a lot of counters being displayed on top of sprites and I also need to display sprites on top of the animated gif.
Since my posts were deleted, I will repeat what I wrote before, showing a bit of what I've done to solve this:

I have the Introductory program first, with procedures, variables, subrotines, definition of sprite's adresses, file locations, etc.
I also already loaded the animation frames into a table, but I'm showing it here in a much raw version. It's easy to do it, and I'll try to remember the most of it (I am not home, I don't have the program with me, so, I'll create fictional names for things):

Code: Select all

Init Display, Screen, etc.

Radar=0
Frame=1
MaxFrames=24

Repeat
   FlipBuffers()
   ClearScreen(RGB(0,0,0))

   DisplaySprite(1000,0,0)                ; THIS IS THE BACKGROUND OF THE GAME

   Gosub Routine1
   Gosub Routine2
   Gosub RoutineToVerifyIfRadarMustBeShown

If Radar = 1                                   ;  The Radar Animation must be displayed

   DisplaySprite(HandScan,200,150) ; This displays the device JPG on Top of the Background (It's a Game Window)
   DisplaySprite(Frame,500,250)      ; This displays one Frame of the GIF that I Photoshoped and converted into 24 small JPGs on top of HandScan

  Frame=Frame+1                           ; Here I increment the Frame to show (IF)

   If Frame > MaxFrames
      Frame = 1
   EndIf

   Gosub RoutineFINDobjects           ;This Puts Another Sprite GIF on Top OF this Frame To Show Things IF detected

EndIf

   Gosub Routine3
   Gosub Routine4
   Gosub Routine5

   If Saved=1
      DisplaySprite(1005,0,0)
   EndIf

etc, etc, etc... More than 2000 lines inside this LOOP

Until Condition to end this Repeat and start another one, unless game ends or user saves and quits.
THIS IS JUST AN EXAMPLE OF HOW I DID IT, but is very hard to decompose a lot of animated GIFs that I have already created into JPGs to show them like this. I'd like to use a DisplayAnimatedSprite, but since there is no option to do it, I will use my process.

Thank you ALL for your help!

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 7:29 pm
by infratec
Changed my listing above.
Now it also works with OpenScreen(). (only tested in Win 10) :wink:

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 8:05 pm
by netmaestro
@infratec:
I had to change the code in two places to make it work.
First, my computer can't make an 800x600x32 screen. I had to use ExamineScreenModes() to get the numbers to plug in here:

Code: Select all

OpenScreen(1920, 1080, 32, "", #PB_Screen_WaitSynchronization, 64)
Secondly, your code for creating the sprite is faulty. You're using the result of CreateSprite for the static sprite number, whereas you can only do that for #PB_Any. When I modified the code to:

Code: Select all

    If Sprite = #PB_Any
      Result = CreateSprite(#PB_Any, ImageWidth(Image), ImageHeight(Image), Mode)
    Else
      CreateSprite(Sprite, ImageWidth(Image), ImageHeight(Image), Mode)
      result = sprite
    EndIf
Then it worked without problems.

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 8:38 pm
by infratec
@netmaestro

My code looks like this:

Code: Select all

If Sprite = #PB_Any
      Sprite = CreateSprite(#PB_Any, ImageWidth(Image), ImageHeight(Image), Mode)
      Result = Sprite
    Else
      Result = CreateSprite(Sprite, ImageWidth(Image), ImageHeight(Image), Mode)
    EndIf
So with #PB_Any I use the return value as sprite.
With a 'static' number as sprite, I don't change it. So the static number is still Sprite.
Result is only used for verifcation that CreateSprite() was Ok in both cases. I use Sprite for further processing and not Result.
I can not see my fault.
Please explain it a bit more.

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 8:46 pm
by netmaestro
The result of CreateSprite when using a static number like 1 or something is not the sprite number. It is only nonzero.
PB Doc for CreateSprite wrote:Return value
Nonzero if the sprite has been created, zero otherwise. If #PB_Any was used for the #Sprite parameter then the generated number is returned on success.
Try this code:

Code: Select all

InitSprite()
OpenWindow(0,0,0,640,480,"")
OpenWindowedScreen(WindowID(0),0,0,640,480)

result = CreateSprite(8,32,32)
Debug result
The way you have it coded, you're expecting 8 to be debugged. It's not 8. You can't return the result, you must return the sprite number.

Re: Help with Animated GIFs...

Posted: Sat Jan 21, 2023 9:28 pm
by infratec
:?: :?: :?:

I don't use Result as sprite. I use Sprite as sprite.

Code: Select all

  If Result
      *AnimatedGIFSprite = AddMapElement(AnimatedGIFSprite\GIFInfoMap(), Str(Sprite))
      *AnimatedGIFSprite\OrgImage = Image
      *AnimatedGIFSprite\Sprite = Sprite
Result is only for validation and this is needed in the static variant, because I can call it with 0 as sprite.
In your version, I can not check if CreateSprite was sucessfull in the static variant, because you ignore the returned value.

Re: Help with Animated GIFs...

Posted: Sun Jan 22, 2023 10:06 am
by Kamarro
Infratec, you're completely right in your code. Netmaestro is misinterpreting things about the code.
Besides, the Result variable in PureBasic is almost always 1 or 0, for True or False, and not just a nonzero. Text says that Result will be Zero if NOT OK, and must be read like that: Zero if OK, Not Zero if NOT OK.
Nothing in your program says that you expected the result to be anything to be used otherwise than to check a sucessful operation or status condition.

Your code works well, I just can't use it because I'm displaying a lot of sprites on screen to compose the image. Usually people tends to interpret Sprite as a moving icon on screen and not as an image to overlay another image.
Most people here looks to be younger than me to know a game from the 90's, others look much older to be playing games, but Fallout (the original one, not the 3 or 4 versions) is the thing most similar to what I'm doing: I have a map terrain composed by tiles (512x512 isometric sprites), figures of characters of the game (80x128 moving and static sprites), a lot of graphic objects that appear under certain conditions on top of other sprites, and, of course, a large number of sub-screens that are displayed on top of all this with Character Statistics, Inventory, Maps, Shopping, General Events, Options, Dialogues of text,etc, etc. And everything is openning and closing on top of other screens and sprites.
To get things much more difficult, I have only one option to write texts over images, the DrawText. This is too much for any slower code and sometimes I also have to use SubRoutines and Spaghetti Lined Code, instead of Procedures, because one results faster than others.
Your code is nice, but these are the reasons why I can't use it. It's a long code with too many sprites, but I'm looking at your code to create a variation that will turn my ready made Animated GIFs, into a bunch of JPGs to be used normally.

You really helped me with your idea and code. Now I'm getting a AnimGIF-TO-StackJPG program to reduce my work with Photoshop that would kill me when I have more than 60 animations to decompose.

Wonderful, man.
Thanks a Lot!