DrawImageFrame - Ei enää erillistä LoadAnimImage kutsua!

Oletko tehnyt jotain, mistä muut voisivat hyötyä. Postita vinkit tänne.
Post Reply
MaGetzUb
Guru
Posts: 1715
Joined: Sun Sep 09, 2007 12:35 pm
Location: Alavus

DrawImageFrame - Ei enää erillistä LoadAnimImage kutsua!

Post by MaGetzUb »

Kehittelimpä funktion, joka piirtää kuvasta tietyn palasen, kun sille vain antaa kuvan, sijainnit vaaka että pystyakselilla, framen järjestysnumeron, sekä framen leveyden ja korkeuden. :) Jos framearvo menee yli kuvassa olevien framejen määrän, aloitetaan ensimmäisestä framesta. :)

Funktio

Code: Select all

Function DrawImageFrame(img, x, y, frame, framew, frameh) 
    frame = Int(frame)
    framesrowx = Int(ImageWidth(img) / framew) 
    framecx = (frame Mod framesrowx) * framew
    framecy = ((Int(frame / framesrowx) * frameh) Mod ImageHeight(img))
    
    DrawImageBox img, x - camx, y - camy, framecx, framecy, framew, frameh
End Function
Esimerkki + Funktio

Code: Select all

SCREEN 512, 512

img = LoadImage("Media\Tileset.BMP")
Repeat 

    
    If Timer() > h + 250 Then h = Timer() : f = f + 1
    d = -1
    For i = 0 To 15
        For j = 0 To 15
            d = d + 1
            DrawImageFrame(img, j*32, i*32, d+f, 32, 32)
        Next j
    Next i

    DrawImageFrame(img, MouseX(), MouseY(), f, 32, 32)

DrawScreen
Forever

Function DrawImageFrame(img, x, y, frame, framew, frameh) 
    frame = Int(frame)
    framesrowx = Int(ImageWidth(img) / framew) 
    framecx = (frame Mod framesrowx) * framew
    framecy = ((Int(frame / framesrowx) * frameh) Mod ImageHeight(img))
    
    DrawImageBox img, x - camx, y - camy, framecx, framecy, framew, frameh
End Function
Solar Eclipse
Meneillä olevat Projektit:
We're in a simulation, and God is trying to debug us.
KilledWhale
Tech Developer
Tech Developer
Posts: 545
Joined: Sun Aug 26, 2007 2:43 pm
Location: Liminka

Re: DrawImageFrame - Ei enää erillistä LoadAnimImage kutsua!

Post by KilledWhale »

Muuten hyvä idea mutta tuo funktiokutsu aiheuttaa turhaa viivettä. LoadAnimImagella pääsee huomattavasti tehokkaampaan lopputulokseen.
CoolBasic henkilökuntaa
Kehittäjä

cbFUN Kello
cbSDL
Whale.dy.fi

<@cce> miltäs tuntuu olla suomen paras
MaGetzUb
Guru
Posts: 1715
Joined: Sun Sep 09, 2007 12:35 pm
Location: Alavus

Re: DrawImageFrame - Ei enää erillistä LoadAnimImage kutsua!

Post by MaGetzUb »

KilledWhale wrote:Muuten hyvä idea mutta tuo funktiokutsu aiheuttaa turhaa viivettä. LoadAnimImagella pääsee huomattavasti tehokkaampaan lopputulokseen.
Totta, mutta tämä on helppo kääntää vaikka sitten C++:le kun käyttää esim SDL kirjastoa. :)
Solar Eclipse
Meneillä olevat Projektit:
We're in a simulation, and God is trying to debug us.
Post Reply