Not able to load image file

BlitzMax Forums/BlitzMax Beginners Area/Not able to load image file

I do know that the Alien Ship is not loading the image and I trying to load the Alien image on the screen.

What I am doing wrong?

SuperStrict

' -----------------------TYPES-----------------------------
Type ShipType
     Field  X:Int,Y:Int=500            'For Player
     Field  Image:TImage
     Field  Speed:Int =5               'Speed for Player
     Field  BX:Int,BY:Int=450          'Bullets
     Field  EX:Int,EY:Int              'Enemys - not done yet

     Function Create:ShipType(File:String,xstart:Int,ystart:Int)
        Local Ship:ShipType = New ShipType
        Ship.X=xstart
        Ship.Y=ystart
        Ship.Image=LoadImage(file)
        If Ship.Image=Null
           Print "Not able to load image file. Program aborting"
           End
        EndIf
        Return Ship
     End Function

     Method Draw()
            DrawImage Image,X,Y
     End Method

     Method Move()
            If KeyDown(Key_Right) Then X:+Speed
            If KeyDown(Key_Left)  Then X:-Speed
           'If KeyDown(Key_Up)    Then Y:-Speed
           'If KeyDown(Key_Down)  Then Y:+Speed

            ' Collisions for Wall on each side to stop
            ' Player going off the playing area!
            If X<0   Then X=0
            If X>770 Then X=770
     End Method
End Type

Type TAlienShip
    Field X:Int = 320
    Field Y:Int = 0
    Field Speed:Int=3
    Field Image:TImage

    Function Create:TAlienShip(File:String,xstart:Int,ystart:Int)
        Local Alien:TAlienShip=New TAlienShip
        Alien.X=xstart
        Alien.Y=ystart
        Alien.Image=LoadImage(LoadBank(File))

       If Alien.Image=Null
           Print "Not able to load image file. Program aborting"
           End
       EndIf
       
        Return Alien
    End Function

    Method UpdateState()
        X :- Speed
        If X<-ImageWidth(Image) Then X=620
   End Method

   Method DrawSelf()
        DrawImage Image,X,Y
    End Method    

End Type

Local myShip:ShipType  = ShipType.Create("gfx/blobship.png",400,300)
Local Alien:TAlienShip = TAlienShip.Create("Gfx/cartoonufo_1-1.png",320,0)

' ---------------SETUP GAME CONDITION---------------
Graphics 800, 600, 0
HideMouse

' ---------------------MAIN LOOP-------------------------
While Not KeyDown(Key_Escape)
      Cls
      myShip.Draw
      myShip.Move
      Alien.UpdateState()
      Alien.DrawSelf()
      Flip
Wend



What are you trying to achieve with 'Alien.Image=LoadImage(LoadBank(File))' in your create function?

The Ship image work when load image but I cant understand why the Alien image doesnt load....

oh duhhh silly me...I just notice no Alien image in my GFX Folder..

So, bmax allows images to be loaded from banks? Interesting.

You can also load a file into a bank, then into a bankstream; manipulate the data in memory then output it again - instead of saving directly to the file.

For a recent project, I used a bankstream to write to the memory (instead of writing a temporary file, where the unencrypted data could be captured more easily), then output it (after encryption) to a file.