[UPDATE] Pseudo 3D Backgrounds System

Description: You made a script? Submit it here to show your creation to the public, share, take reviews, provision of the help and support is here!
Moderators: Lx Xzit, Yoshi021, 5438A38A, Semi-moderatos, Moderators

HengShao M
Topic author, Our friend
Our friend
Avatar
HengShao M
Topic author, Our friend
Our friend
Age: 21
Reputation: 63
Posts: 63
Joined: 8 Jan 2016
Tencent QQ

Post #1by HengShao » 27 Jul 2022, 6:19

As we know, in 38A, there isn't Shader function. So it seems to be impossible to make something 3D. But, is that true? Though we can't use 38A to make real 3D stuff, but we can use something like bitmap to make it look like 3D! So I released this Pseudo 3D Backgrounds script I made, in order to let others apply pseudo 3D BGO to their levels more easily!
UPDATE CONTENT:
Spoiler
Fixed some fatal bugs like background displaying incompletely.
Add a parameter which can customize the stretch multiple of the bgo when the screen is scrolling vertically. Set it to 0 to disable the stretch of the bgo.
The code of this function:
Spoiler

Code: Select all

script pseudo3dbg(id as integer, sid as integer, picid as integer, width as integer, height as integer, split as integer, maxi as double, mini as double, stretch as double, type as integer, parax as double, paray as double, xsp as double, z as double, color as double)
    Dim i as integer
    dim x as integer
    Dim s as integer
    dim t as double
    dim ty as double
    dim ty2 as double
    Dim num as integer = -int(-800/width)/(2*(mini+i*(maxi-mini)/(height/split)))
    for s = sid to sid
        for i = 0 to height/split - 1
            for x = -num to num
                If char(1).section = sid Then
                    If i <> 0 Then
                        If type = 1 Then
                            call BmpCreate(id*1000000000+ i*10000 + x, picid, 0, 1, 0, i*split, width, split, sysval(player1scrX), sysval(player1scrY) + 600*type + height*2*(0.5-type) + i*split, 2*(mini+i*(maxi-mini)/(height/split)), 1, 0, 0, 0, color)
                        Else
                            call BmpCreate(id*1000000000+ i*10000 + x, picid, 0, 1, 0, height-i*split, width, split, sysval(player1scrX), sysval(player1scrY) + 600*type + height*2*(0.5-type) + i*split, 2*(mini+i*(maxi-mini)/(height/split)), 1, 0, 0, 0, color)
                        End If
                    Else
                        call BmpCreate(id*1000000000+ i*10000 + x, picid, 0, 1, 0, 0, width, height, sysval(player1scrX), sysval(player1scrY) + 600*type + height*2*(0.5-type) + i*split, 2*(mini+i*(maxi-mini)/(height/split)), 1, 0, 0, 0, color)
                    End If
                Else
                    Call berase(2,sid*1000000000+ id*100000000 +i*10000 + x)
                End If
                t = parax*(section(sid).x + xsp*sysval(gametime) - sysval(player1scrX))/32 - width*2*(((section(sid).x + xsp*sysval(gametime) - sysval(player1scrX))*parax/32)\width*2 - 1)
                ty = paray*(section(sid).y + section(sid).height*type - sysval(player1scrY) - 600*type)/32
                If i <> 0 Then
                    bitmap(id*1000000000+ i*10000 + x).scaley = 1+ty*stretch
                    If bitmap(id*1000000000+ i*10000 + x).scaley >= split*2/stretch Then
                        bitmap(id*1000000000+ i*10000 + x).scaley = split*2/stretch
                    End If
                End If
                bitmap(id*1000000000+ i*10000 + x).zpos = z-i*0.0001
                bitmap(id*1000000000+ i*10000 + x).destx = sysval(player1scrX) + 400 - (width-1)/2*2*(mini+i*(maxi-mini)/(height/split)) + (width-1)*2*(mini+i*(maxi-mini)/(height/split))*x + t*(mini+i*(maxi-mini)/(height/split))
                If i <> 0 Then
                    bitmap(id*1000000000+ i*10000 + x).desty = sysval(player1scrY) + (600 - height)*type - 2*(0.5-type)*i*split + height*(1-type) - 4*stretch*(0.5-type)*ty*(mini+i*(maxi-mini)/(height/split))- 2*(0.5-type)*split
                Else
                    If type = 1 Then
                        bitmap(id*1000000000+ i*10000 + x).desty = sysval(player1scrY) + (600 - height)*type + 1*split + 2*stretch*ty*(mini+1*(maxi-mini)/(height/split))
                    Else
                        bitmap(id*1000000000+ i*10000 + x).desty = sysval(player1scrY) + (600 - height)*type - 2*(0.5-type)*1*split - 4*stretch*(0.5-type)*ty*(mini+1*(maxi-mini)/(height/split))
                    End If
                End If
            next
        next
    next
end script
'split - this determines the split height of the gfx, the smaller this number is, the more refined the bgo is
'maxi - this determines the maximum zoom multiple of the gfx
'mini - this determines the minimum zoom multiple of the gfx
'stretch - this determines the stretch multiple of the gfx when the screen is scrolling vertically, set it to 0 to disable the stretch of the gfx
'type - 1 for glue sth to the floor of the section, 0 for glue sth to the ceiling of the section
'parax - this determines how fast gfx is scrolling when player moves screen horizontally
'paray - this determines how fast gfx is scrolling when player moves screen vertically
'Credit by HengShao, referenced from Yvahnek's Parallax BGO script
'Example:
'Call pseudo3dbg(1,1,1,64,64,1,1.5,0.5,0.5,1,16,8,0.15,0.99,-1)
'(It should in do loop)
By using this script, you can make some cool pseudo-3D backgrounds like these:
Preview GIFs:
Spoiler
Image
Image
Image
Points for Attention:
Spoiler
Only compatible with 1.4.5.
It can't support GFX with transparent background at present.
BGO may become buggy if the section is too long or the split height of the GFX is too small. To solve this, make the split height bigger or change the ID of bitmap to prevent other bitmaps' ID become coincide with it. (For example: bitmap(sid*1000000000+ id*100000000 + i*10000 + x) changes to bitmap(sid*100000000000+ id*10000000000 + i*10000 + x).)
If the section is too long or the split height of the GFX is too small, the game may lose frames. Take the computer configuration of you and players into account when using this script.
Credits:
Spoiler
HengShao - for making this script
Yvahnek - for I referencing his Parallax BGO script
Slash-18 - for I using his rainbow effect script for the example bgos
There's also an example which shows how to use this script, enjoy it!
Attachments
Pseudo 3D BGO (With Examples).rar
(59.69 KiB) Downloaded 25 times
2333~ :huaji:
A SMBX-38A project I am working on:
Image

If you're interested in the project above, or just want to discuss SMBX, welcome to the Hel Studio Discord Server~ :
https://discord.gg/YS6bfysduC

Return to “Script submission”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest