forums

TNT Basic Forums > Programming Q&A
false image width
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-13-2007 21:06

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

hi,
I'm trying tu use charsets for my game (based on an gameboy RPG style).So I need to cut the charset to get the sprites , but there's a problem with that:my image is broad of 72pixels , and high of 128 pixels.
but when I use the command "image height" or "image width" , tnt gives me a different value:70 for the width , and 122 for the height.... there's no reason for that , and the program doesen't works correctly,the sprites are not correctly cutted!

did I forget something?Is it a format problem(I would not understand it,tnt can load the image correctly!I use gif images..)?
thanks!

01-13-2007 23:22

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

maybe there's white space around the actual image, that is removed?

01-13-2007 23:23

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

> the sprites are not correctly cutted!

what do you mean?

01-14-2007 11:54

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake


here is a screenshot of the complete sprite I get.he has no leg :S , and we can see the feet of the sprite above.

here's my code,if it can help you to help me :-)

'-----------------------------------------------------------------
procedure cutcharset(int numerosprite,int bank,int nspx,int nspy)
set image bank numerosprite,bank
open canvas 2,72,128
canvas 2
paste image 0,0,0,bank'-->like you did..
int num,xx,yy,stpx=image width(0,bank)/nspx,stpy=(image height(0,bank))/nspy'there are 3*4 sprites on this 72*128 image. stpx=step x (for the "for" loop...)

for yy=1 to image height(0,bank) step stpy
for xx=1 to image width(0,bank) step stpx
num=num+1
copy image xx,yy,xx+stpx-1,yy+stpy-1,black,true to num,bank
next xx
next yy
if num<>12
for xx=1 to num
beep
delay 400
next xx
end if
close canvas 2
canvas 0
'-----------------------------------------------------------------



I checked my image , but I don't understand how it can be possible !
here is the image that I used.

01-14-2007 15:01

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

quickly like that, i don't see anything obviously wrong, though isn't first pixel 0 and not 1?

01-14-2007 15:04

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

if you remove empty green areas around the character, you get 70x122 width and height... you're sure you haven't set the green to be removed?

01-14-2007 15:35

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

ok....the green is set in the image bank as transparent color!
so I should set another color for transparency (a color which is not in my image,like red) , and replace "black" with "green" in the copy command.

Ok,I just tried it:


int num,xx,yy,stpx=image width(0,bank)/nspx,stpy=(image height(0,bank))/nspy'there are 3*4 sprites on this 72*128 image. stpx=step x (for the "for" loop...)

for yy=1 to image height(0,bank) step stpy
for xx=1 to image width(0,bank) step stpx
num=num+1
copy image xx,yy,xx+stpx-1,yy+stpy-1,green,true to num,bank
next xx
next yy


It's ok for the sprite,but not for the transparency color :S ! the background color is green , but it doesen't work: that's what I get:


I tried to set "make colour(0,255,0)" instead of "green" in the copy command, but it wasn't a solution....
So thanks to you I resolved my problem.any idea for the transparency color?

thanks!

01-14-2007 15:54

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

this is definitely a bug.

for some reason i can't figure out, adding 'int color = pixel color(0,0)' before 'close canvas 2' fixes it...

01-14-2007 15:56

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

well i dunno... i've done a few tests and the error seems to come and go

01-14-2007 16:55

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Just a thought...

If green is transparent in the image info box in Hieroglyph, have you tried just ignoring transparency in the sprite image? If the charset has transparency defined then try not setting it again during the copy process.

If that doesn't work, try removing the transparency from the charset, you don't need it anyway. Just set the transparency of the sprites during the copy operation.

Worth a try...

Danny (nods)

01-14-2007 17:54

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

>
If that doesn't work, try removing the transparency from the charset, you don't need it anyway. Just set the transparency of the sprites during the copy operation.
>

Hey, that's what he's doing :D and it doesn't fully works because setting mask color when copying image seems to have bugs

01-14-2007 18:18

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

What I was saying was only set the transparency once, either remove it from the original image and only set it in the sprite, or don't set it in the sprite and only set it in the image properties...

Danny (nods)

01-18-2007 23:25

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

huuum....I don't know how to do to don't set any transparency color in the image of the image bank,and I don't know what to write in the copy command : in the help:"Copy Image x1,y1,x2,y2,mask,shrink to i" , so I must give a color for the mask,isn't it?

could you explain me how I shall do?

(PS:what does "shrink" means? my widget said me it was a "rétrécissement" in french :-) but it isn't helpful... and I don't understand the help of tnt basic XD....sorry,I'm just a little french boy :D )

01-19-2007 00:37

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Try this...

In the image properties dialogue in Hieroglyph, don't set a mask. You may need to delete the image and reload it.
The copy command should stay as it is, with a green mask. This should work. You can change 'shrink' to false though.

When an image is cropped, TNT ignores all pixels around the edge of the main picture that contain the background color. If you have a large picture made up of transparent pixels, with a small image in the center then TNT will see this and shrink the picture so that the background is removed. Only pixels with something in them are copied.

