Okay, I've found something weird. Why does this problem work when I make enemies be spawned by hitting mouse, but when I make it timed, it will not work.
First code (timed):
rem
rem AGK Application
rem
rem A Wizard Didn't Do It!
menu:
SetVirtualResolution ( 480, 320 )
do
Print("Tap something to start.")
if GetPointerPressed()=1 then goto game
Sync()
loop
game:
SetSyncRate( 30, 0 )
type _obj
id
x#
y#
endtype
dim enemy[99] as _obj //create an array with 100 slots (0 is counted as a slot)
count = 10 //setup a count to keep track of the number of enemies created
counting = 10
SetClearColor (255,0,0)
rem PORTAL
LoadImage (103,"portal.png")
CreateSprite (103,103)
SetSpriteOffset (103,22.5,22.5)
SetSpritePosition (103,240-22.5,160-22.5)
rem DUMMY PORTAL
CreateDummySprite(104)
SetSpritePosition (104,240,160)
rem PLAYER
loadimage (101,"player2.png",1)
createsprite (101,101)
FixSpriteToScreen (101,1)
SetSpritePosition ( 101, 150, 146.5 )
SetSpriteOffset (101,13.5,13.5)
SetSpritePhysicsOn (101,2)
SetSpritePhysicsCanRotate (101,0)
rem ENEMY
LoadImage (102,"enemy.png",1)
CreateSprite (102,102)
SetSpriteAnimation (102,27,27,10)
SetSpritePosition ( 102, 50, 0 )
SetSpriteOffset (102,13.5,13.5)
SetSpritePhysicsOn (102,2)
SetSpritePhysicsCanRotate (102,0)
PlaySprite (102,10,1,1,10)
rem SCORES
score = 0
scoreText = CreateText( "Score: "+str(score))
SetTextSize (scoreText,20)
rem PHYSICS
SetPhysicsWallBottom ( 0 )
SetPhysicsWallTop ( 0 )
SetPhysicsWallLeft ( 0 )
SetPhysicsWallRight ( 0 )
SetPhysicsGravity (0,0)
rem JOYSTICK
AddVirtualJoystick ( 1, 50, 270, 10 )
SetVirtualJoystickSize (1,80)
rem VARIABLES
record#=GetSeconds()
do
rem KEEP PLAYER IN SCREEN
if GetSpriteX(101)>450 then SetSpriteX(101,GetSpriteX(1)-( joystickX# )*2)
if GetSpriteX(101)<10 then SetSpriteX(101,GetSpriteX(1)-( joystickX# )*2)
if GetSpriteY(101)>290 then SetSpriteY(101,GetSpriteY(1)-( joystickY# )*2)
if GetSpriteY(101)<10 then SetSpriteY(101,GetSpriteY(1)-( joystickY# )*2)
if GetSpriteDistance(104,101)<3 then End
rem PLAYER MOVEMENT
joystickX# = GetVirtualJoystickX ( 1 )
joystickY# = GetVirtualJoystickY ( 1 )
plrx# = GetSpriteX ( 101 )
plry# = GetSpriteY ( 101 )
plrx1# = plrx# - joystickX#
plry1# = plry# - joystickY#
SetSpritePosition ( 101, GetSpriteX ( 101 ) + ( joystickX# )*2, GetSpriteY ( 101 ) + ( joystickY# )*2 )
rem SPAWN FIRST ENEMY
if ( GetSeconds() > record + 4 ) then first=1
if first=1
CreateEnemy()
enemies_on=1
first=0
endif
rem SPAWN ENEMIES
if enemies_on=1
counter=counter+1
if counter>=100
CreateEnemy()
counter=1
endif
endif
rem CONTROL ENEMIES
if enemies_on=1
for counting=10 to 100
enemy[counting].x# = GetSpriteX(enemy[counting].id)
enemy[counting].y# = GetSpriteY(enemy[counting].id)
SetSpritePosition (enemy[counting].id, enemy[counting].x#, enemy[counting].y# )
enemy[counting].x# = enemy[counting].x# + 0.5
enemy[counting].y# = enemy[counting].y# + 0.5
next counting
endif
Sync()
loop
function CreateEnemy()
count = count + 1
if count > 100 then count = 10
if enemy[count].id > 10
enemy[count].x# = 240-13.5
enemy[count].y# = 160-13.5
SetSpritePosition(enemy[count].id, enemy[count].x#, enemy[count].y#)
else
enemy[count].id = clonesprite( 102 )
enemy[count].x# = 240-13.5
enemy[count].y# = 160-13.5
SetSpritePosition (enemy[count].id, enemy[count].x#, enemy[count].y#)
SetSpritePhysicsOn (enemy[count].id,2)
SetSpritePhysicsCanRotate (enemy[count].id,0)
PlaySprite (enemy[count].id,10,1,1,10)
endIf
endfunction
And the second code (works)(spawns when GetPointerState()=1)
rem
rem AGK Application
rem
rem A Wizard Didn't Do It!
menu:
SetVirtualResolution ( 480, 320 )
do
Print("Tap something to start.")
if GetPointerPressed()=1 then goto game
Sync()
loop
game:
SetSyncRate( 30, 0 )
type _obj
id
x#
y#
endtype
dim enemy[99] as _obj //create an array with 100 slots (0 is counted as a slot)
count = 10 //setup a count to keep track of the number of enemies created
counting = 10
SetClearColor (255,0,0)
rem PORTAL
LoadImage (103,"portal.png")
CreateSprite (103,103)
SetSpriteOffset (103,22.5,22.5)
SetSpritePosition (103,240-22.5,160-22.5)
rem DUMMY PORTAL
CreateDummySprite(104)
SetSpritePosition (104,240,160)
rem PLAYER
loadimage (101,"player2.png",1)
createsprite (101,101)
FixSpriteToScreen (101,1)
SetSpritePosition ( 101, 150, 146.5 )
SetSpriteOffset (101,13.5,13.5)
SetSpritePhysicsOn (101,2)
SetSpritePhysicsCanRotate (101,0)
rem ENEMY
LoadImage (102,"enemy.png",1)
CreateSprite (102,102)
SetSpriteAnimation (102,27,27,10)
SetSpritePosition ( 102, 50, 0 )
SetSpriteOffset (102,13.5,13.5)
SetSpritePhysicsOn (102,2)
SetSpritePhysicsCanRotate (102,0)
PlaySprite (102,10,1,1,10)
rem SCORES
score = 0
scoreText = CreateText( "Score: "+str(score))
SetTextSize (scoreText,20)
rem PHYSICS
SetPhysicsWallBottom ( 0 )
SetPhysicsWallTop ( 0 )
SetPhysicsWallLeft ( 0 )
SetPhysicsWallRight ( 0 )
SetPhysicsGravity (0,0)
rem JOYSTICK
AddVirtualJoystick ( 1, 50, 270, 10 )
SetVirtualJoystickSize (1,80)
rem VARIABLES
do
rem KEEP PLAYER IN SCREEN
if GetSpriteX(101)>450 then SetSpriteX(101,GetSpriteX(1)-( joystickX# )*2)
if GetSpriteX(101)<10 then SetSpriteX(101,GetSpriteX(1)-( joystickX# )*2)
if GetSpriteY(101)>290 then SetSpriteY(101,GetSpriteY(1)-( joystickY# )*2)
if GetSpriteY(101)<10 then SetSpriteY(101,GetSpriteY(1)-( joystickY# )*2)
if GetSpriteDistance(104,101)<3 then End
rem PLAYER MOVEMENT
joystickX# = GetVirtualJoystickX ( 1 )
joystickY# = GetVirtualJoystickY ( 1 )
plrx# = GetSpriteX ( 101 )
plry# = GetSpriteY ( 101 )
plrx1# = plrx# - joystickX#
plry1# = plry# - joystickY#
SetSpritePosition ( 101, GetSpriteX ( 101 ) + ( joystickX# )*2, GetSpriteY ( 101 ) + ( joystickY# )*2 )
rem SPAWN ENEMIES
if GetPointerPressed()=1
CreateEnemy()
endif
rem CONTROL ENEMIES
if enemies_on=1
for counting=10 to 100
enemy[counting].x# = GetSpriteX(enemy[counting].id)
enemy[counting].y# = GetSpriteY(enemy[counting].id)
SetSpritePosition (enemy[counting].id, enemy[counting].x#, enemy[counting].y# )
enemy[counting].x# = enemy[counting].x# + 0.5
enemy[counting].y# = enemy[counting].y# + 0.5
next counting
endif
Sync()
loop
function CreateEnemy()
count = count + 1
if count > 100 then count = 10
if enemy[count].id > 10
enemy[count].x# = 240-13.5
enemy[count].y# = 160-13.5
SetSpritePosition(enemy[count].id, enemy[count].x#, enemy[count].y#)
else
enemy[count].id = clonesprite( 102 )
enemy[count].x# = 240-13.5
enemy[count].y# = 160-13.5
SetSpritePosition (enemy[count].id, enemy[count].x#, enemy[count].y#)
SetSpritePhysicsOn (enemy[count].id,2)
SetSpritePhysicsCanRotate (enemy[count].id,0)
PlaySprite (enemy[count].id,10,1,1,10)
endIf
endfunction
I wouldn't say that this is a bug, it is that I just don't get it or something. Anyone had this kind of thing with DBPro or AppGameKit or something else? A little help would be a great help for me.
Thanks,
TP