Posted: 21st Jun 2007 6:02
hi, i've got this texture in .bmp format that i want to animate


this image is not the orginal, it has been saved in jpeg format

an i've tryed doing this:


+ Code Snippet
x=0 : y=0
   for f=1 to 12
   get image fire_num,x,y,x+85,y+128,1
   `x=x+0
   if x=510 then x=0:y=y+128
   if x=510 and y=256 then x=0 and y=0
   next f



but its not showing up, or it just draws the whole image,

i've put it in a label, and tryed it in a function 2, but with no luck

i'm not 2 sure on animating textures, anyone got any code snippits or examples i can learn from?
Posted: 21st Jun 2007 7:13
anyone? I have searched but not found what i wanted.
Posted: 21st Jun 2007 9:55
Firstly, the obvious. You will need to paste the image to the screen first or to an off-screen bitmap. You may have done that already but from the code you are showing we can only guess.

Now on to what is wrong with your code:
The most obvious thing is that you are not increasing the value of fire_num, so all the images are being stored in the same place - overwriting each other.

Try this:
+ Code Snippet
  for y = 0 to 128 step 128
	for x = 0 to 425 step 85
		get image fire_num, x, y, x + 85, y + 128, 1
		inc fire_num
	next x
next y
Posted: 21st Jun 2007 17:52
sorry still not working, when i paste the image outside the screen it completely crashes the computer & i had 2 reboot

this is the code I'm using (anything outside the functions/sub routines is temporary code




+ Code Snippet
sync on : sync rate 60
load object "progsenv_rag.md2",1
set image colorkey 0,0,0
set object transparency 1,4
loop object 1,1,5
set object speed 1,1
set object smoothing 1,60
autocam off

`make object box 2,100,100,100
`position object 2,0,-25,80

load image "gfxenv_dirt.bmp",20

make object box 11,16,32,16
texture object 11,20

position object 1,0,0,0
position camera 0,40,-20
env_fire(2,2,16,256,0,16,80)

color backdrop 0

set ambient light 1

set camera fov 80
do
if inkey$()="w" then move object 11,1
if inkey$()="s" then move object 11,-1
CONTROL CAMERA USING ARROWKEYS 0,1,1
gosub fire_anim;
sync
loop

function env_fire(fire_num,fire_img,fire_size,fire_range,fire_x,fire_y,fire_z)
load image "gfxenv_+fire.bmp",fire_img
x=0
y=0




make object plain fire_num,fire_size,fire_size*2
yrotate object fire_num,180
position object fire_num,fire_x,fire_y,fire_z
texture object fire_num,fire_img
set object ambient fire_num,0
ghost object on fire_num,0
scale object texture fire_num,0.18,0.5

make light fire_num
color light fire_num,232,167,55
position light fire_num,fire_x,fire_y,fire_z
set light range fire_num,fire_range

endfunction

fire_anim:
for y = 0 to 128 step 128
	for x = 0 to 510 step 85
		get image fire_img,x,y,x+85,y+128,1
		inc fire_img
                wait 0.25
	next x
next y
return


also have tryed scroll object texture but thats not working for some reason, seems to be stuck
Posted: 21st Jun 2007 18:14
something tells me this isn't going 2 be as easy as i thought.
anyone??

is it possible in DBPro??

i've tryed alot of things & none have worked
Posted: 21st Jun 2007 18:59
You are going about it completely wrong.

You need to cut the image before you use it and store each image in a seperate variable, then texture the plain with the imae when you want to animate it.

There isn't much point going in to it in any length here because it has been covered in a newsletter tutorial. Have a look at Issue 46 of the monthly newsletter and read the tutorial on explosion effects. You should learn everything you need to know from that.

If you still have problems afterwards then ask again but you should be ok
Posted: 21st Jun 2007 19:27
nope, its STILL not working, his function works fine in his program, but keeps saying "illegal image number at line 149" even tho there is no line 149

load image "gfx\env_+fire.bmp",fire_img
split_image(85,128,fire_img,50105)
if image exist(fire_img)=1 : delete image fire_img : endif

this is just the first frame

all i want is the animated flame, i have saved his example on my pc for future reference,

he has a split_image function that was designed to only work with his program under his conditions


please PLEASE someone post a working example, im not getting anywhere, its totally dead-ended so far

i've got a whole load of media i don't want to have to just discard
Posted: 21st Jun 2007 20:45
anyone?
Posted: 21st Jun 2007 21:18
Try this:
+ Code Snippet
sync on : sync rate 60

load image "envfirefu7.jpg",1
paste image 1,0,0

fire_num = 2
firstframe = fire_num
for y = 0 to 128 step 128
   for x = 0 to 425 step 85
      get image fire_num, x, y, x + 85, y + 128, 1
      inc fire_num
      lastframe = fire_num
   next x
next y

fire_num = firstframe

make object plain 1,85,128
texture object 1,fire_num
set object ambient 1,0

do

   if timer()-lasttick#>80.0
      lasttick# = timer()
      inc fire_num
   endif

   if fire_num > lastframe-1
      fire_num = firstframe
   endif

   texture object 1,fire_num

   sync
loop


When you cut up and image to be stored, its wise to do it before you load anything 3d because the screen gets wiped.
Posted: 21st Jun 2007 21:42
nice try mate, thanx 4 giving it a go but its still not working

1st problem is even if it did work the "texture object" command in the loop is seriously killing the frame rate.

2nd problem is its just not working, its showing the entire image on the plain, even tried manipulating the code. and scale object texture, but nothing

any more sudgestions

i did have a look at "scroll object texture", figured out that it needs to be in the 0.01's rather than the 1's

but i cant make it step, is there an example using that?
Posted: 21st Jun 2007 22:23
but its still not working

Yes, it is!

There is nothing wrong with the code that Sasuke provided. There is also nothing wrong with the tutorial that I linked for you.

What exactly do you want? Do you want someone to come around to your house, hold your hand and write your code for you?
Posted: 21st Jun 2007 22:33
Also to take the hit off the frame rate you could change:
+ Code Snippet
if timer()-lasttick#>80.0
   lasttick# = timer()
   texture object 1,fire_num
   inc fire_num
endif

if fire_num > lastframe-1
   fire_num = firstframe
endif


So it would only update the texture every time the timer()-lasttick# is greater than 80.0. But still, this works and thats a fact, so theres something wrong on your end.
Posted: 21st Jun 2007 22:47
ok well ill have a look later, been scratching my head all day


What exactly do you want? Do you want someone to come around to your house, hold your hand and write your code for you?


yes please,lol
Posted: 22nd Jun 2007 22:23
You do know you have to adjust the code to fit your own project numbers.. right? For example: If you have your image loaded as 100 and they have theirs loaded as 50, in order for their code to work, you have to change the image number to YOUR image number (50 => 100). I think that could be why it's not working for you.
Posted: 26th Jun 2007 0:01
edit:

fixed framerate prob,

but i can't get it into a function/label, its being difficult & just shows a gray texture in place of the fire
Posted: 26th Jun 2007 0:10
Is it possible to get a sample of your code, then we can see whats killing the frame rate.
Posted: 26th Jun 2007 0:14
yes, this is the code, i am TRYing to put it all into functions, wich i can call later in the level editor

+ Code Snippet
// aftermath engine env_objects and env_effects functions

**********TEMP**********TEMP**********TEMP**********TEMP**********TEMP
` **********TEMP**********TEMP**********TEMP**********TEMP**********TEMP


