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 / What value does an array assign to a sprite?

Author
Message
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 28th May 2012 05:27
I made an array and set it to 5

for i = 1 to 5

I then delete every sprite with an id above 5. I wasn't expecting anything to be deleted. However it deleted every sprite even the first five. I have the array in the main loop. So what id is given to the sprite in this case?
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th May 2012 10:47
AGK auto assigns Sprite ID's from 10000. So unless you are assigning Sprite ID's manually all Sprite ID's would be > 5.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th May 2012 12:14
Firstly, we need to know how you created each sprite as there are two ways in AGK. If you used the method where the sprite number is generated for you then, as Funnell7 said, it's very likely that the number will be higher than 5. I actually think it counts backwards from 10,000 but don't quote me on that.

We may need to see some code to be of more help.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th May 2012 12:19 Edited at: 28th May 2012 12:21
Quote: "AGK auto assigns Sprite ID's from 10000. So unless you are assigning Sprite ID's manually all Sprite ID's would be > 5."

This is not quite true.

There are two methods of assigning sprite ID's. The first is automatic:
spriteID = createSprite(imageID)

An ID over 10000 will be assigned to the spriteID variable, this ID could also be assigned to an array:
array[number] = createSprite(imageID)

The second method is hard coded:
createSprite(1,imageID)

This creates a sprite with an ID of "1" but of course any number can be used.

Generally it is better practice to assign an automatic ID and track ID's correctly in your code but if you have a simple game you might find it easier to use hard coded values for simplicity in reading your code.

EDIT: Ninja'd by Hodgey!! I've been away too long

EDIT2: Actually Hodgey the values go up from 10000

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th May 2012 12:34
Quote: "Quote: "AGK auto assigns Sprite ID's from 10000. So unless you are assigning Sprite ID's manually all Sprite ID's would be > 5."
This is not quite true."


I'm confused... If you do this:



The Sprite ID's are 10001, 10002, 10003, 10004, and 10005. Which have been created automatically by AGK. Doing this:



Is manually assigning the Sprite with an ID of 1.

Don't get me wrong, I'm not trying to challenge you in anyway Bax, its just that when I'm not right, I like to make sure I know why so that I can learn from it... This is still all very new to me...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th May 2012 12:38
Erk, I misread your post. You are right completely

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th May 2012 12:50
Quote: "Erk, I misread your post. You are right completely"


Ha, no problem, still recovering from the Hackathon no doubt! Very well done by the way!!

Thanks Bax...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th May 2012 12:52
Quote: "Ha, no problem, still recovering from the Hackathon no doubt! Very well done by the way!!"

Maybe yes! I have also come down with a horrible cold. I got off the train yesterday and got into a taxi, I couldn't speak to tell the driver where to take me for about 30 seconds... I think he thought I'd forgotten where I lived. My voice just quit on me!

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th May 2012 13:01
Quote: "Maybe yes! I have also come down with a horrible cold. I got off the train yesterday and got into a taxi, I couldn't speak to tell the driver where to take me for about 30 seconds... I think he thought I'd forgotten where I lived. My voice just quit on me!"


Damn... I hope you get better soon pal...
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th May 2012 13:03
Quote: "Actually Hodgey the values go up from 10000"

It's been a while since I've printed sprite numbers. DBPro, good times.

Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 28th May 2012 17:19
Thanks guys. I feel stupid. i could have just printed the id. D'oh!
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jun 2012 14:12
@Funnell7


I really have no idea what this code would do.

It is creating sprites using the array's initial contents as the image reference and arrays initially have "undefined" contents - though probably zero.

Just sayin'
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Jun 2012 14:28
Quote: "I really have no idea what this code would do."

If the value is > 0 then it's highly likely that it will give you an "Image doesn't exist" error or something of the sort. If the value is equal to 0 though then it'll just create a bunch of blank sprites. At least, that's what I think will happen.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jun 2012 14:29
Quote: "If the value is > 0 then it's highly likely that it will give you an "Image doesn't exist" error or something of the sort. If the value is equal to 0 though then it'll just create a bunch of blank sprites. At least, that's what I think will happen."

That's right, unless by some miracle there happen to be five existing image numbers assigned to the array

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Jun 2012 14:33
Quote: "unless by some miracle there happen to be five existing image numbers assigned to the array"



Seems like a miracle to me.

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 1st Jun 2012 16:31
Ok, I'll be honest, I'm not entirely sure what you guys are talking about ha (this is still new to me)... But I do this:



Quite alot... Especially when creating an animation. For example, when creating an animation, I end up with this:



Not sure if this is technically correct or not, but I guess I'm setting up a Sprite ID first, and then adding their respective images?...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jun 2012 16:42
What you should be doing is passing the image number in like this:
imageID = loadImage("MyImage.png")
spriteID = createSprite(imageID)

or even:
spriteID = createSprite(loadImage("MyImage.png"))

The way you are currently doing it might well work until "Sprite" contains a number of an image that doesn't exist.

Login to post a reply

Server time is: 2024-11-23 14:01:46
Your offset time is: 2024-11-23 14:01:46