Page 1 of 1

Image chopping

Posted: Tue Feb 08, 2022 5:56 pm
by benfield
What are the criteria for dividing an image file when loading it into a SPRITE array. It seems to be more intelligent than just chopping the screen into equal divisions. Does it recognise white space and/or objects? SPRITE "cards" LOAD "cards.png",14,4 seems to pick out just the cards.

Thanks

Andy Smith.

Re: Image chopping

Posted: Tue Feb 08, 2022 6:14 pm
by Mr. Kibernetik
No, SPRITE LOAD just splits the sprite sheet into the specified amount of raws and columns.

Re: Image chopping

Posted: Tue Feb 08, 2022 6:35 pm
by benfield
Thanks Mr K.

So that I can understand this better, can you tell me why;

X=0!Y=0!W=1366!H=129*A
SPRITE n$ SCAN X,Y, W,H
SPRITE n$ SAVE "cards4.png"
SPRITE S$ LOAD "cards4.png",13,A

gives the same result when A=1, a single suit, as when A=4. N$ is a simple image consisting of 13 cards across by 4 suits down. S$ picks up 13 spades but nothing else. I can’t understand this.

Thanks

Andy.

Re: Image chopping

Posted: Tue Feb 08, 2022 7:53 pm
by Mr. Kibernetik
Is card4.png file available?

Re: Image chopping

Posted: Tue Feb 08, 2022 9:23 pm
by benfield
Attached

Re: Image chopping

Posted: Tue Feb 08, 2022 9:51 pm
by Mr. Kibernetik
This code:

Code: Select all

sprite 0 load "cards4.png",13,4
sprite 0 show
sprite 0 delay 0.5
sprite 0 loop
1 goto 1
works exactly as expected: it shows a sequence of 13*4 cards of all 4 suits.

Re: Image chopping

Posted: Tue Feb 08, 2022 10:11 pm
by benfield
Maybe it’s my fault then but:

- you have used 0 which I assume is a single sprite in which case I don’t really understand the significance of the 13,4
- I wanted a named sprite array N$ with 52 separate elements which I could display separately in a FOR loop

I do appreciate the help - I’m learning a lot

Re: Image chopping

Posted: Tue Feb 08, 2022 10:21 pm
by Mr. Kibernetik
In the code above 0 is a sprite name. It could be "MySpriteName" or anything else instead of "0". And 0 was used without quotes because BASIC will convert number 0 into name "0" automatically. So, this is equivalent to

Code: Select all

sprite "MySpriteName" load "cards4.png",13,4
...
The sprite name does not indicate or affect the number of sprite frames inside the sprite.

You can look at example "Sprites/every frame.txt" to see how multi-frame sprites work.

Re: Image chopping

Posted: Tue Feb 08, 2022 10:33 pm
by benfield
Many thanks.

I really appreciate the tuition.

Re: Image chopping

Posted: Sun Feb 13, 2022 3:31 pm
by Henko
Look in the programs section for more stuff about cards.