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 / Array for sprite movement not finding sprite 0

Author
Message
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 22nd Mar 2012 18:13
I used this code to pick up a sprite and move it. Right now I have all this code eight times to move each sprite. I have eight sprites now but plan on a lot more. I created an array and used the array to replace the sprite ID so I could cycle through the IDs and use one check for all the sprites. It worked fine if I use the sprite ID but when I use the array it says "Sprite 0 does not exist". I am not sure if I can do this or if it is a problem with my array. Thanks.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Mar 2012 19:03
Is this the entire code?

There is nothing here which creates the sprites or puts their references into the array.
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 22nd Mar 2012 20:42
Yes. Your sprite id will start in the 10,000 range. When you create your sprites you want to store the values into that array. Also I would look at your code and do a little optimization. I have a funny feeling that this might run slow.
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 23rd Mar 2012 05:42
No it is not the entire code. I forgot to store the values into the array. I did this and now it works. Well sorta. It grabs all the sprites and moves them all at once. I have to imagine that there has to be a better way to code this then to have a huge if statement for every single sprite I want to move. Here is the whole code. The part I have REM out is the part I want to remove and replace with one if statement or something better.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 23rd Mar 2012 07:21 Edited at: 23rd Mar 2012 07:36
This should get you started;

It's not much more to add a formula to include the positions in the loop as well, but I thought I'd leave something for you to work out

edit:

Also, you don't need to do a sprite hit check against each sprite in your main loop as you would with a text object.

GetSpriteHit( getPointerX() , getPointerY() ) returns the index of the sprite under the pointer.
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 23rd Mar 2012 16:32
Thanks everyone. I didn't realize arrays could do so much. It is good to know.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Mar 2012 16:34 Edited at: 23rd Mar 2012 16:35
Here is a suggestion, assuming only one sprite is selectable and using Marl's suggestion:


Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-23 05:01:57
Your offset time is: 2024-11-23 05:01:57