Problems with image placement
BlitzMax Forums/BlitzMax Beginners Area/Problems with image placement
| ||
Hi all, My fruit machine project is coming on quite nicely, but I'm struggling getting my head around something to do with the placement of images which I want to 'overlay' my main image. The main graphic is 1024x1536, which is normally handled and drawn at 0,0. You can scroll down to the bottom and up to the top via the arrow keys. I now want to place some items that appear on top of this graphic. Some items will start of screen, of course (on the bottom 768 pixels that are only seen when you scroll down) and I can't seem to get the co-ordinates right for these items - it works OK for items that start 'on screen' however, but ideally, I'd want something that works for all items. Here's my code so far, please note that this will be 'thrown away' after use, so it may be scrappy, I just wanted to utilise it to work out the co-ordinates for all the 130-odd 'lamps' that I need to paste over the main image. I hope this makes sense! '---Heaven & Hell (Lamp Locator) '---27 January 2009 '---Version 0.01 Graphics 1024,768 SetBlend ALPHABLEND HideMouse Global gfx_main=LoadImage("main.png") SetImageHandle gfx_main,0,0 Global gfx_lamps=LoadAnimImage("lamps.png",200,128,0,140) SetImageHandle gfx_lamps,100,64 Global var_screenx=0 Global var_screeny=0 Global var_lampcount=137 Global var_lamp=0 Global var_alpha#=1 Global var_alphadir=0 Repeat SetClsColor 255,255,255 Cls If KeyDown(KEY_DOWN) And var_screeny>-768 Then var_screeny:-2 If KeyDown(KEY_UP) And var_screeny<0 Then var_screeny:+2 SetAlpha 1 DrawImage gfx_main,var_screenx,var_screeny If KeyHit(KEY_EQUALS) Then If var_lamp<137 Then var_lamp:+1 Else var_lamp=0 End If End If If KeyHit(KEY_MINUS) Then If var_lamp>0 Then var_lamp:-1 Else var_lamp=137 End If End If If MouseDown(1) Then If var_alpha>0 And var_alphadir=0 Then var_alpha:-0.02 End If If var_alpha=<0 Then var_alphadir=1 If var_alpha<1 And var_alphadir=1 Then var_alpha:+0.02 End If If var_alpha=>1 Then var_alphadir=0 SetAlpha var_alpha End If DrawImage gfx_lamps,MouseX(),MouseY(),var_lamp SetAlpha 1 DrawText MouseX(),0,0 DrawText MouseY()+var_screeny,0,12 DrawText var_screenx,0,24 DrawText var_screeny,0,36 Flip Until KeyHit(KEY_ESCAPE) If you need me to explain further, please just let me know... ;) Cheers, M |
| ||
Draw everything in the same place, all the time... but instead use SetOrigin X, Y to change the top-left location of the screen. eg. SetOrigin 0, -10 will appear to shift everythin UP 10 pixels. |
| ||
Like Brucey said, I'd use set origin to change your offset for "scrolling". You could make a global offset and apply it to everything as it's draw, but that's basicly what set origin does without you having to change every single draw command. the only problem comes if you want a static display (i.e. a timer at the top of the screen, that would usually not move) in which case you have to apply the inverse of the SetOrigin to shift that to the correct place. but I think 1 manual offset change for static items and then using set origin for the who-knows-how-many other things is the easier option. |
| ||
Gents (I assume!) that sounds perfect - will give it a try tomorrow as I've been working on it for the last 12 hours or so and my eyes (not to mention my brain!) are extremely tired. Many thanks! |
| ||
@ima747 just use setorigin 0,0 and draw your HUD!Graphics 800,600 Global x:Int = 0 Global y:Int = 0 While Not AppTerminate() Cls SetOrigin x,y If KeyHit(KEY_UP) Then y:-1 If KeyHit(KEY_DOWN) Then y:+1 If KeyHit(KEY_LEFT) Then x:-1 If KeyHit(KEY_RIGHT) Then x:+1 If KeyDown(KEY_UP) Then y:-1 If KeyDown(KEY_DOWN) Then y:+1 If KeyDown(KEY_LEFT) Then x:-1 If KeyDown(KEY_RIGHT) Then x:+1 SetColor(255,128,0) DrawRect(100,100,100,100) SetOrigin 0,0 SetColor(255,255,0) DrawText "Arowx.com - SetOrigin Test this should not move!",0,0 Flip Wend |
| ||
Thanks again guys, so simple when you look at it. Right, on I press with working out the co-ordinates for 138 seperate items! ;) |
| ||
Right, I now have a 'catalogue', containing the following information for each of my 138 items: -x position -y position -tile number I may well add further additional data fields to enable me to identify groups of tiles, etc. What would be the best way to store all this information? I know that within BMax I'll access it via a list or array, but should I store it in a text doc and 'read it in' or store it as data items? |
| ||
personally, I would go with XML. |