space shooter no display
BlitzMax Forums/BlitzMax Beginners Area/space shooter no display
| ||
im writting my own space shooter for a personal project. for some reason the graphics dont display. could it be something with the initialization?Global ste:String = "game" Global bkd:TImage =LoadImage("C:\Users\MONSTERBUZZ786\Downloads\1 (42).jpg") Global shipster:TImage = LoadImage("C:\ship.bmp") Const WIDTH = 640,HEIGHT = 480, DEPTH = 32 Graphics WIDTH,HEIGHT,DEPTH While Not KeyDown(KEY_ESCAPE) Select ste Case menu '/rend gui Case game If shipa:ship = Null Then ship.Create(shipa, shipster) '/network '/get input Global keys1:Int = KeyDown(KEY_LEFT) Global Keys2:Int = KeyDown(KEY_RIGHT) Global keys3:Int = KeyDown(KEY_UP) If shipa Then shipa.turn(Keys1, Keys2, Keys3, shipa) '/logic '/render backdrop TileImage(bkd, 0,0,0) DrawImage(shipster, 0, 0,0) '/render ship ship.render(shipa) '/render hud SetAlpha 1 SetColor 255,255,255 DrawText "Score:"+Score+" "+ballcount,2,2 '/capture screen shot Print("hello") If ste <> "game" Then cap:TImage = LoadImage("C:\ship.bmp") Case batt ste = "game" 'music Case dead shipa = Null ste = "game" '/rend gui 'music Case dbug '/rend gui End Select Wend Type ship Field x Field y Field ang Field vel Field wep Field eqp Field img:TImage Function Create(ships:ship, image:TImage) ships.img = image End Function Method turn(keys1, keys2, keys3, ships:ship) If keys1 Then ships.ang:-2 If keys2 Then ships.ang:+2 If keys3 Then ships.vel:+5 End Method Method move(ships:ship) If ships Then ships.x:+Sin(ships.ang * (ships.vel / 15)) If ships Then ships.y:+Cos(ships.ang * (ships.vel / 15)) If ships.vel Then ships.vel:-1 End Method Function render(ships:ship) DrawImage(ships.img, ships.x, ships.y, 0) End Function End Type |
| ||
I don't see Flip anywhere in the code. After doing all your rendering, you need to do Flip to switch the backbuffer to the front. |
| ||
A Cls will be nice too. I've also found (perhaps depending on the platform) that LoadImage() doesn't work very well before Graphics(). |
| ||
i was using flip but i get the error unhandled exception:attempt to acess field or method of null object, with my public function. how would you write this in blitzmax? Function Create(ships:ship, image:TImage) ships.img = image End Function ship.create(shipa:ship, image:timage) i want to have the function create the instance, from a type, and set its fields for the user. |
| ||
Your Create function could be something like :Function Create:ship(image:TImage) Local ships:ship = New ship ships.img = image Return ships End Function Note it is returning a new instance of ship. |
| ||
now when i use a statement to name the ship, i'm stuck with unable to convert from 'int' to 'ship'.If shipa:ship = Null Then shipa:ship = ship.Create(shipster) |
| ||
Like....?SuperStrict Graphics 640,480,32 ' // Images Global gfx_ship:TImage=LoadImage("path\to\image") '// Objects Global myShip:TShip = TShip.Create(gfx_ship,320,240) ' // ---------------------------------------------------- While Not KeyDown(KEY_ESCAPE) Cls myShip.Render myShip.Update Flip Wend ' // ---------------------------------------------------- ' // Ship Type Type TShip Field img:TImage Field x:Int Field y:Int Function Create:TShip(_img:TImage,_x:Int,_y:Int) Local a:TShip = New TShip a.img = _img a.x = _x a.y = _y Return a End Function Method Render:Int() DrawImage(img,x,y) End Method Method Update:Int() x=x+1 End Method End Type |
| ||
Try adding Strict or SuperStrict to the top of your program, and fix all the errors it complains about :-) "shipa" isn't declared anywhere. A non-strict program lets you do bad things like that - with unforeseen consequences (like the error you are currently seeing) |