Wheres picFadeOut????
Author |
Message |
Nathan4102
|
Posted: Sat Sep 07, 2013 6:27 pm Post subject: Wheres picFadeOut???? |
|
|
Where the heck is picFadeOut??? I found picFadeIn:
Pic.DrawSpecial(Key, 0, 0, picMerge, picFadeIn, 3000)
Does picFadeOut simply not exist? I guess I could fade the background back over an image to make it "Fade out", but if the background is more than one image, or includes text and other stuff, it won't work. Any suggestions???
Thanks,
Nathan |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Sun Sep 08, 2013 1:39 pm Post subject: Re: Wheres picFadeOut???? |
|
|
It doesn't exist for the same reason that there is no Pic.Erase to go with Pic.Draw. Not only would Turing would have to remember the background at the time of drawing, but there would also be weird things that could happen if you drew over the picture after fading in and before fading out.
However, if you are confident that nothing will be drawn over your picture, you can just save the background yourself and fade it back in over top when using picCopy.
Turing: | type FadedPic :
record
isValid : boolean
x : int
y : int
bgID : int
end record
fcn PicFadeIn (picID, x, y, mode, duration : int) : FadedPic
const x2 := x + Pic.Width(picID ) - 1
const y2 := y + Pic.Height(picID ) - 1
var fadedPic : FadedPic
fadedPic.isValid := true
fadedPic.x := x
fadedPic.y := y
fadedPic.bgID := Pic.New(x, y, x2, y2 )
Pic.DrawSpecial(picID, x, y, mode, picFadeIn, duration )
result fadedPic
end PicFadeIn
% No mode parameter since we have to picCopy
% Also, the FadedPic will be invalid after fading out
proc PicFadeOut (var fadedPic : FadedPic, duration : int)
% Assert that fadedPic is valid
assert fadedPic.isValid
Pic.DrawSpecial(fadedPic.bgID, fadedPic.x, fadedPic.y, picCopy, picFadeIn, duration )
% Free bg and invalidate the record
Pic.Free(fadedPic.bgID )
fadedPic.isValid := false
end PicFadeOut
% Example
Draw.FillOval(150, 135, 50, 35, 12)
var rectangle : int := Pic.New(100, 100, 200, 170)
cls
Draw.FillBox(0, 0, 150, maxy, 7)
View.Update
var fadedRectangle : FadedPic := PicFadeIn(rectangle, 100, 100, picMerge, 1000)
PicFadeOut (fadedRectangle, 1000) |
You're using picMerge, which means you might run into problems with this approach. Replace the example code with the following to see what I mean.
Turing: | Draw.FillOval(150, 135, 50, 35, 12)
var oval : int := Pic.New(100, 100, 200, 170)
cls
Draw.FillBox(0, 0, 150, maxy, 7)
var fadedOIval : FadedPic := PicFadeIn(oval, 100, 100, picMerge, 1000)
Pic.DrawSpecial(oval, 175, 155, picMerge, picFadeIn, 1000)
PicFadeOut (fadedOIval, 1000) |
To get around this we have to do some extra work.
Turing: | % Make BG almost (but not completely) white
% This allows picMerge to distinguish between white (transparent colour of picture) and almost white (bg)
const bgColour := RGB.AddColour (0. 99, 0. 99, 0. 99)
type FadedPic :
record
isValid : boolean
x : int
y : int
bgID : int
modeUsed : int
end record
% Note: I'm going to assume that we are not in offscreenonly mode since picFadeIn and offscreenonly don't really work together
fcn GetBgWherePicIsMerged (picID, x, y : int) : int
const x2 := x + Pic.Width (picID ) - 1
const y2 := y + Pic.Height (picID ) - 1
% Enable offscreenonly so that we don't draw to the window
View.Set ("offscreenonly")
const bg : int := Pic.New (x, y, x2, y2 )
% Xor the picture and save the result
Pic.Draw (picID, x, y, picXor)
const xoredPic : int := Pic.New (x, y, x2, y2 )
% Merge the picture onto the background and xor the xored version on that
% This gives us the background only where the picture was merged
Pic.Draw (bg, x, y, picCopy)
Pic.Draw (picID, x, y, picMerge)
Pic.Draw (xoredPic, x, y, picXor)
const resultPic := Pic.New (x, y, x2, y2 )
% Erase everything
Pic.Draw (bg, x, y, picCopy)
Pic.Free (bg )
Pic.Free (xoredPic )
View.Set ("nooffscreenonly")
result resultPic
end GetBgWherePicIsMerged
fcn PicFadeIn (picID, x, y, mode, duration : int) : FadedPic
const x2 := x + Pic.Width (picID ) - 1
const y2 := y + Pic.Height (picID ) - 1
var fadedPic : FadedPic
fadedPic.isValid := true
fadedPic.x := x
fadedPic.y := y
fadedPic.modeUsed := mode
if mode = picMerge then
fadedPic.bgID := GetBgWherePicIsMerged (picID, x, y )
else
fadedPic.bgID := Pic.New (x, y, x2, y2 )
end if
Pic.DrawSpecial (picID, x, y, picMerge, picFadeIn, duration )
result fadedPic
end PicFadeIn
proc PicFadeOut (var fadedPic : FadedPic, duration : int)
% Assert that fadedPic is valid
assert fadedPic.isValid
Pic.DrawSpecial (fadedPic.bgID, fadedPic.x, fadedPic.y, fadedPic.modeUsed, picFadeIn, duration )
% Free bg and invalidate the record
Pic.Free (fadedPic.bgID )
fadedPic.isValid := false
end PicFadeOut
Draw.FillOval (150, 135, 50, 35, 12)
var oval : int := Pic.New (100, 100, 200, 170)
cls()
Draw.FillBox (0, 0, maxx, maxy, bgColour )
Draw.FillBox (0, 0, 150, maxy, 7)
var fadedOval : FadedPic := PicFadeIn (oval, 100, 100, picMerge, 1000)
Pic.DrawSpecial (oval, 175, 155, picMerge, picFadeIn, 1000)
PicFadeOut (fadedOval, 1000) |
This works for most cases, but adds extra work compared to the first version. If your pictures have a background colour other than white you will have to set it for the FadedPic.bgID as well.
PS: Sorry for the huge post... |
|
|
|
|
![](images/spacer.gif) |
Nathan4102
|
Posted: Sun Sep 08, 2013 5:50 pm Post subject: RE:Wheres picFadeOut???? |
|
|
Wow, didn't think it would be that difficult xD I don't think I'll need to use picMerge, it's just what I've always used as a default. Thanks! |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun Sep 08, 2013 6:29 pm Post subject: RE:Wheres picFadeOut???? |
|
|
picCopy should be your default. It just draws the image on screen as-is. To use picMerge, you need to set a transparent color (using Pic.SetTransparentColor), after which all cases of that color are not drawn in your image (useful for eliminating the white box around character images, for example). |
|
|
|
|
![](images/spacer.gif) |
Nathan4102
|
Posted: Sun Sep 08, 2013 6:43 pm Post subject: RE:Wheres picFadeOut???? |
|
|
Yeah, I used picMerge for like every picture in one of my school projects because I needed to, and now I just always use it for some reason. I definetely should be using picCopy, you're right. |
|
|
|
|
![](images/spacer.gif) |
|
|