Oke, i've tested some simple things with prototype, but cannot get what i need, probally there is a way
First of all:
I Cannot create a new file, added to the project with a prototype definition and functions included, i get errors. Looks like the functions need to be beneath the mainloop. Putting both, PROTOTYPE and the according functions in a second file in the project, causes errors.
Second, most important:
The code be beneath does not work , because i cannot call the player.x and player.y within the function ShowPlayer or is there a way to do so ? It would be nice when we could make a call like this.x , this.y etc. (see code for example) the ShowPlayer is the most interesting!
Third:
Can't i return a TYPE from a function like newobject = functionname() <= then the function will create a global new object (prototype) and return this into a var as object, easier to handle
Hope it's clear a bit, cheers.
First of all:
I Cannot create a new file, added to the project with a prototype definition and functions included, i get errors. Looks like the functions need to be beneath the mainloop. Putting both, PROTOTYPE and the according functions in a second file in the project, causes errors.
Second, most important:
The code be beneath does not work , because i cannot call the player.x and player.y within the function ShowPlayer or is there a way to do so ? It would be nice when we could make a call like this.x , this.y etc. (see code for example) the ShowPlayer is the most interesting!
Third:
Can't i return a TYPE from a function like newobject = functionname() <= then the function will create a global new object (prototype) and return this into a var as object, easier to handle
Code (glbasic) Select
// PROTOTYPE SOME FUNCTIONS AND PROPERTYS //
PROTOTYPE sInit: x, y, filename$
PROTOTYPE sShow:
TYPE TPlayer
x
y
spriteid
Init AS sInit = InitPlayer
Show AS sShow = ShowPlayer
ENDTYPE
// INIT TPLAYER / GAME LOADING ETC //
GLOBAL player AS TPlayer
player.Init(0,0,"Media/grossini.png")
// MAIN LOOP //
WHILE TRUE
player.x = 0
player.y = 100
player.Show()
SHOWSCREEN
WEND
// END MAINLOOP //
// PROTOTYPE FUNCTIONS / METHODS //
FUNCTION InitPlayer: px, py, filename$
sprnum% = GENSPRITE()
LOADSPRITE filename$,sprnum%
player.spriteid = sprnum%
ENDFUNCTION // INITPLAYER
FUNCTION ShowPlayer:
DRAWSPRITE [ thisobject.spriteid],[thisobject.x],[thisobject.y]
ENDFUNCTION
Hope it's clear a bit, cheers.