Post by sadsack on Aug 16, 2008 19:03:17 GMT -5
Hi,
Here is the code I am using to to move an object on the screen with the wsad keys.
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!
Here is the erroe I am getting.
Error 9
Error loading image file test.bmp
Error 9 in CreateFont: system
Key terminated
Graphics terminate
Is there a list of what the error are??
here is my test bmp
Thank you
renny
Here is the code I am using to to move an object on the screen with the wsad keys.
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!
Here is the erroe I am getting.
Error 9
Error loading image file test.bmp
Error 9 in CreateFont: system
Key terminated
Graphics terminate
Is there a list of what the error are??
here is my test bmp
Thank you
renny