I hope this helps, but if you want to post in French then we have a number of members who speak this as their first language (I'm sure the Canadian contingent can back me up on this one!). There was a plan at one point to translate the documentation into French, but this seems to have died out a bit. Anyway, if you still need help then someone is always around to give a bit of advice...

Danny (nods)

01-19-2007 12:59

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

hey , I have a problem with what you're telling me to do:I really can't don't set a transparency color! this is the window , for the image when I just imported it into the image bank:

the transparency color is automatically set to black!


and thank you for these explanations about shrinking!But I can't set shrink to false when I copy my image.I think it's a bug , I wrote this:"copy image xx,yy,xx+stpx-1,yy+stpy-1,green,false,bank" , and get this:" expected a ',' "after setting the bank...

and I think It's better to speak (or try to do it :D ) english,because everybody can speak english here,so everybody can understand what I mean.this is not the case with french...and it's ok,because I can understand what you're saying to me! so if someone want's to speak to me in french it's great and I'll be happy to do it , but I think english shall stay the default language.

01-19-2007 15:09

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

true you can't set no mask, but you can set a mask of a color that is not used in your image (best workaround for now)

01-19-2007 16:20

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

ok,I've already done it.I used red in the image bank,and used green when copying.
If green is set as transparency color , in the image bank , I need to use black for the mask when copying,because the background of the canvas where the charset is pasted is black.
but it doesen't work correctly....so it's certainly a bug..!

01-19-2007 17:04

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

yes, as i mentionned aboce there seems to be a bug as to set transparency color when copying image. I had found a workaround, (look a few psots above) but no idea if it always works.

01-19-2007 17:29

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

oh , sorry,I haven seen your post.

>for some reason i can't figure out, adding 'int color = pixel color(0,0)' before 'close canvas 2' fixes it...

If I understand,you mean that I must add this line before closing canvas?but..I don't use this "color" variable?...hum, I think I don't understand...I tried it nevertheless,but it doesen't work!

01-19-2007 17:37

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

i know the line doesn't make any sense

actually i was trying to get color data from the canvas to check it was not a color problem. But when i added this line things started to work okay O_o

yeah it's really a bug

01-19-2007 18:26

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

actually, when it didn't work, it reported that the color on the canvas was (0,247,0) and not (0,255,0). However, using 247 instead of 255 for mask color didn't work either. Probably some obscure color issue

01-19-2007 21:41

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

hey,I get 253 for the green component! It's rather strange... and it doesn't work , even when I use 253 instead of 255...

01-19-2007 21:43

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

What format is the image saved in - PNG,PICT,JPG,.....?

01-19-2007 21:57

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

yes,I was going to speak about that:I use a png image , and I just tested with a gif: I get the same result : (0,253,0) .
why do we get two different color (wich are different of the real color) ?

and you said the bug seemed to come and go...you mean,with the same code?

01-19-2007 22:25

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

> and you said the bug seemed to come and go...you mean,with the same code?

First time i tried your code, the error was there. Then i added the line to get pixel color and everything was fine. Then i removed the line, coming back to exactly the same code i had in the beginning, but the error didn't come back.

01-19-2007 23:11

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

but the error finally come back for you?
I dit the same test than you did,but the bug was always here... I think that it's strange to have so differents results on two computer,it would certainly have been easier to understand if the error was always here...and if we get the same different color...
so,I'll think of tomorrow...now I need to sleep (yeah,it's 01:05 here in France!) !
I thank you for this help (even if it isn't finished yet) !

01-19-2007 23:36

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

yeah, for now there's little that can be done, unfortunately.

01-20-2007 07:24

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Try measuring the image width yourself! its faster for TNTbasic not to have to calculate it.

01-20-2007 13:48

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

> Try measuring the image width yourself! its faster for TNTbasic not to have to calculate it.

Hum that problem has been solved for long nom ;) The problem now is a transparency bug

01-20-2007 18:00

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

I tried this and everything worked just fine...

graphics mode 800, 600
load images 128
paste image 0, 0, 0
draw frame

int mask=pixel colour(0,0)
int thisSprite=1, x, y

for x=0 to 48 step 24

for y=0 to 96 step 32
copy image x, y, x+24, y+32, mask, false to thisSprite
next y

next x

repeat

sprite 1, mouse x, mouse y, 1
draw frame

until mouse button


The mask colour in the image info box is only used for sprites, if you paste the image it is ignored. I got the colour from the image and used this as the mask for the sprite. Worked first time...

Danny (nods)

01-21-2007 10:41

Posted by:
mikake

Location:
Maubeuge,France

Click Here to Email mikake   Find more posts by mikake

YEEEAAAHH :-)

you're just so brilliant! even if it gives a false color , if we ask it to take the color that it's seeing while pasting the image , it must be ok! and seems to be,it worked fine for me too!
so the problem isn't resolved-I mean the bug- , but It's really a good solution.

did it work fine for you too , Someone ?

01-21-2007 14:24

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

actually, when i told you about adding get color or something, this is exctly what i was trying to do. I made the same code but it still didn't work! This area seems really unstable

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.