Try my code and extract function
Press "Space" to increase frame of the sprite in the animation sequence
// Created: 2017-01-13
// show all errors
SetErrorMode(2)
#constant screenwidth = 1024
#constant screenheight = 768
#constant TRUE = 1
#constant FALSE = 0
// set window properties
SetWindowTitle( "Animation" )
SetWindowSize( screenwidth, screenheight, 0 )
// set display properties
SetVirtualResolution( screenwidth, screenheight )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
PlayerImages = loadimage("\media\water.png")
WaterImages = extractfromspritesheet(PlayerImages, 4, 7, "", "")
frame=1
// Reset a timer for use as ther level timer go down every second
do
SetSpritePosition(waterimages,100,100)
if GetRawKeyPressed(32)=1
inc frame
SetSpriteFrame(WaterImages, frame)
endif
Render2DFront()
sync()
loop
//************
// If you have a spritesheet for any of your sprites - this function will exatract them for you
// For this function to work, each and every sprite needs to be same width and height through
// out the sheet, unless you have an Atlas file
//
// filename$ = path \ filename$ of the selected image
// sizex = How many sprites horizontal in your fixed sprite sheet
// sizey = How many sprites vertical in your fixed sprite sheet
// subimage$ = This i the Atlas file of which is a txt file in the same folder, which references different heights and
// widths of a sprite, use in conjunction with retreive$
// retreive$ = Inside the subimage the start of the line represents the sprite name you wish to extract out
//
// Returns a sprite
//
function extractfromspritesheet(ID, sizex, sizey, subimage$, retreive$)
// Lets work out the sizes of the fixed spritesheet to do this, can use memblocks to get the dimensions
// First Load into memory
if subimage$=""
SpriteSheet = CreateMemblockFromImage(ID)
// The first 3 Header info of a memblock is Width / Height and Depth and as its Integers through out
// The Offsets always goes in multiples of 4
SpriteSizeX = GetMemblockInt(SpriteSheet,0) // Get the whole image width
SpriteSizeY = GetMemblockInt(SpriteSheet,4) // Get the whole image heght
SpriteDepth = GetMemblockInt(SpriteSheet,8) // Not required here, but its to show
// Always release images when not required anymore
DeleteMemblock(SpriteSheet)
// Now we need to work out each individual sprites according to the sizex and sizey brought into
// the function
SpriteWidth = SpriteSizeX / sizex
spriteHeight = SpriteSizeY / sizey
HowMany=sizex * sizey
// make some sprites
makesprite = CreateSprite(ID)
// assign the image to the sprite as howmany images there are,
SetSpriteAnimation(makesprite,Spritewidth,SpriteHeight,HowMany)
else
subimg = LoadSubImage(ID, retreive$)
makesprite = createsprite(subimg)
endif
endfunction makesprite
Seem to work for me
Damian