Author Topic: Animated texture / ANIs not working with gr.DrawImage ?  (Read 12757 times)

0 Members and 1 Guest are viewing this topic.

Offline Parias

  • 27
Animated texture / ANIs not working with gr.DrawImage ?
I've got a couple of things I'd like to try for a campaign I'm working on, and for various plot purposes would like to be able to trigger playback of a full-color ANIs (pre-existing ones from the base game for now) directly to the player's viewport. I've had little prior experience with LUA scripting though, so I'm taking this as a learning opportunity to try and figure things out as I go.

To assess if what I want to do is even possible, I've pieced together the following basic script as a quick test:

Code: [Select]
#Global Hooks

$HUD:

[

tex = gr.loadTexture('cb_sm1-01_d',true)

gr.drawImage(tex)

]

#End

This works in the sense that it loads one of the command briefing ANIs from the main campaign and throws it into the top left of the player's viewport. However, only the first frame is shown - the ANI doesn't animate.  Is what I'm trying to do even supported - is there a better way of doing this?

I've been considering trying to create some kind of flat object in the 3D gameworld and attaching that right in front of the player instead, then applying a texture to it (if I can even figure out how) - but I thought this might be a more straightforward way of doing it.
« Last Edit: July 11, 2014, 11:56:48 am by Parias »

  

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Re: Animated texture / ANIs not working with gr.DrawImage ?
Post a debug log?

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Animated texture / ANIs not working with gr.DrawImage ?
Animations will not play themselves when loaded through the lua API. You basically have to switch frames yourself; you can access all frames in an animation by using the [] operator on a texture handle. In order to find out how many frames an animation has, you can use the "#" operator, and in order to find out how fast you have to switch through frames, you can use texture::getFPS().

You do have used the -output_scripting parameter from FSO to generate scripting.html, have you? That's basically your one-stop reference to all commands in the lua API.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Post a debug log?

Certainly. Here you are: http://pastebin.com/raw.php?i=4maPsWuU

Looks to me like it's definitely recognizing the ANI, of course:

Code: [Select]
Got event GS_EVENT_ENTER_GAME (2) in state GS_STATE_BRIEFING (10)
Entering game at time = 129.508
ANI cb_sm1-01_d with size 440x200 (21.9% wasted)
ANI cb_sm1-01_d.ani with size 440x200 (21.9% wasted)
Frame  1 too long!!: frametime = 0.837 (0.837)
Got event GS_EVENT_END_GAME (4) in state GS_STATE_GAME_PLAY (2)
Unloading in mission messages


Also, I found this obscure post with some interesting information from WMCoolmon: http://www.hard-light.net/forums/index.php?topic=51493.msg1042099#msg1042099

Quote
Yes, animated interface art is possible, and AFAIK alpha channel support is enabled. You will have to show the correct frames of the animation manually, by using gr.loadTexture() and indexing the texture handle (with []) using the FPS, number of frames left, and ba.getFrametime() (which tells you how many seconds have passed). It's not that hard to do.

So it sounds like what I might want to do instead is something like gr.drawImage(tex[1]). gr.drawImage(tex[2]), etc - basically have it increment through each frame of animation?

If this is what I need, WMCoolmon's post fundamentally makes sense to me, but I'm unclear how I'd set up my script to just automatically increment / loop through all of the available frames of animation. I'm going to play around and look at some other examples of this. I actually just had some success - if I set gr.drawImage(tex[30]) for example, the single-frame image I saw was much further into the animation. I just need a way to run through / loop it automatically then.

Edit: Sorry The E, didn't see your post. That's perfect then, it sounds like I'm on the right track.

And yup, I did generate my own scripting.html file and have been parsing through it as well as the basic scripting tutorials on the Wiki - it's how I got this far :) From the data in there though (and given how new I am to scripting / coding in general), it wasn't clear to me that I could actually call individual frames of an animation from a texture handle and how to do it. I think I'm moving in the right direction now though!

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Animated texture / ANIs not working with gr.DrawImage ?
If it's a looping animation, then it should be easy: in your drawing hook, just use mn.getMissionTime(), the number of frames and modulo to determine which frame should be drawn right now.

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Holy hell - she works!


