Archived

This topic is now archived and is closed to further replies.

VB .net scale images wrongly!

This topic is 5245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've made the beginning of a game where you see a guy from a top-down perspective. So far the map is a matrix that consists of either Floor or Obstacle. I have made two 32x32 bitmaps for those tiles, and for the character too, of course. I load the character into a PictureBox, and he looks alright after I set the AutoSize property. But I draw the map directly from file to the form. Screenshot: http://forum.sweclockers.com/attachment.php?s=&postid=2007862 The code for randomizing the map and drawing it:

	Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
		randomize
		dim generator as Double
		dim i,j, MAPSIZE, hasPlayerPos as Integer
		MAPSIZE = 7
		dim map2(MAPSIZE, MAPSIZE) as String
		for j = 0 to MAPSIZE
			for i = 0 to MAPSIZE
				generator = Rnd()
				if generator < 0.3
					map2(i,j)="Obstacle"
				else
					if hasPlayerPos = 1
						map2(i,j)="Floor"
					else
						map2(i,j)="Player"
						hasPlayerPos = 1
					end if
				End If
				label1.Text += map2(i,j)
			next
			label1.Text += "|"
		next
		' --- START DRAWING MAP ---
		'Dim g1 As Graphics										
		'g1 = Me.CreateGraphics									
		'Dim beam As New Pen(Color.Red)							
		'g1.DrawLine(beam,1,1,34,24)
		Dim MyImage1 As Image
		Dim x as Int16
		for j = 0 to MAPSIZE
			for i = 0 to MAPSIZE
				if map2(i,j) <> "Player"
					myimage1 = Image.FromFile("C:\Documents and Settings\Anders\Mina dokument\anders\Visual Studio Projects\Tactics\" & map2(i,j) & ".bmp")
						
						e.Graphics.DrawImage(myimage1, new Point(i*myimage1.Width,j*myimage1.Height))
				end if
			Next
		Next
	End Sub


 
Obviously VB knows that the images are 32x32, since that is how far it "jumps" when drawing the tiles. However, for some reason it draws them too big so that they don't fit! ------------------ "Kaka e gott" - Me Current project: An RPG with tactical, real-time combat with a realistic damage system, and randomly generated world and dialogue. [edited by - Srekel on August 5, 2003 2:24:55 PM] [edited by - Srekel on August 5, 2003 2:26:34 PM]

Share this post


Link to post
Share on other sites
Nevermind, I solved it

There was an overloaded function that took four integers, where the last two were the height and width of the image.

I don''t know why I had to do it thought, I mean VB should''ve taken care of that by itself?

Share this post


Link to post
Share on other sites