Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Can't create sprite?

Author
Message
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 31st Jan 2014 18:17
OK I admit defeat.

I'm running the CreateAllAsteroids function (see below), but AppGameKit seems to get stuck at some point creating one of the new sprites.

What's weird is that it will crash at random points. The function attempts to create 24 sprites from the same image, but sometimes it will crash on the first sprite, sometimes on the 18th, sometimes on the 6th.

I'm really lost with this one so any help will be great.

I'm running v108.19 on win7.

The functions are below.



TrezSoft
AGK Tool Maker
12
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 31st Jan 2014 19:02
Maybe this line fixspritetoscreen(spriteid,0)

As you should not use physics or collisions with fixed sprites.
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 31st Jan 2014 19:18
Cheers TrezSoft, but the "0" in that command is not fixing the sprite.

Anyway I'm desperate so I tried commenting the command out, but it made no difference.

Incidentally the error code I get is 805306369 which seems to suggest there is a memory leak somewhere.

TrezSoft
AGK Tool Maker
12
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 31st Jan 2014 19:35
Missed that sorry , why bother fixing it at all then ?

anyway whats going on here:

spriteid = createsprite(ImageID)
asteroid[a].spriteid = spriteid

if getspriteexists(asteroid[a].spriteid)=0
deletesprite(spriteid)
print("lost sprite "+str(spriteid))

endif
until getspriteexists(asteroid[a].spriteid)=1

maybe i am missing something but why create it check if it does not exist and then try and delete it ?
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 31st Jan 2014 20:04
Ah that weird double check is to catch another weird bug. I found that this line:

asteroid[a].spriteid = spriteid

wouldn't always work and later in the game i would end up with the screen filled with hundreds of sprites.

So to stop that, i just check that the sprite ID has been copied correctly - if it hasn't it deletes the sprite and tries again.

Anyhooo, i just spotted 108.21 and having installed this - the bug has vanished

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Feb 2014 03:09
This might not be all of it, but try changing this:


to this:


And, you should consider changing that first repeat loop so that it stops after <x> iterations and declare a program failure. If there is something fundamentally breaking when you try to create a sprite and you keep trying, it could get stuck in a loop or memory crash.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Feb 2014 08:45
I'm trying to figure out what the point of this code here is:


You create a sprite, then if it doesn't exist you'll delete it. That makes absolutely no sense.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Feb 2014 16:04
Wouldn't it be simpler to re-use the sprite if it exists ?


More efficient then deleting and recreating sprites
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 1st Feb 2014 23:56
Cheers for the help guys. I'll try and add a bit more context.

When the game starts it creates all 24 asteroids in one go.

As the game is ran it checks to see if any sprites have wandered too far from the player or if the sprite no longer exists and it re-runs the CreateAsteroid functions for a specific ID.

The reason for creating a sprite and then checking to see if the ID was copied across to the array correctly - I'm pretty sure the sprite is created corrected, but for some reason AppGameKit doesn't copy to ID into the array correctly all the time.

So unless I put that weird check in, I end up with hundreds of sprites filling the screen.

Login to post a reply

Server time is: 2024-11-25 01:54:55
Your offset time is: 2024-11-25 01:54:55