Dumb Beginners Questions
BlitzMax Forums/BlitzMax Beginners Area/Dumb Beginners Questions
| ||
Need a bit of help here, if you wouldn't mind :) 1. How can I read the color of a pixel on the screen or on an image? 2. I am using For EachIn Next to cycle through type lists currently. Is there a way to move through a type list inside a Repeat or While loop? 3. Can you define pointers that point to items in a list, and what is the syntax for accessing them? 4. How can I clone an image ? 5. How can I shift part of the screen (like for scrolling), I think the old Blitz had CopyRect or something like that. You could just move part of the screen to another location. 6. Is it possible to draw just part of a larger image to the screen? Phew. Thank you so much for any help. I feel like I'm really making progress in my programming, thanks to you guys! Rico |
| ||
1. You need to use GrabPixmap() and ReadPixel().Pixmap:TPixmap = GrapPixmap(x,y,1,1) 'Grabs the pixel into a 1x1 pixmap Color:Int = ReadPixel(Pixmap,0,0) 'Read the color of the pixel Red:Int = (Color & $FF0000) shr 16'Extract the red component Green:int = (Color & $FF00) Shr 8 'Extract the Green Component Blue:Int = Color & $FF ' Extract the Blue component 2. You can use TList.FirstLink(), TLink.NextLink() Local Link:TLink = List.FirstLink() 'Get the first link of the list While Link <> NULL 'Check if link is valid Local MyObject:TMyObject = TMyObject(Link.Value()) 'Get the object of the link and cast it to TMyObject MyObject.Update() 'Do whatever it is you want with MyObject Link = Link.NextLink() 'Get the next link Wend 3. 4. There is no need to clone an image. If you want to draw it twice, just use DrawImage twice with different coordinates. If you want to copy, then slightly alter one copy, it is better to use pixmaps, then transfer to images. Local Pixmap1:TPixmap = LoadPixmap("Myimage.png") 'First image Local Pixmap2:TPixmap = CopyPixmap(Pixmap1) 'Make a copy WritePixel(Pixmap2,100,100,$FFFF0000) 'alter the pixmap Local Image1:TImage = LoadImage(Pixmap1) 'Transfer Pixmap1 to an image Local Image2:TImage = LoadPixmap(Pixmap2) 'Transfer Pixmap2 to an image 5. GrabImage() will copy part of the screen into a TImage. But generally, scrolling is done by redrawing the screen with all images offset by a scroll value. 6. You can use SetViewport to clip the image to the portion you want to draw, but apparently this is a little buggy on some computers. Another way is to use PixmapWindow(), but this will be slow if a lot of things need ot be drawn. Lastly, there are some routines in the code archives to address this issue. Note that I haven't tested any of the above examples, and there is probably more than one solution, some even better than mine. :) |
| ||
3. You can use references. An example to create a reference /"pointer" to the last object in a list:Local reference:Yourtype = list.Last() You can now use reference in any way you like, and modifying it will change the object in the list (as they are the same thing, actually) |
| ||
Excellent - Thank you. With regards to the scrolling, does that mean say if you do a scrolling message (just as an example) you have to draw and move each letter seperately using DrawImage? Just seems a bit inefficient somehow. Can you do it using Pixmaps? Also if I want to draw an un-filled rectangle, is there a special command, or do i use DrawPoly? I've been using DrawRect for filled rectangles. I suppose I could draw a black rectangle inside a white one to get the same effect, if I had to. Thanks. - Rico |
| ||
There are loads of code archives and posts on unfilled rectangles like this . As for screen-scrolling there isn't the same copyrect. There are a few code archives and forum posts which cover that as well. |