Code: [Select]
#Global Hooks

$HUD:

[

tex = gr.loadTexture('cb_sm1-01_d',true)
totalframes = tex:getFramesLeft()
animfps = tex:getFPS()
missiontime = mn.getMissionTime()
i = (missiontime * animfps) % totalframes
gr.drawImage(tex[i])

]

#End

Now to go forth and turn this into something glorious. Thanks for your help - I promise to use this newfound power mostly for good, instead of evil. Mostly.

 

Offline Cyborg17

  • 29
  • Life? Don't talk to me about life....
Re: Animated texture / ANIs not working with gr.DrawImage ?
Would this work with .EFF?

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Animated texture / ANIs not working with gr.DrawImage ?
Yes. At the level at which lua interacts with the engine, there is no difference between effs and anis.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline m!m

  • 211
Re: Animated texture / ANIs not working with gr.DrawImage ?
You should also cache the loaded texture as every time you call gr.loadTexture('cb_sm1-01_d',true) the whole animation is reloaded (it isn't completely reloaded, the engine is smart enough to know that it already loaded that animation and gives you that handle instead).
A simple fix would be something like this:
Code: [Select]
#Global Hooks

$HUD:
[
if tex == nil then
    tex = gr.loadTexture('cb_sm1-01_d',true)
end

totalframes = tex:getFramesLeft()
animfps = tex:getFPS()
missiontime = mn.getMissionTime()
i = (missiontime * animfps) % totalframes
gr.drawImage(tex[i])
]

#End

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Animated texture / ANIs not working with gr.DrawImage ?
totalframes and animfps can probably also be set just once.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Animated texture / ANIs not working with gr.DrawImage ?
And if you're doing that route, you might as well load the anim in an $On Game Init hook, so you don't get a delay from loading when the HUD is drawn for the first time.

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Hi all - I've made some decent progress but I'm having a weird blocker. Here's my current process:

* I've set up a script that reads a pre-determined file - cbanims.txt. Each line in this file has a string (i.e. "cb_sm1-01_d") which is indexed into a variable (if I'm saying that correctly).
* My script has a function ("readfile.showcbanim()") which uses this index to figure out which animation to play.
* From FRED, my intention is then to call my scripted function with the desired index number as an argument to dynamically play different animations based on in-mission triggers - i.e. invoke script-eval with readfile.showcbanim(2) will read the second line in my text file, and then play the anim file it references. The whole purpose of this is to get around the script-eval character limit in FRED of course.

Seems simple enough, right? I have this all laid out and functional. If I write "readfile.showcbanim(some number)" at the very end of my script with an "On HUD Draw" hook, this works perfectly - I can change the number in the script and the associated string with an anim filename that it finds will load and play.

However, if I call the script through FRED via script-eval, this doesn't work at all - or more specifically, the gr.drawImage component doesn't work. I stuck a ba.warning into my function so I'd get a pop-up alert upon execution, and even though this alert DOES trigger (and does show the expected variable data), the animation itself never actually plays. The image / texture area itself actually never even appears - it's like gr.drawImage just gets arbitrarily passed over if FRED is involved.

I've experimented with gr.drawString and I'm getting a similar effect - I just can't seem to invoke either of these if I'm using a function called from FRED for some reason. If I call the function from the end of the script itself however, they work fine.

Here's my horrible mess of code - does anybody have any idea what I'm doing wrong?

Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On HUD Draw:

