Solved

Image Command help!

Posted on 2001-09-18
12
150 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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