Hm...
Shouldn't there be a page on movement?
— Hartnell
Shouldn't there be a page on movement?
— Hartnell
Hi,
I tryed to make this movement code to work. Here is the code.
key.initialize 'Initalize keys, without keys we wouldn't be able to exit the game loop causing B2D to crash (save often, it sucks to forget this)
class ImageSprite
public x
public y
public image
public speed
function Move()
if Key.Pressed(vk_W) then 'Move up
y = y - speed
end if
if Key.Pressed(vk_S) then 'Move down
y = y + speed
end if
if Key.Pressed(vk_A) then 'Move left
x = x - speed
end if
if Key.Pressed(vk_D) then 'Move right
x = x + speed
end if
end function
end class
dim Sprite 'Create a new variable named imageFile
Set Sprite = new ImageSprite
Sprite.speed = .5
Sprite.x = 200
Sprite.y = 200
Sprite.image = graphics.loadImage("test.bmp") 'We're settings the imageFile variable to the test.png image
dim font
font = graphics.CreateFont("system",15,true)
Do While not Key.Pressed(vk_escape) and not Key.Pressed(vk_windowx)
'If you don't press escape and don't press the window's X button (top right) it will loop
Sprite.Move
graphics.SetXY Sprite.image , Sprite.x , Sprite.y 'Set its X and Y to the Sprite's x and y
graphics.Clear 'Anything between this and .Display is drawn
graphics.setImage(Sprite.image) 'Draw sprite
graphics.SetText "(" & Sprite.x & " , " & Sprite.y & ")", 10, 10, font 'Output the X and Y
graphics.SetText "Use WASD to move the block", 10, 30, font 'Instructions
graphics.Display 'Finish it up
loop 'Needed for the loop to work
key.terminate 'Destroy the key object
graphics.terminate 'Destroy the graphics object... We're done!
this is the error I get
Error 9
Error loading image file test.bmp
Error 9 in CreateFont: system
Key terminated
Graphics terminated
What is erroe 9???
Is there a place I can goto that have all the error listed???
renny
Hey. You need to initialize the graphics object too, before you use it:
graphics.initialize
You can optionally add parameters for the window size, and if it should run full-screen or not. Check the documentation for more info :)