[

readfile = {} --Sets up our table and gets it ready to store strings.
readfile.strings = {}
readfile.filename = "cbanims.txt" --We're going to be pulling our strings from "cbanims.txt"

if cf.fileExists(readfile.filename, "data/scripts",true) then --Confirms the existence of, then opens cbanims.txt in the data\scripts sub-folder.
local file = cf.openFile(readfile.filename,"r","data/scripts")
local i = 1
while true do
local entry = file:read("*l")
if entry == nil then break end
readfile.strings[i] = entry --Store indexed lines from cbanims.txt in readfile.strings
i=i+1
--ba.warning("Doing the things!")
end
file:close()
end

readfile.showcbanim = function(line) --Function called from FRED for showing our anim - uses the line number in cbanim.txt as an argument
local t = readfile.strings[line]
if t then
local f = loadstring(t)
if t then
ba.warning("Attempting to render " ..t.. " ")   --Blast a debug notice confirming what file we're loading (confirm data is being read correctly)
cbanim = gr.loadTexture(""..t.."",true) --Pull what anim resource to use from cbanims.txt and store it in cbanim

totalframes = cbanim:getFramesLeft() --Magic 3 lines to make the animation animate
animfps = cbanim:getFPS()
missiontime = mn.getMissionTime()

screenx = gr.getScreenWidth()
screeny = gr.getScreenHeight()
i = (missiontime * animfps) % totalframes
x = (screenx - cbanim:getWidth()) / 2
y = (screeny - cbanim:getHeight()) / 2 + 250
gr.drawImage(cbanim[i],x, y) --Play our animation
else
ba.warning("'"..t.."' loaded from line "..line.." of "..t.." and called from readfile.showcbanim() is not valid.") --Give a debug warning if string loaded isn't valid
end
else
ba.warning("readfile.showcbanim() has just attempted to load line "..line.." from "..readfile.filename.." and failed. Most likely this line or the file does not exist.") --Give a debug warning if the table entry is empty
end
end



]

#End

(You might see some similarities to FelixJim's RunFromFile script here, so credit where credit is due as I've been using it to help learn how to get things working. I also appreciate the earlier suggestions on optimizing things and will be rolling those in once I'm past the "just get it working" phase)

Here's the debug warning I get from the ba.warning call in readfile.showcbanim() confirming that execution 'should' be working when I try to invoke this from FRED (the "Attempting to render (string)" bit - this accurately changes if I pass different line numbers from FRED, so it's definitely getting far enough to read my strings and start processing them)

Code: [Select]
---------------------------
Warning!
---------------------------
Attempting to render cb_sm1-01_d
ntdll.dll! ZwWaitForSingleObject + 21 bytes
kernel32.dll! WaitForSingleObjectEx + 67 bytes
kernel32.dll! WaitForSingleObject + 18 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! SCP_DumpStack + 354 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! Warning + 416 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! l_Base_warning_f + 72 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! luaD_precall + 785 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! luaV_execute + 5766 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! luaD_call + 161 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! f_call + 58 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! luaD_rawrunprotected + 86 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! luaD_pcall + 100 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! lua_pcall + 134 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! script_state::EvalString + 460 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! sexp_script_eval + 643 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! eval_sexp + 11499 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! eval_when_do_one_exp + 417 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! eval_when + 792 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! eval_sexp + 3659 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! mission_process_event + 547 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! mission_eval_goals + 517 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! game_simulation_frame + 1153 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! game_frame + 497 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! game_do_frame + 239 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! game_do_state + 379 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! gameseq_process_events + 237 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! game_main + 782 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! WinMain + 330 bytes
fs2_open_3_7_2_RC3-DEBUG.exe! __tmainCRTStartup + 358 bytes
[...]
[ This info is in the clipboard so you can paste it somewhere now ]


Use Yes to break into Debugger, No to continue.
and Cancel to Quit

---------------------------
Yes   No   Cancel   
---------------------------


So.. I'm completely stumped.  Is $On HUD Draw an inappropriate hook to use if you intend to call something from FRED, and if so, what should I be using instead? Why does this work fine when I call the function from inside the script, but not when I call it using script-eval in FRED?
« Last Edit: July 18, 2014, 08:33:51 pm by Parias »

 

Offline DahBlount

  • 29
  • Alpine ☆ Cancer Tribulation
    • Minecraft
    • Skype
    • Steam
Re: Animated texture / ANIs not working with gr.DrawImage ?
I'm fairly sure you should make the file "cbanims.cfg" in data\config and use references like $FileName:, then create a parse scheme to grab the file from the .cfg file. As it stands FSO can't read .txt files in data\scripts, so it's pretty much only possible to use a config file.
<Axem> yet still more insightful than #hard-light

<Axem> jad2.23 will just be cat videos

<DahBlount> So
<DahBlount> JAD2.2 is like that
<Axem> maybe
<Axem> it can be whatever you like!
<DahBlount> A Chocolate Sundae?
<Axem> sure

My models: GTF Gilgamesh - GTD Nuadha [Redesigning] - Ningirama [WIP] - GTG Zephyrus

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Are you sure? Sorry, as I know I'm the noob here, but that seems contradictory to the information I'm seeing...

* The .txt file I have in data\scripts DOES get read - in fact, my LUA script works perfectly fine so long as I call my function at the end of it (instead of from FRED). Because I'm hooking into On HUD Draw, the .txt file is read and the corresponding anim effect is loaded and played constantly as soon as I start the mission. FSO seems to read it just fine. My goal is just to be able to trigger this dynamically from the mission instead of it being a constant, and it's only when I call the function from FRED (where a path and filename doesn't even enter the equation - it's just "run this function with this numerical argument" and the exact same LUA script that worked previously takes over from there) that a small component of it (gr.drawImage) doesn't seem to work. The rest of the script definitely does seem to work when called from FRED though as you can see the right string from my .txt file gets pulled when I put a ba.warning debug line in front of the execution.

* FelixJim's RFF script that I'm borrowing from also relies on the same logic - his sample uses "runfromfile.txt" in data/scripts to read function calls in a similar way to what I'm doing (which is why I actually used this as a baseline example). Of course his post is also a year old, so I'm not sure if perhaps something changed engine-wise between then and now.

(Sorry if I'm being vague in explaining any of this though - I've been beating my head against it for the last two days and I'm about burned out)

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Animated texture / ANIs not working with gr.DrawImage ?
The problem is that "On HUD Draw" will call that function once every frame, while script-eval is (presumably) only doing it once. What you should do instead is have your showcbanim() function load the animation and set it up so that gr.drawImage() then gets called every frame (until the animation is done, presumably).
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
So what you're saying is that my drawImage call probably is working when called via script-eval -- but it only happens for a single frame, and so basically goes by so fast I never see it?

Oh god, that.. actually makes perfect sense (and I could probably further verify if I set something up to report if drawImage was actually successful or not). In any case, I'm admittedly fuzzy on how to implement what you're describing but I think I conceptually get it. I'm going to play with this a bit and will report back if I need further guidance.

Thanks!

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Alright, sorry - I've been toying with this for the last little while and still haven't had any success.  I added a ba.warning bit at the end of my execution to report on the value of "i" (i.e. the current anim frame it should be on) out of the totalframes value (max number of frames in the anim):

Code: [Select]
gr.drawImage(cbanim[i],x, y) --Play our animation
ba.warning("i is " ..i.. ", totalframes is " ..totalframes.. "")

If I execute readfile.showcbanim from within my script, I'll get back "i is 3.75, totalframes is 180", "i is 7.5, totalframes is 180", etc every time I hit "no" to the debug warning window and step forward - I can see the animation rendering to the game screen and properly advancing in tandem.

If I use script-eval to call it from FRED, I'll actually see the same thing (albeit with more decimal places) - i.e. i is 15.149917602539, totalframes is 180. The message only appears once which sounds in sync with the "your FRED mission is only parsing script-eval once" theory. The interesting bit is if I change my script-eval event to use an "every-time" conditional instead of "when" (in both cases I'm using has-time-elapsed 1 as the trigger) I can see the "i" value - i.e. supposed current frame - increasing, so I'll get "i is 18.899917602539", "i is 22.649917602539", etc. The value which drives the current animation frame is clearly incrementing - the animation itself just doesn't appear.

I also just tried statically declaring a particular frame in my drawImage call (i.e. gr.drawImage(cbanim[15],x, y) ) which I was half-way hoping would leave at least a static image on the screen, but it didn't. Even if I stick this (and the associated loadTexture call) at the very highest point in my function, I still get nothing rendered if I call it from FRED.

