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 / Need some hint to delete sprites

Author
Message
Luca91
11
Years of Service
User Offline
Joined: 1st Sep 2012
Location: Italy
Posted: 30th Jan 2013 15:46
Hello mates,

I'm using this code to draw my sprite array on the screen:



Since I call this function every time my player do something, after some minutes the game slow down (because there is no delete sprite function). Since I create sprites "on the fly" I don't know how can I remove them before to call the RefreshMap function another time.

Any help would be really appreciated
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Jan 2013 16:00 Edited at: 30th Jan 2013 16:01
The game slows down because you are loading memory by creating the same sprites over and over and they never go away.

Assuming you stick with your basic methodology, you need to store the sprite ids when you create them.

Since you appear to be using an array of structures, add a field in your structure to store the sprite id. Make sure that the field is initialized to zero.

Then replace lines like this:


With something like this:


Of course, you can create a function that does all those steps (using the same global array) by passing the x, y, sfx and sfy values and the image number to use for creating the sprite.

There are a lots of threads about dealing with gridded displays and best methods for handling refreshes and movement. I don't do that in my stuff (yet), so have only offered a fix for the problem you are seeing.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Luca91
11
Years of Service
User Offline
Joined: 1st Sep 2012
Location: Italy
Posted: 30th Jan 2013 17:42
Thank you very much Ancient Lady, your solution works great !
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Jan 2013 18:15
Always glad to help.

Happy Programming!

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Feb 2013 17:24

Isn't this incorrect? Shouldn't it be


I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Feb 2013 17:40
Mobiius that's right. I have noticed that functions without parameters can be compile without parenthesis and it might compile ok with the colon but it's a bad habit to get into as it might be fixed at some point to not allow it any more.

I always create functions as you have suggested whether they need parameters passing in or not.


this.mess = abs(sin(times#))
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Feb 2013 17:58
Good catch, Mobiius!

I didn't spot that one. I skipped over the start and just looked at the body of the code.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 1st Feb 2013 19:03
Basic is not C, so the brackets are not required; nor should they ever be! IMHO

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Feb 2013 19:31
Open and close parenthesis as function argument delimiters is pretty common across many languages, including Basic.

They help the compiler determine if there are (or should be) any arguments in the call stack.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 1st Feb 2013 22:09
Only really dumb compilers need that!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 1st Feb 2013 22:42
that function declaration with colon resembles a little the python style. Here is a small function I used in a very old script I have written for job:

Maybe Luca is a python fan...

Login to post a reply

Server time is: 2024-05-06 16:51:34
Your offset time is: 2024-05-06 16:51:34