i have tryied about everything to get a picture to move in code using visual basic 6.0 i need help i would like to move unit(man) to move while to screen is centered on the picture but i cant seem to get it to rea the key down and key left and key right and key up buttons on key board please help to get it to work
10 5429
i have tryied about everything to get a picture to move in code using visual basic 6.0 i need help i would like to move unit(man) to move while to screen is centered on the picture but i cant seem to get it to rea the key down and key left and key right and key up buttons on key board please help to get it to work
have you tried with SELECT CASE and using VB constants in the KeyDown event?
e.g. - Select Case KeyCode
-
Case vbKeyDown
-
'[Code for moving down]
-
Case vbKeyUp
-
'[Code for moving up]
-
Case vbKeyLeft
-
'[Code for moving left]
-
Case vbKeyRight
-
'[Code for moving right]
-
End Select
HTH
OK. Go to the form , enter in the form code , select "ONE KEY DOWN" in the left upper corner and then write this:
DIm Up as KeyCodeConstants
up = vbKeyUp
If KeyCode = Up Then
PictureBox.Top = PictureBox.Top + 25
End If
And you can use otther values (+25 ; +30 ; - 30 and . . . . ) and you can define other buttons. And the program is finished . . . .
*VACE*
ive tried that but it dosnt move the picture1 anywhere if i can get it to mave and still have the screen centered on the picture ht all i neeed i the code im trying is this -
If e.KeyCode = Keys.Left Then
-
CharacterLocation.Offset(-1, 0)
-
ElseIf e.KeyCode = Keys.Up Then
-
CharacterLocation.Offset(0, -1)
-
ElseIf e.KeyCode = Keys.Right Then
-
CharacterLocation.Offset(1, 0)
-
ElseIf e.KeyCode = Keys.Down Then
-
CharacterLocation.Offset(0, 1)
-
End If
-
this is put into the keydown event but i wont move the picture anwhere
is their anyone who can help me please
Don't be impatient. The people here are scattered around the world (in different time zones) and volunteering what time they can spare to help others. It can take a while to get a response.
A few thoughts... - Can you please explain what you mean about "still have the screen centred on the picture"? If you mean this the way it sounds, then you would need to move the picture, and move the form in the opposite direction. Or perhaps physically move the monitor, but that's certainly outside the scope of this discussion.
- Since I'm not familiar with the version of VB you're using (I'm an old VB6 programmer) can you explain to me what CharacterLocation.Offset(0, 1) does? Does it actually change something (and is it the right "something?) or is it merely a function that returns a value (which you are ignoring)?
- If you're moving your picture one "twip" at a time, it will be a long time before you see any noticeable difference.
- Is the key detection working? At this point we don't know what is broken. Trace the execution and see whether it is going where you expect.
Im Sorry if im impatient im new to these online fourms and can be demmanding at times but all is good i forget the time to time the help people give out im trying not to sound rude but im sorry if i am im also new to programming and us to the real world fast pace get there get it and get back as quickly as posible and programming to me is like frogger with a 10 lane highway with cars going 75miles an hour ...... any who back to the topic all what the code does or ....... actully should do
is
I would like when i hit left keydown the picture moves left on the screen and when i hit right keydown picture moves right and up and down the samething
the charlocation doesnt mean anything if you have ever play Dragon warrior or any console game the char...... is always in the center of the screen no matter what thats what im trying to do hope that maks sence
So you don't want to move the picture at all, then. You want it to stay put, and everything else to move around it.
I think that we need much more detail on how you're putting this stuff on the display, and what is supposed to move and what isn't.
So far it's like taking one headlight in to a mechanic and asking him what's wrong with your car. Not enough info to work on.
Also, I'd still like you to answer my earlier questions. This is standard debugging practice - identify the problem before you try to correct it. Is the problem in the detection of the key, or the adjustment of the whatever-it-is-you're-adjusting, or in drawing your display?
i dont mean to be bothersome but al this is in 2005 express sorry about this i was woundering why the code wouldnt work sorry to wast your time but ill be glad to give you the code im working on -
-
Imports System.IO
-
-
Public Class TileTest
-
Inherits System.Windows.Forms.Form
-
-
#Region " Windows Form Designer generated code "
-
-
Public Sub New()
-
MyBase.New()
-
-
'This call is required by the Windows Form Designer.
-
InitializeComponent()
-
-
'Add any initialization after the InitializeComponent() call
-
-
End Sub
-
-
'Form overrides dispose to clean up the component list.
-
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
-
If disposing Then
-
If Not (components Is Nothing) Then
-
components.Dispose()
-
End If
-
End If
-
MyBase.Dispose(disposing)
-
End Sub
-
-
'Required by the Windows Form Designer
-
Private components As System.ComponentModel.IContainer
-
-
'NOTE: The following procedure is required by the Windows Form Designer
-
'It can be modified using the Windows Form Designer.
-
'Do not modify it using the code editor.
-
Friend WithEvents Clock As System.Windows.Forms.Timer
-
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
-
Me.components = New System.ComponentModel.Container
-
Me.Clock = New System.Windows.Forms.Timer(Me.components)
-
'
-
'Clock
-
'
-
'
-
'TileTest
-
'
-
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
-
Me.ClientSize = New System.Drawing.Size(440, 469)
-
Me.Name = "TileTest"
-
Me.Text = "Tile Map"
-
-
End Sub
-
-
#End Region
-
-
Dim Tileset As Bitmap 'Holds the tile pictures.
-
-
Dim Backup As Bitmap 'Backup picture holds the map that we've just drawn.
-
Dim GFX As Graphics 'Draws to the backup picture.
-
-
Dim FormGFX As Graphics 'Draws to the form.
-
-
Dim Map(,) As Integer 'The map is a 2D array of integers.
-
-
Dim Charpics(3) As Bitmap 'Hold each frame in one of the array elements.
-
Dim Cyc As Integer 'This number tells which frame to draw.
-
-
Dim CharacterLocation As Point
-
-
Const Tilesize As Integer = 143
-
Const NumofTilesBetweenCharacterAndScreenEdge As Integer = 3
-
-
-
Private Sub TileTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
-
Tileset = New Bitmap("tileset.bmp") 'Put the bitmap into the tileset picture.
-
-
Backup = New Bitmap(143 * 7, 143 * 7) 'Backup will be initialzed to an empty bitmap
-
-
GFX = Graphics.FromImage(Backup) 'GFX draws onto the backup picture.
-
FormGFX = Me.CreateGraphics() 'Draw to the form.
-
-
Dim SR As StreamReader = New StreamReader("map.txt")
-
Dim Ln As String
-
Dim LX, LY As Integer
-
Dim Chs As String
-
'The map in the file is now 24x24, so the array must be initialized as:
-
-
Map = New Integer(9, 9) {}
-
-
For LY = 0 To 9
-
Ln = SR.ReadLine() 'One row of tiles from the file.
-
-
For LX = 0 To 9 'Goes through each column.
-
-
Chs = Ln.Substring(LX, 1) 'Get a string with one character in it.
-
-
Map(LX, LY) = Integer.Parse(Chs) 'Convert this string into its matching number.
-
'"0" -> 0, "1" -> 1 ...
-
'The number is put into the map.
-
-
Next
-
-
Next
-
-
SR.Close()
-
-
CharacterLocation = New Point(3, 3)
-
-
Charpics(0) = New Bitmap("Shack.gif")
-
Charpics(1) = New Bitmap("Shack2.gif")
-
Charpics(2) = New Bitmap("Shack3.gif")
-
Charpics(3) = New Bitmap("Shack4.gif")
-
'Load each frame one by one into the array.
-
-
-
-
'Allow the keypresses to go directly to the form.
-
Me.KeyPreview = True
-
'Enable the clock.
-
Clock.Start()
-
-
Draw() 'Draw the map.
-
-
End Sub
-
-
Private Sub Draw() 'Draw map to the backup.
-
-
'The tileset contains 8 tiles, where each tile is 16 pixels wide.
-
'The map is 8x8 tilewise.
-
-
'Drawing the map requires nested for loops.
-
-
Dim LX, LY As Integer
-
Dim Thisindex As Integer 'The index of the map at the point LX,LY.
-
Dim Tile As Rectangle 'Holds the rectangle defining which tile we will draw.
-
-
Dim CamX, CamY As Integer
-
-
'Preface: The character will be 3 tiles away from both edges of the display.
-
'Therefore the width of the display will be 2 * 3 + 1... that's 7 tiles.
-
'The same applies to the vertical axis.
-
'The camera represents the tile that will be in the upper left corner of the screen.
-
If CharacterLocation.X - NumofTilesBetweenCharacterAndScreenEdge < 0 Then
-
CamX = 0 'This keeps the camera from going off of the left edge of the map.
-
ElseIf CharacterLocation.X + NumofTilesBetweenCharacterAndScreenEdge >= Map.GetUpperBound(0) Then
-
CamX = Map.GetUpperBound(0) - 2 * NumofTilesBetweenCharacterAndScreenEdge
-
'Same but for the right edge of the map.
-
Else
-
'The usual... camera remains 3 tiles away from the character, until the character moves near the edge of the map.
-
CamX = CharacterLocation.X - NumofTilesBetweenCharacterAndScreenEdge
-
End If
-
If CharacterLocation.Y - NumofTilesBetweenCharacterAndScreenEdge < 0 Then
-
CamY = 0
-
ElseIf CharacterLocation.Y + NumofTilesBetweenCharacterAndScreenEdge >= Map.GetUpperBound(1) Then
-
CamY = Map.GetUpperBound(1) - 2 * NumofTilesBetweenCharacterAndScreenEdge
-
Else
-
CamY = CharacterLocation.Y - NumofTilesBetweenCharacterAndScreenEdge
-
End If
-
-
For LY = 0 To NumofTilesBetweenCharacterAndScreenEdge + NumofTilesBetweenCharacterAndScreenEdge
-
For LX = 0 To NumofTilesBetweenCharacterAndScreenEdge + NumofTilesBetweenCharacterAndScreenEdge
-
-
Thisindex = Map(CamX + LX, CamY + LY)
-
'Get the index from the map.
-
'Since the camera changes, we need to extract the tiles from a different location in the map.
-
'Everything else is drawing the tile we give it, so it doesn't change.
-
-
Tile = New Rectangle(Thisindex * Tilesize, 0, Tilesize, Tilesize)
-
'Get the rectangle defining the tile.
-
-
GFX.DrawImage(Tileset, LX * Tilesize, LY * Tilesize, Tile, GraphicsUnit.Pixel)
-
'And then draw the tile onto the backup.
-
-
Next
-
Next
-
-
-
'Map code.
-
GFX.DrawImage(Charpics(Cyc), (CharacterLocation.X - CamX) * 143, (CharacterLocation.Y - CamY) * 143)
-
'Draw the character to the display at the location... this also changes depending on the camera location, so
-
'the camera location is subtracted from the character location.
-
-
'At this point the whole map should reside on the backup bitmap. The bitmap is not visible, so it must be made visible.
-
FormGFX.DrawImage(Backup, Me.ClientRectangle())
-
-
-
-
End Sub
-
-
-
-
Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
-
Cyc = (Cyc + 1) Mod 4 'Cyc cycles through 0, 1, 2, 3, 0, 1, 2, 3, 0, 1 ...
-
Draw() 'Draw.
-
End Sub
-
-
Private Sub TileTest_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
-
'FormGFX.SetClip(Me.ClientRectangle)
-
FormGFX.DrawImage(Backup, Me.ClientRectangle())
-
-
End Sub
-
-
Private Sub TileTest_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
-
-
Dim Collided As Boolean
-
-
'This is the basic movement. Collision detection always comes after this movement caused by the user.
-
If e.KeyCode = Keys.Left Then
-
CharacterLocation.Offset(-1, 0)
-
ElseIf e.KeyCode = Keys.Up Then
-
CharacterLocation.Offset(0, -1)
-
ElseIf e.KeyCode = Keys.Right Then
-
CharacterLocation.Offset(1, 0)
-
ElseIf e.KeyCode = Keys.Down Then
-
CharacterLocation.Offset(0, 1)
-
End If
-
-
'Check for collisions after moving the character.
-
If CharacterLocation.X < 0 OrElse CharacterLocation.X > Map.GetUpperBound(0) OrElse CharacterLocation.Y < 0 OrElse CharacterLocation.Y > Map.GetUpperBound(1) Then
-
Collided = True
-
ElseIf Map(CharacterLocation.X, CharacterLocation.Y) = 9 Then
-
Collided = True
-
-
End If
-
-
'If we have collded, then the character needs to move back immediately.
-
If Collided Then
-
'Take all of the keycodes and reverse their operation.
-
If e.KeyCode = Keys.Left Then
-
CharacterLocation.Offset(1, 0)
-
ElseIf e.KeyCode = Keys.Up Then
-
CharacterLocation.Offset(0, 1)
-
ElseIf e.KeyCode = Keys.Right Then
-
CharacterLocation.Offset(-1, 0)
-
ElseIf e.KeyCode = Keys.Down Then
-
CharacterLocation.Offset(0, -1)
-
End If
-
-
End If
-
-
-
-
-
-
'Check for collisions after moving the character.
-
If CharacterLocation.X < 0 OrElse CharacterLocation.X > Map.GetUpperBound(0) OrElse CharacterLocation.Y < 0 OrElse CharacterLocation.Y > Map.GetUpperBound(1) Then
-
Collided = True
-
ElseIf Map(CharacterLocation.X, CharacterLocation.Y) = 9 Then
-
Collided = True
-
-
End If
-
-
'Note that the keydown event can fire more than once over the 100 ms that the timer is not drawing.
-
End Sub
-
End Class
-
-
-
-
wow thats some serious code guys! :D
im in year 10 and iv been playin around with vb
im using vb2008 but this is how i move a picture box:
picturebox1.left = picturebox1.left + 5
picturebox1.top = picturebox1.top +5
i dont know if thats a help but i thought i may as well pitch in and give it a shot :D
wow thats some serious code guys! :D
im in year 10 and iv been playin around with vb
Thanks for that vincey92.
I'm not sure it is particularly helpful in this case, but don't let that discourage you. We definitely need people to pitch in. There are too few who bother. This sort of forum works best as a discussion where everyone contributes what they can.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bardo |
last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to
reconize the arrow keys. But I have no luck at all. The problem is that the
keydown event won't fire at all, unless I...
|
by: Tony |
last post by:
I'm building a simple "breakout" style video-game, and I want keyboard
control of the paddle.
What I need is for an event handler to respond whenever a key is pressed,
regardless of what the...
|
by: Rasika WIJAYARATNE |
last post by:
I have a form with a KeyDown event handler method attached to it. It
has three text boxes and two buttons (buttons are attached to event
handler). However when I debug, the form opens with the...
|
by: Anne |
last post by:
hie again, i have 3 textbox and i would like the user to
go to the next textbox by pressing the 'ENTER' key. i have
tried using this:
Private Sub txtRequestor_KeyDown(ByVal sender As...
|
by: fripper |
last post by:
I have a VB 2005 windows app and I want to recognize keydown events. I have
a form key down event handler but it does not get control when a key is
depressed. In playing around I found that if I...
|
by: velasquez.m |
last post by:
i'm working with visual studio 2005 and have a solution with 16
projects in it.
this specific application has a base form with other forms added to it
at any area of the application that the...
|
by: MLM450 |
last post by:
I have a control that handles the KeyDown event but it does not seem to
execute when a combination of keys is pressed - like CTRL+Z. If I
press CTRL, it executes. If I press Z, it executes. But the...
|
by: win |
last post by:
when the cursor is in a textbox, only coding in the keydown event of the
textbox triggered, the coding in the keydown event of the form does not
triggered!
Problem: I need to change a VB6 program...
|
by: sush_jd via DotNetMonster.com |
last post by:
I am using managed VC++ code in a Win Form App. There is a text box -
txtRONumber. I have defined a KeyDown event handler (non-default) for it,
like below. InitializeComponent() is being called...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |