There are a bunch of different ways of doing this same thing but here is one way.
type t_Sprite
sprite_image as integer
sprite_id as integer
endtype
global planes as t_Sprite[3]
loadPlaneImages()
createPlane()
do
Print( ScreenFPS() )
Sync()
loop
function loadPlaneImages()
planes[1].sprite_image = LoadImage("planes/planeRed1.png")
planes[2].sprite_image = LoadImage("planes/planeGreen1.png")
planes[3].sprite_image = LoadImage("planes/planeBlue1.png")
endfunction
function createPlane()
for i = 1 to planes.length
planes[i].sprite_id = CreateSprite(planes[i].sprite_image)
next
setspriteposition(planes[1].sprite_id,getspritex(planes[2].sprite_id) + GetSpriteWidth(planes[2].sprite_id), 0)
setspriteposition(planes[2].sprite_id,getspritex(planes[1].sprite_id) + GetSpriteWidth(planes[1].sprite_id), 0)
SetSpritePosition(planes[2].sprite_id, 0,768 - GetSpriteHeight(planes[2].sprite_id))
endfunction
Here is something that may help you understand arrays.
// Project: grid_placement
// Created: 2015-04-11
// set window properties
SetWindowTitle( "grid_placement" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// Set up a multi-dimensional array using types
type t_Sprite
id as integer[1]
endtype
// instantiate the multi-dimensional array
global sprites as t_Sprite[1]
// call the sprite creation function once before we enter the do loop or game loop
createGridOfSprites( 3, 15, 25, 12, 512, 384, 2.5, 27.96541 )
do
// reposition the sprite grid on pointer press
if GetPointerPressed() = 1
repositionGrid(ScreenToWorldX(GetPointerX()), ScreenToWorldY(GetPointerY()), 2.5, 27.96541 )
endif
Print( ScreenFPS() )
Sync()
loop
function createGridOfSprites( width as integer, height as integer, xSize as float, ySize as float, xPos as float, yPos as float, xSpacing as float, ySpacing as float )
// call array resizing function
resizeMDArray(width, height)
x# = xPos
y# = yPos
for j = 1 to sprites.length
for i = 1 to sprites[j].id.length
sprites[j].id[i] = CreateSprite(0)
SetSpriteColor(sprites[j].id[i], Random(0, 255), Random(0, 255), Random(0, 255), 255)
SetSpriteSize(sprites[j].id[i], xSize, ySize)
SetSpritePosition(sprites[j].id[i], x#, y#)
// increment position on x axis by sprite width + space between sprites
inc x#, xSize + xSpacing
// reset x# variable to original starting point to draw the next line of sprites
if i = width then x# = xPos
next
inc y#, ySize + ySpacing
next
endfunction
function repositionGrid( xPos as float, yPos as float, xSpacing as float, ySpacing as float)
// this is almost the same as the sprite creation function except it only positions sprites
x# = xPos
y# = yPos
for j = 1 to sprites.length
for i = 1 to sprites[j].id.length
SetSpritePosition(sprites[j].id[i], x#, y#)
inc x#, GetSpriteWidth(sprites[j].id[i]) + xSpacing
if i = sprites[j].id.length then x# = xPos
next
inc y#, GetSpriteHeight(sprites[j].id[1]) + ySpacing
next
endfunction
function resizeMDArray( w as integer, h as integer)
// dynamically alter array size to fit our specific needs
sprites.length = h
for l = 1 to sprites.length
sprites[l].id.length = w
next
endfunction
function deleteSpriteGrid()
// iterate through the arrays to delete all sprites
for j = 1 to sprites.length
for i = 1 to sprites[j].id.length
DeleteSprite(sprites[j].id[i])
next
next
endfunction