Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Game Programming (http://www.xtremevbtalk.com/-net-game-programming/)
-   -   Side scrolling code (http://www.xtremevbtalk.com/-net-game-programming/326672-scrolling-code.html)

Chazz85 12-15-2013 12:49 PM

Side scrolling code
 
Ok i'm planing to begin making a 2d rpg game for steam in in like 8months so i tried to get side scrolling working just to test . So i went on youtube and used a tutorial i fully understood what the code should do and how it functions. Then it didn't work the guy was using vb 2010 just like me and nothing i retyped it like 3 times. So if anyone here could spot a error or fix my code please help.

Code:
Public Class Form1 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'Starts right and left etc etc' Select Case e.KeyCode Case Keys.Right TimerRight.Enabled = True TimerLeft.Enabled = False Case Keys.Left TimerLeft.Enabled = True TimerRight.Enabled = False End Select End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp 'Allows movement to stop if key is released' Select Case e.KeyCode Case Keys.Right TimerRight.Enabled = False Case Keys.Left TimerLeft.Enabled = False End Select End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Disabled scroll bar' Me.AutoScroll = False End Sub Private Sub TimerRight_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerRight.Tick Dim Objects() As PictureBox = {Enemy1, Enemy2, Enemy3} For x = 0 To Objects.Length - 1 Objects(x).Left() -= 3 Next End Sub Private Sub TimerLeft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerLeft.Tick Dim Objects() As PictureBox = {Enemy1, Enemy2, Enemy3} For x = 0 To Objects.Length - 1 Objects(x).Left() += 3 Next End Sub

If it's in incorrect format sorry and thank you for your time.

passel 12-16-2013 10:13 AM

Do you have three pictureboxes named Enemy1, Enemy2 and Enemy3, and do they contain an image?

Chazz85 12-16-2013 11:29 AM

No they are just color blocks in this example all black

Gruff 12-16-2013 02:48 PM

When I pasted your code the Handles Statement at the end of the events did not paste.

After adding it things worked fine.

Also the KeyUp event seemed like overkill.
I used the following instead.
Code:
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp 'Allows movement to stop if key is released' TimerRight.Enabled = False TimerLeft.Enabled = False End Sub

Chazz85 12-17-2013 09:21 AM

Thanks for shortening the keydown event but i'm still having issues with this on pc and idk why.

Gruff 12-17-2013 09:44 AM

idk? (I don't know)

As I said the code ran and the picture boxes moved for me.
I have no idea what you are missing.

Chazz85 12-17-2013 11:03 AM

ok


All times are GMT -6. The time now is 11:48 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.