Objects and Pointers

BlitzMax Forums/BlitzMax Beginners Area/Objects and Pointers

Hi quick question, in my current project I have a number of objects, each object contains the field

Field image:Timage.

which is the image data I use to draw the object. In the game each object uses 1 of 5 different images, so I am thinking rather than store the image data in each object I should be storing a pointer to the image data in each object?
Thanks

What you are doing is effectively storing a pointer. All Blitz types are pointers to structures, so you only have to load an image once and you can have thousands of objects referencing it.

ok I see. Thanks for the help

On the same kind of topic. Just tried out this code to explain something to myself:

Type TSquare
   Field test:TBall
EndType

Local square:TSquare
square= New TSquare

Type TBall
   Field one:Int
   Field two:Int
EndType

DebugStop
Local ball:Tball
ball = New tball
ball.one=3

square.test=ball
square.test.one=6


Am I right in thinking that square.test is a pointer to ball? As the line

square.test.one=6

changes the value of ball.one?

yes
Type TSquare
   Field test:TBall
EndType

Local square:TSquare
square= New TSquare

Type TBall
   Field one:Int
   Field two:Int
EndType

DebugStop
Local ball:Tball
ball = New tball
ball.one=3
print ball.one

square.test=ball
square.test.one=6
print ball.one

run this

Yip thought so. Cheers