I'm probably steering a bit off-course here and missing the obvious - you're probably right in that I still need a way to force the image to properly appear every frame, but from the results I'm getting (especially switching my script-eval call to an every-time conditional that's pretty much always true) leave me baffled on exactly what the difference is between calling this directly from my script, and from FRED, especially when I can't even get a static image to appear. What am I doing wrong - could you provide some tips on how I would get gr.drawImage to call every frame?

Edit: I've tried randomly switching over to different hooks too just for kicks - $On Hud Draw, $On Game Init, $On Frame, etc, but none of these seem to work any differently as far as the symptoms I'm seeing are concerned.
« Last Edit: July 19, 2014, 01:42:43 am by Parias »

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Animated texture / ANIs not working with gr.DrawImage ?
I would probably do something along these lines (with the caveat that I don't actually know Lua):
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init:

[

readfile = {} --Sets up our table and gets it ready to store strings.
readfile.strings = {}
readfile.filename = "cbanims.txt" --We're going to be pulling our strings from "cbanims.txt"

if cf.fileExists(readfile.filename, "data/scripts",true) then --Confirms the existence of, then opens cbanims.txt in the data\scripts sub-folder.
local file = cf.openFile(readfile.filename,"r","data/scripts")
local i = 1
while true do
local entry = file:read("*l")
if entry == nil then break end
readfile.strings[i] = entry --Store indexed lines from cbanims.txt in readfile.strings
i=i+1
--ba.warning("Doing the things!")
end
file:close()
end

readfile.showcbanim = function(line) --Function called from FRED for showing our anim - uses the line number in cbanim.txt as an argument
local t = readfile.strings[line]
if t then
--ba.warning("Attempting to render " ..t.. " ")   --Blast a debug notice confirming what file we're loading (confirm data is being read correctly)
cbanim = gr.loadTexture(""..t.."",true) --Pull what anim resource to use from cbanims.txt and store it in cbanim

totalframes = cbanim:getFramesLeft() --Magic 3 lines to make the animation animate
animfps = cbanim:getFPS()
starttime = mn.getMissionTime()

screenx = gr.getScreenWidth()
screeny = gr.getScreenHeight()
else
ba.warning("readfile.showcbanim() has just attempted to load line "..line.." from "..readfile.filename.." and failed. Most likely this line or the file does not exist.") --Give a debug warning if the table entry is empty
end
end

]

$On HUD Draw:

[

if cbanim != nil then
local animtime = mn.getMissionTime() - starttime
local i = animtime * animfps
if i >= totalframes then
cbanim = nil
else
local x = (screenx - cbanim:getWidth()) / 2
local y = (screeny - cbanim:getHeight()) / 2 + 250
gr.drawImage(cbanim[i],x, y) --Play our animation
end
end


]

#End
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Parias

  • 27
Re: Animated texture / ANIs not working with gr.DrawImage ?
Wow, thanks! I was contemplating trying something like that...

Dropped it in and it loaded OK (only LUA-specific variance I think was I had to change "if cbanim != nil" to use ~=)..... at least in the sense that the game processed it without hemmoraging errors and all of the functions triggered when they should have (I stuck extra ba.warnings everywhere just to make sure - it definitely runs through readfile.showcbanim() which then successfully triggers the "if cbanim" bit in the seperate HUD Draw hook).

But sadly, nothing still gets rendered from gr.drawImage when I call readfile.showcbanim() from FRED via script-eval. And if I call showcbanim "locally" from within the script instead, the anim will appear and play the first few frames, but then disappear and not come back. That might just have to do with the slightly different way the anim is being looped though and I'm not worried about that right now  - the point is, an image still gets rendered by gr.drawImage if I call the associated function in the script locally, but not from script-eval in FRED.

I was admittedly working from the fsport mod for some of this, so I just shifted the script over to my base Freespace 2 folder and tried running the game with no mods at all just to see if maybe something silly was happening there. No change either.

 

Offline m!m

  • 211
Re: Animated texture / ANIs not working with gr.DrawImage ?
Have you checked the coordinates where the script draws the animation?
This part seems a bit suspicious:
Code: [Select]
  screenx = gr.getScreenWidth()
  screeny = gr.getScreenHeight()