• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Image Command help!

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
Linky
Asked:
Linky
  • 5
  • 3
  • 3
  • +1
1 Solution
 
Richie_SimonettiIT OperationsCommented:
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
 
Richie_SimonettiIT OperationsCommented:

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
 
andyclapCommented:
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
Industry Leaders: 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!

 
LinkyAuthor Commented:
What would be the best way to do this for a game?
0
 
Richie_SimonettiIT OperationsCommented:
Set statement isn't necessary.
0
 
rspahitzCommented:
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
 
rspahitzCommented:
(Actually, 11 images named Animate0.gif through Animate10.gif)
0
 
rspahitzCommented:
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
 
rspahitzCommented:
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
 
LinkyAuthor Commented:
Thanks all for the help...
0
 
LinkyAuthor Commented:
Thanks all for the help...
0
 
rspahitzCommented:
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

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!

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now