Create Image query

BlitzPlus Forums/BlitzPlus Beginners Area/Create Image query

Siopses(Posted 2007) [#1]
I'm curious how you can put a CreateImage in a type without
making the CreateImage Global. Should I merely put the image in a bank, then PeekInt for it when I require it in
the type.
For Example:
Graphics 640,480
gamebank=CreateBank(12)
PokeInt gamebank,0,Rect(MouseX,MouseY,50,100,1)=bat=CreateImage(50,100,0)
PokeInt gamebank,4,Oval(ball\x,ball\y,20,20,0)=ball=CreateImage(20,20,0)
PokeInt gamebank,8,Rect(enemy\x,enemy\y,50,100,0)=bat2=CreateImage(50,100,0)
;Types
Type Player
	Field x,y,bat
End Type
bat1=New Player
bat1\x=MouseX
bat1\y=MouseY
bat1\bat=PeekInt(gamebank,0)
Type Enemy
	Field x,y,bat2
End Type
antagonist=New Enemy
antagonist\x=500
antagonist\y=240
antagonist\bat2=PeekInt(gamebank,4)
Type ball
	Field x,y,ball
End Type
bally=New ball
bally\x=320
bally\y=240
bally\ball=PeekInt(gamebank,8)

Did I do this right?


b32(Posted 2007) [#2]
Yes, I believe this should work, however, not in this context. But using a bank like this should be possible.
An alternative would be making a Type called Image, and destroy it after using it.


Siopses(Posted 2007) [#3]
What d'you mean? You mean for example, create the
image inside the type?


b32(Posted 2007) [#4]
Yes, however it is just another way of doing the same.
So you can use a type to store the images until you've created all players/enemies etc. After that, this type can be released.
But it doesn't really matter which method you choose, I suppose. The bank thing should work the same.
The advantage of using Banks is that they can be passed as a parameter to the function. Then again, with Types, the functions don't need a parameter, because you can find the images with First/Last/Before/After/For Each from within the function.