(AGK version: 108.19)
Submitted: 2013-10-21 14:52:05
rem AGK Application 1.08 Beta 19
rem MR 21.10.2013 

SetDisplayAspect( 4.0/3.0 )

//--------------------------

MainLoop()
end

//--------------------------

function MainLoop()

    //my atlas image
    //3 rows each 8 images = 24 subimages
    //image witdh = 512 / 8 = 64 pixels
    //64x64 one image

    dim img[24]
    imga=loadimage("animals.png")
    for i=0 to 23
        //each line line in "animals subimages.txt" = imageName:X:Y:Width:Height (ignore //)
        //img0:0:0:64:64
        //img1:64:0:64:64
        //img2:128:0:64:64
        img[i]=LoadSubImage(imga,"img"+str(i)) //get one image by virtual image name in "animals subimages.txt" file
    next

    //-------------------------- dummy sprite for width & height because display aspect
    spr=createsprite(0)
    setspritesize(spr,10.0,-1) //-1 = automatic height
    w#=getspritewidth(spr)
    h#=getspriteheight(spr)
    deletesprite(spr)
    //--------------------------

    //-------------------------- some sprites on screen
    i=0
    for y#=0.0 to 100.0-h# step h#
    for x#=0.0 to 100.0-w# step w#
        spr=createsprite(img[i])
        setspriteposition(spr,x#,y#)
        setspritesize(spr,w#,h#)
        i=i+1
        if i>23 then i=0
    next
    next

    //--------------------------

    do
     if getpointerpressed()=1 then exit
     Sync()
    loop

    //--------------------------

    //... free ...

    undim img[]
    deleteimage(imga)

endfunction

(AGK version: 2)
Submitted: 2023-04-18 08:00:34
// Project: loadsubimage
// Created: 2023-04-16
// code by virtual nomad

// show all errors
SetErrorMode(2)

// set window properties
SetWindowSize(800,600, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 800,600) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts


Texture = LoadImage("Explosion03.png")
GLOBAL Frame, Duration#, LastFrame#, Boom as Integer []
Frame = 0
Duration# = 0.05
For x = 0 to 15
    Boom.Insert(LoadSubImage(Texture, "img_"+STR(x)))
Next x
 
Plane = CreateObjectPlane( 10.0, 10.0 )
    SetObjectImage( Plane, Boom[Frame], 0 )
    SetObjectTransparency( Plane, 1 )
 
SetCameraRotation( 1, 0.0, 0.0, 0.0 )
SetCameraPosition( 1, 0.0, 0.0, -15.0 )
 
Do
    If LastFrame# + Duration# <= Timer()
        INC Frame   :   If Frame > Boom.Length then Frame = 0
        SetObjectImage( Plane, Boom[Frame], 0 )
        LastFrame# = Timer()
    EndIf
    Sync()
loop
(AGK version: 2)
Submitted: 2023-04-18 08:23:46
// Project: create subimage file
// Created: 2023-04-16
// by blendman

// show all errors
SetErrorMode(2)

// set window properties
SetWindowSize(800,600, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 800,600) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts


SaveSubImagetext("","",0,0)


Function SaveSubImagetext(saveFilename$, imageFilename$, Col, row)
  
  If imageFilename$=""
    imageFilename$ = ChooseRawFile("*.jpg;*.png", 1)
    
  EndIf
  
  If imageFilename$=""
    Message("No image selected")
  Else
    
    imageFilename$ = "raw:"+imageFilename$
    
    
    If col<=0
      col = 4
    EndIf
    
    If row <= 0
      row = 4
    EndIf
    
    nbimg = col * row
    
    if GetFileExists(imageFilename$) = 0
		message(imageFilename$)
		end
    endif
    
    LoadImage(1, imageFilename$)
    
    If GetImageExists(1)
      
      imgw = getImageWidth(1) 
      imgh = getImageHeight(1)
      
      w = imgw/Col
      h = imgh/row
      
      a=-1
      b=0
      For i=0 To nbimg-1
        
        inc a
        If a> col-1
          a=0 
          inc b
        EndIf
        txt$ =txt$ + "img_"+Str(i)+":"+Str(a*w)+":"+Str(b*h)+":"+Str(w)+":"+Str(w)+":" +Chr(13)
        
      Next
      
      If saveFilename$ = ""
        ext$ = "." +GetExtensionFile(imageFilename$)
        saveFilename$ = ReplaceString(imageFilename$, ext$, "",1)+" subimages.txt"
      EndIf
      
      DeleteImage(1)
      
      OpenToWrite(1, saveFilename$)
       WriteLine(1, txt$)
      CloseFile(1)
      
      
    EndIf
  EndIf
  
  end
  
Endfunction

Function GetExtensionFile(file$)
	
	count = FindStringCount(file$, "/" ) 
	file$ = GetStringToken(file$, "/", count+1)
	ext$ = GetStringToken(file$,".",2)
	
EndFunction ext$
Help make AGK better by submitting an example for this command!
(All examples are subject to approval)
Login to post an example of your own.