Solved

Image Command help!

Posted on 2001-09-18
12
146 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
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility

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
Comment Utility
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
 
LVL 2

Author Comment

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

Expert Comment

by:Richie_Simonetti
Comment Utility
Set statement isn't necessary.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 22

Expert Comment

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

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks all for the help...
0
 
LVL 2

Author Comment

by:Linky
Comment Utility
Thanks all for the help...
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now