Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image

Status
Not open for further replies.

21091958

Programmer
Aug 21, 2005
20
GB

diceRoll.Image = Image.FromFile("D:\MYGAME\dice1.jpg")

The image is situated in the folder of the game
I am using this code 6 times to represent a dice rolling.
Problem, every time the game is played on a different machine, the path to the images needs to be changed, how can i get around this one. I want to burn it on a cd, and give to a few friends to test, but this needs to be resolved first.
Cheers
 
Can you explain a bit please, I am a kind of lost here
thank you
 
Code:
diceRoll.Image = Image.FromFile(application.startuppath & "dice1.jpg")

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
You can use it like this:
Code:
diceRoll.Image = Image.FromFile(application.ExecutablePath.substring(0,application.ExecutablePath.lastindexof("\")) & "\dice1.jpg")

application.ExecutablePath will return "D:\MyGame\MyApp.exe"
Using substring(0,application.ExecutablePath.lastindexof("\")) will return "D:\MyGame"

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I have tried both codes and their return returns an error exception at run time, it crashes after the first roll of the dice. The property of image image is set to embedded resource?

Private Sub tmrStart_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrStart.Tick
Randomize()
Dice = CInt(6 * Rnd()) Mod 6 + 1 ' just to be sure it is in the interval 1-6
diceRoll.Image = Image.FromFile(Application.ExecutablePath.Substring(0,
Case 1
diceRoll.Image = Image.FromFile(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\")) & "\dice1.jpg")

this 6 times altogether.
 
Why not put the 6 images for your die in an ImageList?

You can then reference the image you require by the ImageList Index, remember of course that the ImageList is ZERO based so your code will need to be something like:

Code:
diceRoll.Image = ImageList1.Images(Dice -1)
 
Tekhed's idea would probrably be the easiest. Unless you want people to be able to provide their own dice skins. Just stick an image list on your form and add the images to it. Then reference the images from it in code. that way its entirely embedded, no worrying about paths.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
If you want to allow the user to specify their own skins for the die, then you simply need to create a 2nd ImageList on the fly and get the user to add the images that they wish to use.

You will need to write a function that will bind the images to the list, validate that they have selected 6 images, and ensure that each image is correctly associated with the number 'thrown'..

I would also write the paths of the images into the machine registry (or you can write a .DAT file in the application dir or something like that) so that when the app was launched again the custom images can be automatically loaded.
 
Thank you it works perfect but for one thing, there is always a but, I have lost the effect of the dice rolling( displaying the different sides of the dice), now the image of one side of the dice is displayed and stay still
If i use a text box i can see the value of the dice changing
 
I've set up a Label control with an ImageList (size of both set to 32*32) and a Timer (Interval set to 50)

The following seems to work:

Code:
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Timer1.Enabled = Not Timer1.Enabled

  End Sub

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Label1.ImageIndex = CInt(6 * Rnd()) Mod 6

  End Sub

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top