Ok, I have put a few post's on here lately as I am doing an AGK2 Colouring Book project.
See here for the code etc:
http://forum.thegamecreators.com/?m=forum_view&t=213305&b=48
Along the way I have run into some problems as AGK2 is quite new to me but I have coded before and in DBPro.
The problem is, is that when I get past one problem I come across another two and it seems to be never ending at the minute.
Anyway as part of my game I am using memBlocks to do a flood fill technique to make the colouring in, fill a section of the screen.
I have managed this with a screen res of 640 x 430 but when I up the picture res to 1130 x 800 it slows down somewhat.
Not just the filling of the screen but also reading the pixels in the memBlock. Again please see the full code on the other post to see the full code but as part of the code I am trying to create a memblock from an image and then when I change the picture to colour I delete this memblock and create another for the new picture and then start flood filling that one.
Here is a section of the code to demonstrate what I am trying to do.
memBlock = CreateMemblockFromImage (page[0].iImage)
colour_backGrnd = GetPixel(memBlock, 0, 0, pageWidth)
StoreFillPixels( memBlock, pageWidth, pageHeight, colour_backGrnd )
DeleteMemblock(memBlock)
memBlock = CreateMemblockFromImage (page[1].iImage)
colour_backGrnd = GetPixel(memBlock, 0, 0, pageWidth)
StoreFillPixels( memBlock, pageWidth, pageHeight, colour_backGrnd )
I have come across a problem here though in that when I create the second memblock even though the first one was deleted it seems to do a merge of the 2 when I read the memblock pixels after and take forever to read the memblock but them doesn't colour the image correctly after.
Is there a way to fully flush the deleted memblock and would this solve the problem?
Do you know of a way to really speed up the program? 640 x 430 is ok but 1150 x 800 is not great on a tablet, just about ok on the PC though.
Other things I have thought is maybe change my grab pixel technique and change it to a more traditional flood fill routine but I was also wondering is it slow because AGK2 does not have the lock pixel command does this really slow down the memblock process when writing bytes etc as the same fill technique in DBPro is super fast at large screen res.
Here is an example of the flood fill idea but doesn't seem to work correctly yet!
I have attached a picture to colour for you to see what I mean.
Hope someone can assist and I guess it will be onto more problems
Cheers again for all the help so far.
imgWidth = 1150
imgHeight = 800
drawImageScrNum = 1
drawImage = LoadImage ( "/media/pages/PIC1.png" )
memBlock = CreateMemblockFromImage ( drawImage )
// set display properties
SetVirtualResolution( imgWidth, imgHeight )
SetOrientationAllowed( 1, 1, 1, 1 ) // 0, 0, 1, 1 Settings for horizontal value only but upside down turn allowed
SetSyncRate ( 60, 0 )
CreateSprite ( drawImageScrNum, drawImage )
SetSpritePosition ( drawImageScrNum, 0, 0 )
sync ()
// ***** Main Game Loop *****
do
// Check for the pointer to be pressed
if GetPointerPressed()=1
// Store pointer x and y values for position on screen
mouseX = GetPointerX()
mouseY = GetPointerY()
xMse = GetPointerX()
yMse = GetPointerY()
// Waits for the pointer to be released before filling area so doesn't constantly fill
while GetPointerReleased()=0
Sync()
endwhile
// Checks pointer is in the main screen area to fill picture
if mouseX >= 0 and mouseX <= imgWidth and mouseY >= 0 and mouseY <= imgHeight
offsetPxl = 12 + (( (xMse) + ( (yMse) * imgWidth )) * 4 )
oRd=GetMemblockByte( memBlock, offsetPxl)
oGr=GetMemblockByte( memBlock, offsetPxl+1)
oBl=GetMemblockByte( memBlock, offsetPxl+2)
nRd = Random(1, 255)
nGr = Random(1, 255)
nBl = Random(1, 255)
FloodFillUtil(memBlock, imgWidth, imgHeight, xMse, yMse, oRd, oGr, oBl, nRd, nGr, nBl)
DeleteImage(fillImage)
fillImage = CreateImageFromMemblock( memBlock )
SetSpriteImage(drawImageScrNum, fillImage )
endif
endif
Sync()
loop
// ******************** Functions **********************
function FloodFillUtil(memBlock, w, h, x, y, oRd, oGr, oBl, nRd, nGr, nBl)
osetPxl = 12 + (((x) + ((y) * w)) * 4)
// Base cases
if x < 0 or x >= w or y < 0 or y >= h
ExitFunction
endif
R=GetMemblockByte(memBlock, osetPxl)
G=GetMemblockByte(memBlock, osetPxl+1)
B=GetMemblockByte(memBlock, osetPxl+2)
if R <> oRd and G <> oGr and B <> oBl
ExitFunction
endif
// Replace the color at (x, y)
//screen[x][y] = newC;
//osetPxl = 12 + (((x) + ((y) * w)) * 4)
SetMemblockByte( memBlock, osetPxl, nRd )
SetMemblockByte( memBlock, osetPxl+1, nGr )
SetMemblockByte( memBlock, osetPxl+2, nBl )
SetMemblockByte( memBlock, osetPxl+3, 255 )
// Recur for north, east, south and west
floodFillUtil(memBlock, w, h, x+1, y, oRd, oGr, oBl, nRd, nGr, nBl)
floodFillUtil(memBlock, w, h, x-1, y, oRd, oGr, oBl, nRd, nGr, nBl)
floodFillUtil(memBlock, w, h, x, y+1, oRd, oGr, oBl, nRd, nGr, nBl)
floodFillUtil(memBlock, w, h, x, y-1, oRd, oGr, oBl, nRd, nGr, nBl)
endfunction
Programming - AMOS on the AMIGA! / DBPro / Python / A bit of C &amp;amp;amp;amp;amp;amp;amp;amp;amp; C++ / now also AGK2! Graphics - Deluxe Paint on the Amiga / Paintshop Pro / Photoshop / Lightroom / Grafx2
Previously worked for Prisma Software producing childrens educational software on the Amiga. Titles - Pepe's Garden - Paint Pot / Kids Academy range - Paint Pot II / Shopping Basket / Which Where What? / Blobs / Alvin's Puzzles