| Mirage Source http://miragesource.net/forums/ |
|
| Optimizing drag function http://miragesource.net/forums/viewtopic.php?f=201&t=3439 |
Page 1 of 1 |
| Author: | Stomach Pulser [ Sun Mar 02, 2008 3:01 pm ] |
| Post subject: | Optimizing drag function |
Well, I am adding a custom top bar to my game (the bar at the top of everything with a minimize, maximize, and exit button). I am coding it myself and made this code to drag it. It occurs when you click on the label that is over the dragable part of the bar. x2 and y2 are integers to store the original location of the cursor (when the user clicks on the bar). Code: Private Sub lblDragBar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x2 = X y2 = Y End Sub Private Sub lblDragBar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Button Case 1 If x2 > X Then frmMirage.Left = frmMirage.Left + (X - x2) If x2 < X Then frmMirage.Left = frmMirage.Left - (x2 - X) If y2 > Y Then frmMirage.top = frmMirage.top + (Y - y2) If y2 < Y Then frmMirage.top = frmMirage.top - (y2 - Y) End Select End Sub Is there any way to optimize this? |
|
| Author: | James [ Sun Mar 02, 2008 11:39 pm ] |
| Post subject: | Re: Optimizing drag function |
you could do a with Me or with frmMirage and such, then where it has frmMirage.whatever just do .Left and .Right etc. Code: Private Sub lblDragBar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button Case 1 With frmMirage If x2 > X Then .Left = .Left + (X - x2) If x2 < X Then .Left = .Left - (x2 - X) If y2 > Y Then .top = .top + (Y - y2) If y2 < Y Then .top = .top - (y2 - Y) End With End Select End Sub |
|
| Author: | Anthony [ Mon Mar 03, 2008 12:13 am ] |
| Post subject: | Re: Optimizing drag function |
This is a good place for my question I have been wondering forever haha. Do With statements actually optimize anything? |
|
| Author: | Dr. Spoon [ Mon Mar 03, 2008 3:04 am ] |
| Post subject: | Re: Optimizing drag function |
simply yes in stead of evaluating/reading the <whatever> part multiple times it reads With <whatever> once and reuses what it read the first time |
|
| Author: | Stomach Pulser [ Mon Mar 03, 2008 3:30 am ] |
| Post subject: | Re: Optimizing drag function |
So this: Code: Public Sub ItemEditorInit() '**************************************************************** '* WHEN WHO WHAT '* ---- --- ---- '* 07/12/2005 Shannara Added gfx constant. '**************************************************************** frmItemEditor.picItems.Picture = LoadPicture(App.Path & GFX_PATH & "items" & GFX_EXT) frmItemEditor.txtName.Text = Trim(Item(EditorIndex).Name) frmItemEditor.scrlPic.Value = Item(EditorIndex).Pic frmItemEditor.cmbType.ListIndex = Item(EditorIndex).Type If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_WEAPON) And (frmItemEditor.cmbType.ListIndex <= ITEM_TYPE_SHIELD) Then frmItemEditor.fraEquipment.Visible = True frmItemEditor.scrlDurability.Value = Item(EditorIndex).Data1 frmItemEditor.scrlStrength.Value = Item(EditorIndex).Data2 Else frmItemEditor.fraEquipment.Visible = False End If If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex <= ITEM_TYPE_POTIONSUBSP) Then frmItemEditor.fraVitals.Visible = True frmItemEditor.scrlVitalMod.Value = Item(EditorIndex).Data1 Else frmItemEditor.fraVitals.Visible = False End If If (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_SPELL) Then frmItemEditor.fraSpell.Visible = True frmItemEditor.scrlSpell.Value = Item(EditorIndex).Data1 Else frmItemEditor.fraSpell.Visible = False End If frmItemEditor.Show vbModal could be optimized better? Along with most other initializations and such? |
|
| Author: | Dr. Spoon [ Mon Mar 03, 2008 3:54 am ] |
| Post subject: | Re: Optimizing drag function |
basically yes.. |
|
| Author: | Kousaten [ Fri Mar 07, 2008 11:07 pm ] |
| Post subject: | Re: Optimizing drag function |
Interesting. Any clue as to how much improvement we're looking at if one was to optimize all of the initializations with 'With'? |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|