Transitions on tiles

Blitz3D Forums/Blitz3D Beginners Area/Transitions on tiles

Uraliss(Posted 2003) [#1]
Hi folks,
The map editor for my game is coming along nicely and im starting to knock up a simple game level so i can progress onto the actual game. The problem im having is one of lazyness really - i need to get transitions on some of my tiles so that say - a pebbled area goes into a grassy area. Rather than drawing hundreds of tiles that show this transition i was wondering if it was possible to calculate the images for these tiles in realtime. In my level array data I would use a flag that says that a particular tile should be a transitionl tile of the one above and the below it say... My game is a strategy game and doesnt need fast graphics except for spell effects etc.
Can anybody suggest a way to do this or should I bite the bullet and spend a week or so on photoshop doing them manually?

Cheers


Sunteam Software(Posted 2003) [#2]
A simple fade blend would be the cheapest way. Go through the tile set and find the transition tiles, then for each one read through the pixels of the two different tiles to be blended, take an average of the rgb components and write it to a new tile.


Uraliss(Posted 2003) [#3]
Im having problems with the blending - cant seem to get my head around it.
Beaker helped me with the gradient but im still a little stuck.
Here is my code (with some rgb functions from Rob Farley)
It should blend the first tile into black (my idea is to blend 2 tiles together but i need to get this right first) - It isn't working - it seems to start ok then turns into a rainbow pattern!?!?!
Any help appreciated Thanks



;### Initialise

graphics 800, 600, 16
transition=loadanimimage("D:\Projects\Game Graphics\tileset2.bmp",64,64,0,50)
drawimage transition,0,0,1
drawimage transition,128,0,2
trans1=createimage(64,64)
trans2=createimage(64,64)
grabimage trans1,0,0
grabimage trans2,128,0
scratch=createimage(64,64)


;### Main Loop

for y=0 to 63
for x= 0 to 63



red1=read_r(x,y,trans1)
green1=read_g(x,y,trans1)
blue1=read_b(x,y,trans1)



; red2=read_r(x,y,trans2)
; green2=read_g(x,y,trans2)
; blue2=read_b(x,y,trans2)


gradient1#=float(x)/63*255


compred#=float(red1/gradient1#)*255
compgreen#=Float(green1/gradient1#)*255
compblue#=float(blue1/gradient1#)*255


write_rgb x,y,compred#,compgreen#,compblue#,scratch
next
next

drawimage scratch,64,0
while not keyhit(1)
wend


;### Functions
;####################################################################

;ARGB Functions by Rob Farley 2003
;rob@...
;http://www.mentalillusion.co.uk

Function read_r(x,y,image_name)
argb=ReadPixel(x,y,ImageBuffer(image_name))
Return (ARGB Shr 16) And $ff
End Function

Function read_g(x,y,image_name)
argb=ReadPixel(x,y,ImageBuffer(image_name))
Return (ARGB Shr 8) And $ff
End Function

Function read_b(x,y,image_name)
argb=ReadPixel(x,y,ImageBuffer(image_name))
Return ARGB And $ff
End Function

Function write_rgb(x,y,r,g,b,image_name)
argb=(b Or (g Shl 8) Or (r Shl 16) Or ($ff000000))
WritePixel x,y,argb,ImageBuffer(image_name)
End Function


Anthony Flack(Posted 2003) [#4]
Just given it a quick scan, and I see one problem: you should be multiplying them numbers by 256 not 255

oh, given it another quick scan and I see that no, actually 255 is right in this case, I thought you were doing the bit-shifting.... um, okay, give me a bit longer.


_PJ_(Posted 2003) [#5]
--

sorry just noticed:
"He stands at the Citadel of Uraliss, looking Northwest to the Plains of Blood.
It is dawn and Uraliss is slightly tired. The Ice Fear is very mild. Uraliss is utterly bold. "

Have you seen the LOM remakes at icemark.com?
Really impressive PC version :)


Anthony Flack(Posted 2003) [#6]
Hmm, well for starters, better and faster to do this:
Get rid of unnecessary floats, and unnecessary multiplications and stuff.

gradient1#=x/63.0

compred=red1*gradient1#
compgreen=green1*gradient1#
compblue=blue1*gradient1#



Uraliss(Posted 2003) [#7]
Anthony
That seems to have done the trick! dont understand why it wasnt working before.

Thanks.


malice
Yep they are cracking remakes. Brings back memories of late night speccy sessions stomping doomdark into the ground. And... I so had the hots for Shareth.


Anthony Flack(Posted 2003) [#8]
Good-o. Those floats probably didn't help.
While I'm at it, this is how you blend the 2.

compred=(red1*gradient1#) + (red2*(1-gradient1#))
compgreen=(green1*gradient1#) + (green2*(1-gradient1#))
compblue=(blue1*gradient1#) + (blue2*(1-gradient1#))



Oh, and your reading of the pixels is massively inefficient. You're reading each pixel 3 times. And not using readpixelfast. And you're making function calls for each one, instead of doing it in-line. Slow, slow, slow. You should probably fix that.


Uraliss(Posted 2003) [#9]
Thanks Anthony,
I had worked out to blend the 2 but did it in a slightly different way to you.

Now that I understand the concept and you have helped me fix where I was going wrong I can take a look at optimising the code a bit.

Before that though I was going to investigate how to blend multiple tiles together so say:

1 1 2
2 X 3
1 1 3

where x will be the blended tile and tiles 1, 2, 3 are rocks, grass, and soil perhaps.
Then again maybe thats not feasible because the surrounding tiles wont be blended.

Maybe I will just pre-render the main ones and save em off to an animstrip for my level editor....

Any thoughts?