load image "gfx\env_+fire.bmp",1
paste image 1,0,0

fire_num = 2
firstframe = fire_num
for y = 0 to 128 step 128
   for x = 0 to 425 step 85
      get image fire_num, x, y, x + 85, y + 128, 1
      inc fire_num
      lastframe = fire_num
   next x
next y

fire_num = firstframe


sync on : sync rate 60 :autocam off
load image "gfx\env_dirt.bmp",20
make object box 11,16,32,16
texture object 11,20


position camera 0,40,-20
env_rag(3,1,100,0,0,180,0)
env_fire(2,16,256,0,32,80)
env_rag(1,1,100,0,0,10,0)
`env_light(3,512,0,0,255,0,0,-50)
env_3d_sound(1,"sound\env_wind1.wav",1,100,0,0,0)



make object plain 20,1024,1024
xrotate object 20,90
position object 20,0,-4,0
texture object 20,20
scale object texture 20,20,20

color backdrop 0

set ambient light 10

set camera fov 80

do
camposx#= camera position x()
camposy#= camera position y()
camposz#= camera position z()

camroty#= camera angle y()

if inkey$()="w" then move object 11,1
if inkey$()="s" then move object 11,-1
CONTROL CAMERA USING ARROWKEYS 0,1,1
position listener camposx#,camposy#,camposz#
rotate listener 0,camroty#,0
point object 2,camera position x(), 0, camera position z()

xrotate object 2,0
zrotate object 2,0

gosub init_fire

sync
loop

` **********TEMP**********TEMP**********TEMP**********TEMP**********TEMP
` **********TEMP**********TEMP**********TEMP**********TEMP**********TEMP





function env_fire(fire_onum,fire_size,fire_range,fire_x,fire_y,fire_z)
make object plain fire_onum,fire_size,fire_size*2
    yrotate object fire_onum,180
    position object fire_onum,fire_x,fire_y,fire_z
    set object ambient fire_onum,0
    ghost object on fire_onum,0
 `   scale object texture fire_onum,0.18,0.5
    make light fire_onum
    color light fire_onum,232,167,55
    position light fire_onum,fire_x,fire_y,fire_z
    set light range fire_onum,fire_range    
