[Blitzmax] Problem to print multiple images

Discussion in 'Game Development (Technical)' started by Sogeking_87, Jan 6, 2014.

  1. Sogeking_87

    Sogeking_87 New Member

    Joined:
    Jan 6, 2014
    Messages:
    1
    Likes Received:
    0
    Hi all, i'm a newbie of game programming.
    I started with Blitzmax Language but i encountered an hard problem that affects all game i start to code.
    Multiple objects cant share the same image. If i create a list of objects, and each object of the list use the function loadimage on a path. Only the last item of the list can print that image. I will post an example of my problem.

    Code:
    Graphics 800,600
    
    Type rospo 
    Global x:Int
    Global y:Int
    Global image:TImage
    Method newros() image=LoadImage("pascal.bmp") EndMethod
    Method draw() DrawImage(image,x,y) EndMethod
    End Type
    
    Global R:rospo [19]
    
    Cls
    
    For Local i=0 To 18
    	R[i] = New rospo
    	R[i].x = Rand(2,798)
    	R[i].y = Rand(2,598)	
    	R[i].newros()
    Next
    
    For Local ii=0 To 18
    	R[ii].draw()
    Next
    
    Flip
    
    While Not KeyDown(Key_enter)
    	
    Wend	
    
    I know this is not a list but the problem is the same...
    Why i see only one image instead of 19 ????

    Help me pls!!!
     
  2. bantamcitygames

    Administrator Original Member Indie Author Greenlit

    Joined:
    Jul 27, 2004
    Messages:
    1,731
    Likes Received:
    78
    I don't know Blitzmax, so I just checked their docs quickly and I think instead of Global, you should be declaring your members has Field inside your rospo Type.
     
  3. Desktop Gaming

    Moderator Original Member Indie Author

    Joined:
    Feb 24, 2005
    Messages:
    2,296
    Likes Received:
    12
    Bruno is correct - kind of. However, doing it that way will result in 19 copies of the same image being loaded, which is horribly wasteful when all of the images are the same.

    Code:
    Strict
    
    Graphics 800, 600
    
    rospo.Init()
    
    Type rospo 
    	Field x:Int
    	Field y:Int
    	
    	Global image:TImage
    	
    	Function Init()
    		image = LoadImage("pascal.bmp")
    	End Function
    	
    	Method Draw()
    		DrawImage(image, x, y)
    	EndMethod
    End Type
    
    Global R:rospo [19]
    
    Cls
    
    For Local i=0 To 18
    	R[i] = New rospo
    	R[i].x = Rand(2,798)
    	R[i].y = Rand(2,598)	
    Next
    
    For Local ii=0 To 18
    	R[ii].draw()
    Next
    
    Flip
    
    While Not KeyDown(Key_enter)
    	
    Wend
    Methods and Fields belong to instances of types, while Functions and Globals belong to the Type/Class itself.
     
  4. bantamcitygames

    Administrator Original Member Indie Author Greenlit

    Joined:
    Jul 27, 2004
    Messages:
    1,731
    Likes Received:
    78
    Ahhh... that makes sense
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer