Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Image \ Sprite Created From Memblock Is Corrupted.

Author
Message
Dead Pixel
9
Years of Service
User Offline
Joined: 27th Nov 2014
Location:
Posted: 15th Feb 2015 21:10
Hi AppGameKit users,

Whilst following along with the examples in chapter 24 of "Hands On AppGameKit BASIC" which deals with memblocks, I wrote the following short piece of code, it compiles OK and I was expecting to see a randomly coloured pixel in the top left-hand corner of the image. However, what I'm actually seeing is a black and white image that appears to be corrupted with random data. I have attached a screenshot for clarification.



Even if I comment out all the SetMemblockByte commands I still get the corrupted image so I'm guessing it must be something simple that I'm overlooking and and no doubt I'll feel like kicking myself when I see what the answer is.

Using memblocks reminds me of using POKE and PEEK many years ago on my 48K ZX Spectrum !!!

Thanks for reading.

[ Coding In BASIC using AppGameKit V2 ]

Attachments

Login to view attachments
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Feb 2015 22:15
I've had this issue before, it seems that if the memblock gets too big then it fills up with junk values.

When I ran you code but had the width and height set to 10 there was no problem with the image. Obviously this isn't a solution but hopefully give some background.

What I did was set all the pixel values - red, green, blue and alpha - to zero then filled the memblock with the values I wanted. This can be done with a for-to-next loop, which I've added to your function.



Hope this helps.

Dead Pixel
9
Years of Service
User Offline
Joined: 27th Nov 2014
Location:
Posted: 15th Feb 2015 23:25
Thanks, 29 games - Your fix has solved the problem for me. Nice one !!!

This is probably considered bad practice generally, but
s_Id = CreateSprite(CreateImageFromMemblock(Create_Memblock())) compiles and runs without any problem as does the following - SetSpritePosition(CreateSprite(CreateImageFromMemblock(Create_Memblock())), 50, 50)

Both work, but you'd need to place the commands outside your do.....loop, otherwise you'll be creating new sprites continously.

//******************************
// Coding In BASIC using AppGameKit V2
//******************************

Login to post a reply

Server time is: 2024-11-21 12:21:15
Your offset time is: 2024-11-21 12:21:15