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 / Creating Sprite with UDT ID

Author
Message
SageTech
19
Years of Service
User Offline
Joined: 3rd Dec 2004
Location: Orlando, Florida
Posted: 25th Jan 2012 04:19
I'm trying to use a UDT to manage all Player Sprite variables. I know that you can create a sprite like so:



However I am trying to use the UDT, Like this:



I get an error of "Sprite 0 does not exist at line 43 in root". What am I doing wrong?
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 25th Jan 2012 05:01
Type PlayerSpriteType
ID as Integer
X# as Float
Y# as Float
Health as Integer
EndType
Global PlayerSprite AS PlayerSpriteType

image = loadimage("myimage.png")

PlayerSprite.ID = createSprite(image)
greenlig
20
Years of Service
User Offline
Joined: 30th Aug 2003
Location: Melbourne
Posted: 25th Jan 2012 05:05
I found that if I don't cast the ID variable, it works fine.

This code should work.



Greenlig

Your signature has been erased by a mod as it is far too big.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 25th Jan 2012 05:21
What's at line 43? This typically isn't the error you'd get when making a sprite but when you're trying to use one. Check for typos, I've often been caught out on them.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Jan 2012 10:39 Edited at: 25th Jan 2012 10:40
I've had no problems casting ID variables as integers. It sounds like there's a syntax error in there somewhere to me as Hodgey suggested.

Can you post the first 43 preferably 50 lines (sometimes the IDE can't add up too well )?

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Jan 2012 15:29

This line is the problem.

Your trying to create a sprite with no image assigned. You need to pass a valid image number into the CreateSprite() function.

My signature is NOT a moderator plaything! Stop changing it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Jan 2012 15:31
No you don't. Using zero creates a blank / white sprite.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jan 2012 16:56
Quote: "Your trying to create a sprite with no image assigned"


Works perfectly well for me

SageTech
19
Years of Service
User Offline
Joined: 3rd Dec 2004
Location: Orlando, Florida
Posted: 25th Jan 2012 21:47
@BatVink

I'd Imagine so, I learned you could do it from the newsletter!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Jan 2012 15:44
Pah.

My signature is NOT a moderator plaything! Stop changing it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Jan 2012 16:06
It's quite a handy feature actually. I use blank sprites set the colour and alpha to black / semi-transparent and stick it behind a pop-up menu such as "Quit Game? Yes / No" and it is a cheap way to fade the background out (for example).

They are also great for making lines...

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Jan 2012 18:08
Quote: "It's quite a handy feature actually. I use blank sprites set the colour and alpha to black / semi-transparent and stick it behind a pop-up menu such as "Quit Game? Yes / No" and it is a cheap way to fade the background out (for example)."


Spooky, that's exactly how I use it! I'm just about to add colour values to my text/message system so I can overlay with different colours.

Login to post a reply

Server time is: 2024-04-25 10:20:29
Your offset time is: 2024-04-25 10:20:29