endfunction

function env_fire_init()
load image "gfx\env_+fire.bmp",1
paste image 1,0,0

fire_num = 2
firstframe = fire_num
for y = 0 to 128 step 128
   for x = 0 to 425 step 85
      get image fire_num, x, y, x + 85, y + 128, 1
      inc fire_num
      lastframe = fire_num
   next x
next y

fire_num = firstframe

endfunction

function env_rag(rag_num,rag_anim,rag_size,rag_x,rag_y,rag_z,rag_yrot)
    load object "progs\env_rag.md2",rag_num
    set image colorkey 0,0,0
    set object transparency rag_num,4
    if rag_anim=0
        set object frame rag_num,0
    else
        loop object rag_num,1,5
    endif
    set object speed rag_num,1
    set object smoothing rag_num,60
    position object rag_num,rag_x,rag_y,rag_z
    scale object rag_num,rag_size,rag_size,rag_size
    yrotate object rag_num,rag_yrot
endfunction

function env_light(light_num,light_range,light_r,light_g,light_b,light_x,light_y,light_z)
    make light light_num
    set light range light_num,light_range
    color light light_num,light_r,light_g,light_b
    position light light_num,light_x,light_y,light_z
endfunction

function env_3d_sound(sound_num,sound_path$,sound_playing,sound_vol,sound_x,sound_y,sound_z)
    load 3dsound sound_path$,sound_num
    set sound volume sound_num,sound_vol
    if sound_playing=1
        loop sound sound_num
    else
        stop sound sound_num
    endif
endfunction

function env_global_sound(gsound_num,gsound_path$,gsound_playing,gsound_vol)
    load sound gsound_path$,gsound_num
    set sound volume gsound_num,gsound_vol
    if gsound_playing=1
        loop sound gsound_num
    else
        stop sound gsound_num
    endif
endfunction


init_fire:
if timer()-lasttick#>80.0
   lasttick# = timer()
   texture object 2,fire_num
   inc fire_num
endif

if fire_num > lastframe-1
   fire_num = firstframe
endif
return


most of the code is temporary, bar the functions & gosubs
Posted: 26th Jun 2007 0:29
I have some code which I used from a TGC explosion tutorial.

The code is modified by me, but studying it should help. What it does is SPLIT your images into sub-images, then an object plain cycles through the images. It's designed for explosions, not fires, but if you can understand this you can understand fires.

+ Code Snippet
` ***********************************************************
`  EXPLOSIONS
` ***********************************************************

TYPE Explosion_TYPE
   image             AS DWORD
   alive             AS BOOLEAN
   frame             AS BYTE
   max_frames        AS BYTE
   delay             AS BYTE
   delay_count       AS BYTE
   repeat            AS BOOLEAN
ENDTYPE

` This permits you to have 50 animated explosions on-screen at once.
` If you want fewer, just lower ex_max

GLOBAL ex_max AS DWORD = 50
GLOBAL ex_first AS DWORD = 30000
GLOBAL ex_counter AS DWORD = 0
GLOBAL DIM explosions(ex_max) AS explosion_TYPE

` Only do this once
prepare_explosions()






` in-loop - compulsory, update does the "animating"
update_explosions()




` This creates the explosion, the parameters are:
`   x#, xpos
`   y#, ypos
`   z#, zpos
`   1 - explosion type
`   100 - scale (100%)
`   0 - delay (increase from zero to slow the texture)
`   1 to loop the explosion, else 0 to make it a one-off
spawn_explosion(x#,y#,z#,1,100,0,1)











` ***********************************************************
`  PREPARATION
` ***********************************************************

FUNCTION prepare_explosions()

  imgNo = 1
   while image exist(imgNo) = 1
      inc imgNo
   endwhile


   load image "envfirefu7.jpg",imgNo,1
   split_image(imgNo,6,2,30101)
   delete image imgNo

   FOR j = 1 TO ex_max

      MAKE OBJECT PLAIN ex_first+j,100,100
      DISABLE OBJECT ZWRITE ex_first+j
      DISABLE OBJECT zdepth ex_first+j
      GHOST OBJECT ON ex_first+j,3
      SET OBJECT LIGHT ex_first+j,0
      HIDE OBJECT ex_first+j
   NEXT j
ENDFUNCTION

