Solved

Image Command help!

Posted on 2001-09-18
12
151 Views
Last Modified: 2010-05-02
In Visual Basic 6.0, I am trying to write a program to change what the content in the image box is to a different picture when I push a button (i.e. animate it) I have a list of *.bmps that I want to be called when I push a button in Visual basic (e.g. my game character walking animation). I know this sound confusing, but maybe somebody can help me.
0
Comment
Question by:Linky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491802
you could use Loadpicture function from within comman_click event.
Something like:

sub command1_click()
picture1.picture= loadpicture("c:\mypic.bmp")
'or
image1.picture= loadpicture("c:\mypic.bmp")
end sub

if you have more than one picture to load, i suggest you rename  those files to something like this:
mypic1.bmp
mypic2.bmp
mypic3.bmp
.... and so on

Then:

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491810

sub command1_click()
static idx as integer
' This code asumes that you have four bmps called mypic1.bmp
' to mypic4.bmp
idx=idx+1
if idx=5 then idx=1

picture1.picture= loadpicture("c:\mypic" & idx & ".bmp")
'or
image1.picture= loadpicture("c:\mypic" & idx & ".bmp")
end sub
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6491811
something like
set image1.picture=loadpicture("c:\mygame\character1.bmp")

Note that the image doesn't redraw until the next 'idle' moment, so you'll probably want to add
image1.refresh
after changing the image

Incidentally, this isn't the most efficient way of doing things for games, but it's certainly the easiest if speed isn't an issue.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Linky
ID: 6491840
What would be the best way to do this for a game?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491861
Set statement isn't necessary.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
ID: 6491936
It sounds like you want to create an animation which is activated by a button.

To do this, you probably want to use a timer to control the speed of the animation, so try this:

Private m_intImageCounter as integer

Private Sub Command1_Click()
   m_intImageCounter = 0
   Timer1.interval = 100' 1/10 second
   Timer1.enabled=true
End Sub

Private Sub Timer1_Timer()
   Picture1.Picture = LoadPicture(app.path & "images\Animate" & m_intImageCounter & ".gif")
   m_intImageCounter = m_intImageCounter + 1
   if m_intImageCounter > 10 then
      ' stop the timer after all (10?) images are displayed
      Timer1.Enabled = False
   end if
End Sub

'This assumes you have 10 images named Animate##.gif located in a subfolder 'images' located in your app's path
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491938
(Actually, 11 images named Animate0.gif through Animate10.gif)
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491939
Darn...you also need to convert m_intImageCounter to a string for the concatenation.  I usually use mid$(str$(m_intImageCounter),2), so:

...
Picture1.Picture = LoadPicture(app.path & "images\Animate" & mid$(str$(m_intImageCounter),2) & ".gif")
...
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491944
I'll get this right yet...add a "\" after the use of app.path:

Picture1.Picture = LoadPicture(app.path & "\images\Animate" & mid$(str$(m_intImageCounter),2) & ".gif")
0
 
LVL 2

Author Comment

by:Linky
ID: 6492039
Thanks all for the help...
0
 
LVL 2

Author Comment

by:Linky
ID: 6492041
Thanks all for the help...
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6492048
Glad to help...VB games can be fun, but be warned that using VB this way often leads to choppy animations, especially if you decide to use interacting images with collisions.  To do that, you may be better off with lower-level languages, or possibly API calls from VB.  Also, for large bitmaps, you may be better off using the BITBLT API function.

Anyway, have fun with it!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 52
Search combo error "Data Type Mismatch in Criteria Expression" 2 83
Can we place a tooltip on the actual vb6 form 5 53
TT Auto Dashboard 13 101
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question