How do i ? (Images)

Blitz3D Forums/Blitz3D Beginners Area/How do i ? (Images)

Iso(Posted 2004) [#1]
how do i make it so that an image moves left when you press left arrow,right when you press right ect? plz help


Iso(Posted 2004) [#2]
also is it possible to change the icon of the .exe?


Iso(Posted 2004) [#3]
lol, and alos how do i make it so if escape is pressed at anyy time during the game it ends?


semar(Posted 2004) [#4]
You usually use DrawImage command to draw the image on the screen.

DrawImage command has 4 parameters:
DrawImage image, x,y [,frame]

image = an handler which points to a loaded image that you want to display
x,y = the screen coordinates at where display such image
[,frame] = an optional parameter which indicates which frame to display - only for animated images.

Now, let's focus on the first three parameters - just use a simple one-frame image.

'Image' is the image handler; for example:
Global MyImage = LoadImage("C:\images\house.bmp")

"x,y" are the x and y coordinates. You have to declare it as well:
Global x = 0
Global y = 100

So now, when you have this statement:
Drawimage myimage,x,y

It will draw house.bmp image at x = 0 and y = 100

Now, let's make a very short example with a main loop (assuming you have an image located at "C:\images\house.bmp" :
Graphics 640,480,0,2
Global MyImage = LoadImage("C:\images\house.bmp")
Global x = 0
Global y = 100
while not keydown(1)
cls
drawimage myimage,x,y
flip
wend
end


What it does, it display the image until you press esc (the ESC key has a key code = 1, hence the statement KeyDown(1).

Now, can you guess what happens if you change the x value ? Try to put this statement in the main loop:
while not keydown(1)
x = x + 1
if x > 640 then 
x = 0
endif
;
;rest of previous code here

You see ? The image 'moves' to the right, because you change the x position - which is the horizontal position of the image on the screen - at each loop. When the x position is greater than the screen width (that we have set to 640 in the very first program statement), then the x value is reset to 0, so that the image re-enters from the left side.

Experiment with this. Try, for example, to modify dinamically also the y value, and make the image bouncing on the screen. You have to check for boundaries, like we do already with the x variable.

Later, add a control like:
if keydown(right_key_code) then
x = x + 1
endif

if keydown(left_key_code) then
x = x - 1
endif

Choose a key code for right and left direction, and you will notice that when you press that key, the image will be drawn at the new position.

By the way, if you want learn quickly:
- read the basics in the manual provided;
- learn the graphic statement descriptions in the manual;
- go through the examples provided, read the code, modify it to see the results.
- Read how each basic command work.
- Make some very simple program to see how to deal with input keys, graphics, sounds...
- there are some good tutorials here:
www.blitzcoder.com

also is it possible to change the icon of the .exe?
Use MicroAngelo or ResourceHacker. Or look here in the code archive, or at blitzcoder.

Have fun,
Sergio.