Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / New to AGK2

Author
Message
XE800
9
Years of Service
User Offline
Joined: 24th Nov 2014
Location:
Posted: 24th Nov 2014 18:11
Hi! I'm wondering how to create a sprite from part of an image.

I thought this would work (based on the GetImage help page):

Setvirtualresolution(640,480)
ResetTimer()
swap()
//SetPrintSize(28)
//SetPrintColor(255,255,0)
//Print("G")
LoadImage(1,"Image.gif")
render()
GetImage(2,0,0,32,32)
CreateSprite(1,2)
Do
SetSpritePosition(1,Random(0,600),Random(0,400))
Sync()
Sleep(250)
If Timer()>10 Then Exit
Loop
End

But all I get is blackness. What am I doing wrong?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Nov 2014 18:26
Welcome to the forums

LoadImage doesn't put the image onto the screen, it only puts it into memory. You'll need to paste it before you GetImage().

You might want to check LoadSubImage, which allows you to load images straight from an Texture Atlas. You'll need to check out the example code to see how it works, you describe your Texture Atlas coordinates in a text file.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-04-16 13:05:28
Your offset time is: 2024-04-16 13:05:28