Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImagePop - puts image on screen with a little popup effect
#1
Started on this routine today for a friend who wants to make a menu pop on the screen with a little flair.  Here's what I have so far.  It just grows the image in with a little extra grow and shrink loop at the end, and then shrinks the image out.  Posting here for any suggestions and improvements.  Maybe there's a much better way to do the effect.

- Dav

Code: (Select All)

'imagepop.bas
'============
'Shows menu image on screen with a popup effect.
'Coded by Dav MAY/2024 with QB64PE v3.13.0

Screen _NewImage(1024, 680, 32)

'== make a sample image to use offscreen  (REPLACE WITH YOUR OWN)
menu& = _NewImage(500, 500, 32) 'name the image
_Dest menu& 'point drawing commands to it
Cls , _RGB(255, 255, 255) 'main color of image
Line (10, 10)-(490, 490), _RGB(64, 64, 128), BF 'draw border
For y = 10 To 490 Step 5
    Line (10, y)-(490, y), _RGB(0, 0, 0), B 'draw lines down screen
Next
_PrintMode _KeepBackground 'using this so printstring wont destroy background
For t = 1 To 200
    _PrintString (Rnd * 425 + 10, Rnd * 460 + 10), "MENU" 'print something
Next
'===================

_Dest 0 'now point drawing back to main screen


'=== draw stuff on screen
For x = 10 To _Width - 10 Step 10
    For y = 10 To _Height - 10 Step 10
        Line (x, y)-Step(5, 5), _RGB(Rnd * 255, Rnd * 255, Rnd * 255), BF
    Next
Next

'pop image in
PopImage "in", _Width / 2, _Height / 2, menu&

Sleep 2 'wait

'pop it out
PopImage "out", _Width / 2, _Height / 2, menu&



Sub PopImage (way$, x, y, image&)

    Static PopImageBack& 'share this

    xmax = _Width(image&)
    ymax = _Height(image&)

    _Display

    If UCase$(way$) = "IN" Then

        '== copy background first
        PopImageBack& = _CopyImage(_Display)

        '=== pop image on screen

        xcount = 0: ycount = 0
        Do
            _PutImage (x - xcount, y - ycount)-(x + xcount, y + ycount), image&
            xcount = xcount + 4: ycount = ycount + 4
            If xcount > xmax / 2 Then xcount = xmax / 2
            If ycount > ymax / 2 Then ycount = ymax / 2
            If xcount >= (xmax / 2) And ycount >= (ymax / 2) Then Exit Do
            _Limit 250
            _Display
        Loop

        '=== make a little pop effect (grows and shrinks at end)
        For highpop = 100 To 1 Step -20
            For t = 1 To highpop Step 4
                Cls
                _PutImage (0, 0), PopImageBack&
                _PutImage (x - xcount - t, y - ycount - t)-(x + xcount + t, y + ycount + t), image&
                _Display
                _Limit 200 + highpop
            Next
            For t = highpop To 1 Step -3
                Cls
                _PutImage (0, 0), PopImageBack&
                _PutImage (x - xcount - t, y - ycount - t)-(x + xcount + t, y + ycount + t), image&
                _Display
                _Limit 200 + highpop
            Next
        Next

        'Make sure it show normal at the end
        Cls
        _PutImage (0, 0), PopImageBack&
        _PutImage (x - (xmax / 2), y - (ymax / 2)), image&
        _Display

    End If

    If UCase$(way$) = "OUT" Then

        'check if PopImageBack& exists here? <<

        'unpop image here
        xcount = xmax: ycount = ymax
        Do
            Cls
            _PutImage (0, 0), PopImageBack&
            _PutImage (x - xcount, y - ycount)-(x + xcount, y + ycount), image&
            xcount = xcount - 4: ycount = ycount - 4
            If xcount > xmax / 2 Then xcount = xmax / 2
            If ycount > ymax / 2 Then ycount = ymax / 2
            If xcount <= 0 And ycount <= 0 Then Exit Do
            _Limit 200
            _Display
        Loop

        '=== restore background
        Cls
        _PutImage (0, 0), PopImageBack&
        _Display
    End If

    _AutoDisplay

End Sub

Find my programs here in Dav's QB64 Corner
Reply
#2
Have you seen these? -- https://qb64phoenix.com/forum/showthread.php?tid=1329 

There might be something in that pack of interest for you, which produces a "pop out" style effect.  Wink
Reply
#3
(05-29-2024, 01:07 PM)SMcNeill Wrote: Have you seen these? -- https://qb64phoenix.com/forum/showthread.php?tid=1329 

There might be something in that pack of interest for you, which produces a "pop out" style effect.  Wink

Oh yes, those are cool!  I had saved them, somewhere.  Saved them again now. Smile

- Dav

Find my programs here in Dav's QB64 Corner
Reply




Users browsing this thread: 2 Guest(s)