SaveBrush(), then LoadBrush() fails?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

SaveBrush(), then LoadBrush() fails?

Post by Bugala »

I have thisw 320 x 256 pixel picture that has my games object/character pictures in it.

I have loop like this:

tempnumber=0
tempx=1
tempy=1

loop starts--->
tempnumber=tempnumber+1
tempx = tempx + 40
if tempx > 320
tempx=1
tempy=tempy+40
endif
createbrush(i, 38, 38)
selectbrush(i)
DisplayBGPicPart(1, tempx, tempy, 38, 38)

Savebrush(i, "brushes/brush"..i..".brs")
LoadBrush(i, "brushes/brush"..i..".brs", {transparency=#Black})

loop ends<----


So basically it just keeps adding higher value to X and Y so that all brushes from premade picture are took and made.

Strange part in this is, that it keeps failing at certain points.

There are 8 x 6 brushes in that picture.

If i run it like i nthis example, then it fails at brush 8, which is at placing Y-row 1 and X-row 8.

That can make sense that there could be some reason of it going too much right or something (trying to grab partr over x320) after all, it is most right row.

However, if i change that "If tempx > 320" to "If Tempx > 280" i get no problems until brush 34, which is located at y-row 5 and x-row 6 (an the whole thing is 7x6 since eighth row from x is left out), now this one makes no sense at all to bug.

Its not bottom most, since previous 5 have been same Y-row as well. Its not either right most, since there have been took x-row 7 too in previous y-rows. So wwhy does it in middle of everything decide that brush 34 is not valid one?

In both cases, in 8x6 grids brush 8, and 7x6 grids bursh 34, it complains when it tries to load the brush that file is unknown type or something similar.


Anyone have any idea why thsi happens? Is there something wrong with my PNG picture?
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by TheMartian »

Hi

There is no EndSelect() statement to match the SelectBrush() statement (At least not in the code you have included) I don't know how Hollywood reacts to this internally. But unless it somehow forces an EndSelect() when encountering a new SelectBrush() it is probably to be avoided. I can't say if it has any bearing on your problem though :-)

regards
Jesper
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by Bugala »

As i took code from my memory, i forgot that one line.

There is.
EndSelect()

right before line:
SaveBrush()

so that is not the cause of the problem.


and hopefully better from memory this time as i just checked it, it says on that loadbrush line "brush34.brush is Unknown/unsupported file format"

or very close to that.
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by TheMartian »

Hi

Mmm - I think the problem may be with the way you create your brush. First you select the brush and then you 'paint' the area of the brush using the DisplayBGPicPart() from your background picture. However you have to consider what the default values are for the dx, dy parameters, which you do not explicitly set. Notice they default to the value of the x,y parameters, and those values are variable from brush to brush and different from 0. But my guess is that you intend to paint the area to the brush starting at the brush 0,0 coordinates. Otherwise you would paint far outside the brush area with 'interesting' results. Try to change the command to:

DisplayBGPicPart(1, tempx, tempy, 38, 38,0,0)

Then it should draw the selected part of your picture starting at location 0,0 of the destination (the brush). My guess is that without the dx,dy parameters explicitly set to 0,0 you will probably end up with garbage in the saved data, which sooner or later will include random data that is unacceptable to the brush file format.

Se extract from the Hollywood guide below


SYNOPSIS
DisplayBGPicPart(id, x, y, width, height[, dx, dy, table])

INPUTS
id - id of the background picture to use as source
x - left corner
y - top corner
width - width of the tile
height - height of the tile
dx - optional: destination x-position for the tile
(defaults to x) (V1.5)
dy - optional: destination y-position for the tile
(defaults to y) (V1.5)
table - optional: further configuration table

regards
Jesper
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by Bugala »

actually a bit of a question first.

Is there some nice way to copy paste in amikit and then copy paste at browser.

For im feeling im wasting your precious time for nothing by taking this code from memory, for actually i have those two 0s on end of that DisplayBGPic command already. I just forgot to put them when i took that command from memory.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by Bugala »

to avoid wasting peoples time just because my memory have left something out, i decided to upload the problem code and picture to dropbox so you can download and check for yourselves:

http://dl.dropbox.com/u/3375468/problem.hws
http://dl.dropbox.com/u/3375468/help_my ... ics%29.png

notice that you still need to make folder "pics" where you copy that picture.

I deleted everything else from the code but this problem part.

edit: oh, and notice that you need to press left mouse button for it to continue after picture have been loaded.
pecaN
Posts: 124
Joined: Thu Jun 10, 2010 4:15 pm

Your problem solved

Post by pecaN »

Hi,your problem is so strange and interesting that i had to act immediately!:-) i downloaded your pic and wrote a simple prog similar to that of yours...and it works without ANY problems and creates all 48brushes in 3seconds! As i am writing this on my mobile,i hope i am able to post it here tommorrow afternoon! And don't be scared,it's very short and commented!:-)
pecaN
Posts: 124
Joined: Thu Jun 10, 2010 4:15 pm

Re: SaveBrush(), then LoadBrush() fails?

Post by pecaN »

Hi Bugala,
so here you are the source code i promised to post... works perfectly with your picture, all the brushes are cut from the pic, saved to ram and loaded again.
I only changed the name of the picture because it was very long:-)) regards pecaN



/* this simple proggy creates 48 brushes (displayed in a grid of 8x 6 rows) */
/* from a background 320 x 256 png picture */


@DISPLAY { Width = 320, Height = 256} /* opens a 320 x 256 window on desktop */


tempx = 1 /* initial x-position for creating brushes */
tempy = 1 /* initial y-position for creating brushes */


For created_brushes = 1 to 48 /* we want 48 brushes (8 x 6 rows in your picture) */

/* this line loads a brush DIRECTLY from your picture!!! x,y = source, width and height = 38 */
/* you don't have to use CreateBrush, DisplayBGPicPart etc... !!! */
LoadBrush(created_brushes, "pic.png", {x=tempx, y=tempy, width=38, height=38 })

SaveBrush(created_brushes, "Ram:Brush"..created_brushes..".brush") /* save a brush to Ram */
LoadBrush(created_brushes, "Ram:Brush"..created_brushes..".brush") /* load it now */
DisplayBrush(created_brushes,tempx,tempy) /* and display immediately */

tempx = Add(tempx,40) /* the same as tempx=tempx+40 - but faster:-)) */

If tempx > 320 /* if tempx >320 - that means that all 8 brushes in x-row were created */
tempx = 1 /* bring tempx back to 1 */
tempy = Add(tempy,40) /* add 40 to tempy so we are jumping to next row */
EndIf

next /* repeat this until all 48 brushes are created */


WaitLeftMouse /* and that's all!!! :-)) */
Post Reply