I don't understand why I am getting this error. I have two agc that separates like following:
main.agc
// Project: MyGame
// Created: 19-09-01
// show all errors
#include "sprite.agc"
#insert "Utilities.agc"
SetErrorMode(2)
// set window properties
SetWindowTitle( "MyGame" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( GetDeviceWidth()/2, GetDeviceHeight()/2 ) // 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 )
InitPlayer()
//player.x = GetVirtualWidth() / 2 - GetSpriteWidth(player.image)
InitPlayerPosition(player)
do
Print( ScreenFPS() )
print(player.sprite)
if GetRawKeyState(KEY_RIGHT)
inc player.x, 10
elseif GetRawKeyState(KEY_LEFT)
dec player.x, 10
endif
SetSpritePosition(player.sprite, player.x, player.y)
Sync()
loop
sprite.agc
// File: sprite.agc
// Created: 19-09-01
type Player
image as integer
sprite as integer
x as integer
y as integer
endtype
global player as Player
function InitPlayer()
player.image = LoadImage("Player.png")
player.sprite = CreateSprite(player.image)
endfunction
function InitPlayerPosition( a ref as Player)
a.x = GetVirtualWidth() /2 - GetSpriteWidth(a.image/2)
a.y = GetVirtualHeight() / 2
endfunction
When I run the above code it gave me "sprite 50000 doesn't exist in sprite.agc at line 18".
However if i comment out InitPlayerPosition and use player.x = GetVirtualWidth() / 2 - GetSpriteWidth(player.image), it doesn't show any error and my sprite show in the middle(this is what i wanted).
I can't tell the difference between these two codes.
Is this a bug or I did something wrong?