Sprite Structure

Advanced game related topics
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Sprite Structure

Post 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.
P.N.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Sprite Structure

Post 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

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: Sprite Structure

Post 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!
P.N.
User avatar
STARGÅTE
Addict
Addict
Posts: 2265
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Sprite Structure

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Sprite Structure

Post 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
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply