Hi,
I am trying to optimize another slow AppGameKit Classic HTML5 game...
I am currently using: "SetSpriteVisible()" to make unused playfield sprites invisible.
It's very slow and am wondering if "DeleteSprite()" would be faster?
Let me know thanks!
Jesse
EDIT #1: Link to game:
http://fallenangelsoftware.com/spaceswap.html
SOURCE CODE:
function DrawPlayfield()
index as integer
for index = 2 to 78
SetSpriteVisible ( BoxRedSprite[index], 0 )
SetSpriteVisible ( BoxOrangeSprite[index], 0 )
SetSpriteVisible ( BoxYellowSprite[index], 0 )
SetSpriteVisible ( BoxGreenSprite[index], 0 )
SetSpriteVisible ( BoxBlueSprite[index], 0 )
SetSpriteVisible ( BoxPurpleSprite[index], 0 )
SetSpriteVisible ( BoxWhiteSprite[index], 0 )
next index
BoxRedUsed = 2
BoxOrangeUsed = 2
BoxYellowUsed = 2
BoxGreenUsed = 2
BoxBlueUsed = 2
BoxPurpleUsed = 2
BoxWhiteUsed = 2
indexY as integer
indexX as integer
screenY as integer
screenY = 83
screenX as integer
screenX = 67
for indexY = 0 to 12
for indexX = 0 to 5
if ( (PlayerSwapOnePlayfieldX <> indexX or PlayerSwapOnePlayfieldY <> indexY) and (PlayerSwapTwoPlayfieldX <> indexX or PlayerSwapTwoPlayfieldY <> indexY) )
if (Playfield[indexX, indexY] = 1)
SetSpriteVisible ( BoxRedSprite[BoxRedUsed], 1 )
SetSpritePositionByOffset( BoxRedSprite[BoxRedUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxRedUsed
inc BoxRedUsed, 1
elseif (Playfield[indexX, indexY] = 2)
SetSpriteVisible ( BoxOrangeSprite[BoxOrangeUsed], 1 )
SetSpritePositionByOffset( BoxOrangeSprite[BoxOrangeUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxOrangeUsed
inc BoxOrangeUsed, 1
elseif (Playfield[indexX, indexY] = 3)
SetSpriteVisible ( BoxYellowSprite[BoxYellowUsed], 1 )
SetSpritePositionByOffset( BoxYellowSprite[BoxYellowUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxYellowUsed
inc BoxYellowUsed, 1
elseif (Playfield[indexX, indexY] = 4)
SetSpriteVisible ( BoxGreenSprite[BoxGreenUsed], 1 )
SetSpritePositionByOffset( BoxGreenSprite[BoxGreenUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxGreenUsed
inc BoxGreenUsed, 1
elseif (Playfield[indexX, indexY] = 5)
SetSpriteVisible ( BoxBlueSprite[BoxBlueUsed], 1 )
SetSpritePositionByOffset( BoxBlueSprite[BoxBlueUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxBlueUsed
inc BoxBlueUsed, 1
elseif (Playfield[indexX, indexY] = 6)
SetSpriteVisible ( BoxPurpleSprite[BoxPurpleUsed], 1 )
SetSpritePositionByOffset( BoxPurpleSprite[BoxPurpleUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxPurpleUsed
inc BoxPurpleUsed, 1
elseif (Playfield[indexX, indexY] = 11)
SetSpriteVisible ( BoxRedSprite[BoxRedUsed], 1 )
SetSpritePositionByOffset( BoxRedSprite[BoxRedUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxRedUsed
inc BoxRedUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
elseif (Playfield[indexX, indexY] = 12)
SetSpriteVisible ( BoxOrangeSprite[BoxOrangeUsed], 1 )
SetSpritePositionByOffset( BoxOrangeSprite[BoxOrangeUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxOrangeUsed
inc BoxOrangeUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
elseif (Playfield[indexX, indexY] = 13)
SetSpriteVisible ( BoxYellowSprite[BoxYellowUsed], 1 )
SetSpritePositionByOffset( BoxYellowSprite[BoxYellowUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxYellowUsed
inc BoxYellowUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
elseif (Playfield[indexX, indexY] = 14)
SetSpriteVisible ( BoxGreenSprite[BoxGreenUsed], 1 )
SetSpritePositionByOffset( BoxGreenSprite[BoxGreenUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxGreenUsed
inc BoxGreenUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
elseif (Playfield[indexX, indexY] = 15)
SetSpriteVisible ( BoxBlueSprite[BoxBlueUsed], 1 )
SetSpritePositionByOffset( BoxBlueSprite[BoxBlueUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxBlueUsed
inc BoxBlueUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
elseif (Playfield[indexX, indexY] = 16)
SetSpriteVisible ( BoxPurpleSprite[BoxPurpleUsed], 1 )
SetSpritePositionByOffset( BoxPurpleSprite[BoxPurpleUsed], screenX, screenY-PlayfieldOffsetY )
PlayfieldColoredBoxIndex[indexX, indexY] = BoxPurpleUsed
inc BoxPurpleUsed, 1
if ( mod(MatchFlashTimer, 3) = 0 )
SetSpriteVisible ( BoxWhiteSprite[BoxWhiteUsed], 1 )
SetSpritePositionByOffset( BoxWhiteSprite[BoxWhiteUsed], screenX, screenY-PlayfieldOffsetY )
inc BoxWhiteUsed, 1
endif
endif
endif
if (indexY = 12)
SetSpritePositionByOffset( BoxBlackSprite[indexX], screenX, screenY-PlayfieldOffsetY )
endif
inc screenX, 45
next indexX
inc screenY, 45
screenX = 67
next indexY
screenY = 83
screenX = 67+22
for indexY = 0 to 11
for indexX = 0 to 5
if (PlayerPlayfieldX = indexX and PlayerPlayfieldY = indexY)
if (ShowCursor = TRUE) then SetSpritePositionByOffset( SelectorSprite, screenX, screenY-PlayfieldOffsetY )
PlayerScreenX = screenX
PlayerScreenY = screenY-PlayfieldOffsetY
endif
inc screenX, 45
next indexX
inc screenY, 45
screenX = 67+22
next indexY
endfunction