canvas size limitation

BlitzMax Forums/BlitzMax Beginners Area/canvas size limitation

Hi.
My game use 1024x768 resolution.
I've coded an game-editor to place some ennemies ships on a canvas. Next i save their positions. In the editor, With a 1024x768 window, i can't fix the canvas size more than 1024x768 pixels. This is a problem to position some ennemies outside this zone (in my game, a space shooter, a lot of ennemies come from outside the screen)

The following code, is an example, in my game editor i can't use a pixmap : i use a lot of max2d commands as Drawline, drawimage, to position things on the canvas.

Is there another solution than use a 1152x864 window !?!

Thanks !

Strict

Const WWX = 1024
Const WWY = 768

Global Win:TGadget=CreateWindow("",0,0,WWX,WWY, Null,WINDOW_TITLEBAR)
Global Panel:TGadget=CreatePanel (0,0,WWX-40,WWY-80,Win)
Global Canvas:TGadget=CreateCanvas (0,0,WWX,WWY,Panel)
Global sh:TGadget = CreateSlider(0,WWY-80, WWX-40,20,Win, SLIDER_HORIZONTAL)
Global sv:TGadget = CreateSlider(WWX-40,0,20,WWY-80,Win, SLIDER_VERTICAL)	

SetSliderRange sh , ClientWidth(panel) , GadgetWidth(Canvas) 
SetSliderRange sv, ClientHeight(panel) , GadgetHeight(Canvas)

SetSliderValue sv, 0
SetSliderValue sh , 0

Global Ennemies_list : TList = CreateList()

Type TEnnemi
	
	Field x
	Field y
	
	Function Create:TEnnemi(x:Int , y:Int)
		
		Local e:TEnnemi = New TEnnemi
		
		e.x = x
		e.y = y
		
		ListAddLast Ennemies_list , e
		
		Return e
		
	End Function
	
	Function Draw_all ()
		
		For Local e:TEnnemi = EachIn Ennemies_list
			SetColor 255 , 255 , 0
			DrawOval e.x-3,e.y-3,6,6
		Next
		
	End Function
	
End Type

Function Draw_canvas()
	
		SetGraphics CanvasGraphics(canvas)
		Cls
		
		SetGadgetShape Canvas, -SliderValue(sh), -SliderValue(sv), GadgetWidth(Canvas), GadgetHeight(Canvas)
		
		SetColor 0,40,0
		For Local i=0 To GadgetWidth (Canvas) Step 32
			DrawLine i,0,i,GadgetHeight(Canvas)
		Next
		
		SetColor 0 , 40 , 0
		For Local i=0 To GadgetHeight (Canvas) Step 32
			DrawLine 0,i,GadgetWidth(Canvas),i
		Next
		
		TEnnemi.Draw_all()		
		
		Flip
			
End Function

Global paintTimer:TTimer=CreateTimer(75)


Repeat
WaitEvent()

	Select EventID()
	
	Case EVENT_TIMERTICK
	
		Draw_canvas()
		
	Case EVENT_MOUSEDOWN
	
		TEnnemi.Create (EventX(), EventY())
		
	Case EVENT_WINDOWCLOSE
		
		FreeGadget canvas
		End
		
	End Select

Forever


Saving the things with types internally and draw all stuff that is within the current "view rect" which bases on a virtual position an a virtually unlimited canvas.

You don't need a 10000x10000 canvas ... it must only be virtually that large -> works similar to a regular tile system with "draw whats within screen"

As Dreamora said.

Use a virtal "Viewport" and only draw items/enemies inside it. The canvas size itself stays the same.

ok, thanks for the idea.

Strict

Const WWX = 1024
Const WWY = 768

Global Win:TGadget=CreateWindow("",0,0,WWX,WWY, Null,WINDOW_TITLEBAR)
Global Canvas:TGadget=CreateCanvas (0,0,WWX-40,WWY-80,Win)
Global sh:TGadget = CreateSlider(0,WWY-80, WWX-40,20,Win, SLIDER_HORIZONTAL)
Global sv:TGadget = CreateSlider(WWX-40,0,20,WWY-80,Win, SLIDER_VERTICAL)	

Const RX = 200
Const RY = 200

Global ViewX = 0
Global ViewY = 0
Global ViewWidth  = WWX + RX*2
Global ViewHeight = WWY + RY*2


SetSliderRange sh , GadgetWidth(Canvas),  ViewWidth 
SetSliderRange sv,  GadgetHeight(Canvas), ViewHeight 

SetSliderValue sv, 0
SetSliderValue sh , 0

Global Ennemies_list : TList = CreateList()

Type TEnnemi
	
	Field x
	Field y
	
	Function Create:TEnnemi(x:Int , y:Int)
		
		Local e:TEnnemi = New TEnnemi
		
		e.x = x - RX - ViewX
		e.y = y - RY - ViewY
		
		ListAddLast Ennemies_list , e
		
		Return e
		
	End Function
	
	Function Draw_all ()
		
		For Local e:TEnnemi = EachIn Ennemies_list
			SetColor 255 , 255 , 0
			DrawOval e.x - 3 +ViewX + RX, e.y+ViewY + RY - 3 , 6 , 6
			SetColor 255,255,255
			DrawText "x=" + String(e.x) + ",y=" + String(e.y), e.x+ViewX+RX,e.y+ViewY+RY+10
		Next
		
	End Function
	
End Type

Function Draw_canvas()
	
		SetGraphics CanvasGraphics(canvas)
		Cls
		
		ViewX = - SliderValue(sh)
		ViewY = - SliderValue(sv)
		
		SetColor 0,40,0
		For Local i=0 To ViewWidth Step 32
			DrawLine i+ViewX,0+ViewY,i+ViewX,GadgetHeight(Canvas) 
		Next
		
		SetColor 0 , 40 , 0
		For Local i=0 To ViewHeight Step 32
			DrawLine 0+ViewX,i+ViewY,GadgetWidth(Canvas),i+ViewY
		Next
		
		SetColor 255 , 0 , 0
		Tracer_boite (ViewX+RX,ViewY+RY,WWX,WWY)
		
		TEnnemi.Draw_all()		
		
		Flip
			
End Function

Function Tracer_boite (pbox_xmin,pBox_ymin,pWidth,pHeight)

	Local pBox_xmax = pbox_xmin + pWidth
	Local pBox_ymax = pbox_ymin + pHeight
	
	DrawLine pBox_xmin, pBox_ymin, pBox_xmax, pBox_ymin
	DrawLine pBox_xmax, pBox_ymin, pBox_xmax, pBox_ymax
	DrawLine pBox_xmin, pBox_ymax, pBox_xmax, pBox_ymax
	DrawLine pBox_xmin, pBox_ymin, pBox_xmin, pBox_ymax
	
	SetColor 255,255,255
		
End Function

Global paintTimer:TTimer=CreateTimer(75)


Repeat
WaitEvent()

	Select EventID()
	
	Case EVENT_TIMERTICK
	
		Draw_canvas()
		
	Case EVENT_MOUSEDOWN
	
		TEnnemi.Create (EventX(), EventY())
		
	Case EVENT_WINDOWCLOSE
		
		FreeGadget canvas
		End
		
	End Select

Forever