` ***********************************************************
`  SPAWN
` ***********************************************************

FUNCTION spawn_explosion(x#,y#,z#,explosion_type,size,delay,repeat)

   ` Sanity Checks
   IF size < 1 : size = 1 : ENDIF
   IF delay < 1 : delay = 0 : ENDIF

   ` Explosion Counter
   IF (ex_counter = ex_max)
      ex_counter = 1
   ELSE
      INC ex_counter
   ENDIF

   ` Explosion Data
   explosions(ex_counter).alive        = 1
   explosions(ex_counter).frame        = 1
   explosions(ex_counter).image = ex_first + (explosion_type * 100)
   explosions(ex_counter).delay        = delay
   explosions(ex_counter).delay_count  = delay

   IF explosion_type = 1
      explosions(ex_counter).max_frames   = 12
   ENDIF

   IF repeat = 0
      explosions(ex_counter).repeat = 0
   ELSE
      explosions(ex_counter).repeat = 1
   ENDIF

   ` Explosion Object
   object = ex_first + ex_counter
   POSITION OBJECT                     object,x#,y#,z#
   SET OBJECT TO CAMERA ORIENTATION    object
   TEXTURE OBJECT                      object,explosions(ex_counter).image + explosions(ex_counter).frame
   SCALE OBJECT                        object,size,size,size
   SHOW OBJECT                         object

ENDFUNCTION


` ***********************************************************
`  UPDATE
` ***********************************************************
FUNCTION update_explosions()

   ` For each explosion
   FOR j = 1 TO ex_max

      ` For each alive explosion
      IF explosions(j).alive = 1
         ` Scroll through textures
         IF explosions(j).delay =  explosions(j).delay_count
            INC explosions(j).frame
            TEXTURE OBJECT ex_first+j, explosions(j).image + explosions(j).frame
            explosions(j).delay_count = 0
         ELSE
            INC explosions(j).delay_count
            IF explosions(j).delay_count > explosions(j).delay THEN explosions(j).delay_count = explosions(j).delay
         ENDIF

         IF explosions(j).frame = explosions(j).max_frames
            IF explosions(j).repeat = 0
               explosions(j).alive = 0
               HIDE OBJECT ex_first+j
            ELSE
               explosions(j).frame = 1
            ENDIF
         ENDIF
      ENDIF
   NEXT j


ENDFUNCTION


` ***********************************************************
`  REMOVE
` ***********************************************************

FUNCTION engine_kill_all_explosions()
   ` Go through explosions, killing them
   FOR j = 1 to ex_max
      explosions(j).alive = 0
      explosions(j).frame = 0
      HIDE OBJECT ex_first+j
   NEXT j
ENDFUNCTION


` ###########################################################
` ###########################################################
`     IMAGE SPLITTER
` ###########################################################
` ###########################################################

` BaseImage = Image to Split
` imgX      = Number of Columns
` imgY      = Rumber of Rows
` firstImg  = Start of Images Made
` Authorship: BATVINK (I think)

FUNCTION split_image(baseImage,imgX,imgY,firstImg)

  ` Find a free memblock
  memNo = 2
   while memblock exist(memNo) = 1
      inc memNo
   endwhile

   ` Make the image memblock
   make memblock from image memNo,baseImage
   iW = (memblock dword(memNo,0))
   iH = (memblock dword(memNo,4))
   iD = (memblock dword(memNo,8))

   ` Settings for access to memblock
   imgWidth = iW / imgX
   imgHeight = iH / imgY
   mbSize = ((imgWidth * imgHeight) + 3) * 4
   memNo2 = memNo + 1

   ` Destination memblock, one "cell" size
   while memblock exist(memNo2) = 1
      inc memNo2
   endwhile
   make memblock memNo2, mbSize
   write memblock dWord memNo2,0,imgWidth
   write memblock dWord memNo2,4,imgHeight
   write memblock dWord memNo2,8,iD

   ` Cycle through rows and columns
   for imagesY = 1 to imgY
      for imagesX = 1 to imgX
         img = ((imagesY -1) * imgX) + imagesX
         NewByte = 12
         for rows = 1 to imgHeight
            for cols = 1 to imgWidth
               offSet1 = (imagesY - 1) * imgWidth * imgHeight * imgX
               offset2 = (iW * (rows - 1))
               offset3 = imgWidth * (imagesX - 1)
               offset4 = cols - 1
               imgDword = (offset1 + offset2 + offset3 + offset4 + 3) * 4

               ` Make the cell image in the memblock
               write memblock dWord memNo2,NewByte, memblock dWord(memNo,imgDWord)
               inc NewByte,4
            next cols
         next rows
         NewByte = 12

         ` Convert memblock to next counter in standard image system
         make image from memblock (img + firstImg - 1),memNo2
      next imagesX
   next imagesY
   delete memblock memNo
   delete memblock memNo2
   delete image baseImage
ENDFUNCTION