Page 1 of 1

Sprite Structure

Posted: Sat Jun 02, 2012 10:14 pm
by Pot Noodle
Hi guys, I wonder if someone can help me here?

I am trying to create a sprite structure like so

Stucture Car
X.w
Y.w
Id.l
EndStructure

Dim Sprite.Car(9)
Global CurrentSprite = 5

This is the problem:
If Xpos < Sprite(CurrentSprite)\Id <--- I need the ID as well as the X, how is this done?

Thanks for your help in advance.

Re: Sprite Structure

Posted: Sat Jun 02, 2012 10:26 pm
by falsam

Code: Select all

Structure Car
  X.w
  Y.w
  Id.l
EndStructure

Dim Cars.Car(0)

For i=1 To 10
  ReDim Cars(i)
  Cars(i)\Id=i
  Cars(i)\X=i*10
Next

CurrentSprite = 5

Debug Cars(CurrentSprite)\Id
Debug Cars(CurrentSprite)\X

Re: Sprite Structure

Posted: Sat Jun 02, 2012 10:38 pm
by Pot Noodle
Structure Car
X.w
Y.w
Id.l
EndStructure

Dim Cars.Car(0)

For i=1 To 10
ReDim Cars(i)
Cars(i)\Id=i
Cars(i)\X=i*10
Next

CurrentSprite = 5

Debug Cars(CurrentSprite)\Id
Debug Cars(CurrentSprite)\X
I think you misunderstood me, what i want to do is
Retreve the X cord from a sprite so it should look something like this:

If Xpos < Sprite(Index)\ID\X

But I have 1 to 9 sprites so i use CurrentSprite to identify the sprite in the Array then I need the ID of the Sprite then I need the X Cord of the sprite and thats the problem!

Re: Sprite Structure

Posted: Sat Jun 02, 2012 11:03 pm
by STARGĂ…TE
a Sprite have not X-coordinate.

You must have your own structure like:

Code: Select all

Structure Sprite
  ID.i
  X.i
  Y.i
EndStructure

Structure Car
  *Sprite.Sprite
EndStructure
then you save in Car and read it:

Code: Select all

Sprite1.Sprite
Sprite1\ID = LoadSprite(...)
Sprite1\X = ...
MyCar.Car
MyCar\Sprite = @Sprite1
;....
If X < MyCar\Sprite\X

Re: Sprite Structure

Posted: Sat Jun 02, 2012 11:15 pm
by J. Baker
My AnimateSprite() procedure returns the frame number for sprite sheet.
http://www.purebasic.fr/english/viewtop ... 16#p284416

You might also look at this post for Data sprites...
http://www.purebasic.fr/english/viewtop ... 16&t=49979