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.

AppGameKit Classic Chat / Tier 2 - Load image and sprite frames

Author
Message
Klomy
10
Years of Service
User Offline
Joined: 17th May 2014
Location:
Posted: 17th May 2014 15:46
Greetings,

newcomer to AppGameKit here, trying to figure out a couple things (for tier 2) !

1 - Is there any way to load an image into AppGameKit by other means than specifying the file name ? Like I load the image myself and push the data to AppGameKit, or maybe specify a stream or whatever ?

The goal here is to not have a folder with multiples images files. Instead pack them all in one file. I can do that, but just don't know how to send them to AGK.

Or maybe there is a "best practice" around for managing resource files, if so I would like to know about it ! I just don't feel like having a ton of resource files in a folder everyone can freely play with it is a good idea, so I'm trying to figure out how to avoid that.

2 - For sprite animations, let's say I have an image which contains 10 frames. I see I can play only a part of it, but is it possible to define a custom non-linear sequence to play ? ex : fr1-fr6-fr3-fr6

As for having a strait sequence in my file, the goal is to be able to reuse frames to keep the image size minimal.

If after loading my image and defining my animation frames size I could use each frame as an image, that would be enough.

I understand I can do that by having all my frames as independent images (10 images instead of 1 image with 10 frames), and load them all into new frames. Ultimatly I would go with that option, but still I'd like to keep them all in one file.


Thanks !
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th May 2014 13:11
You can encrypt the images, load them into a memblock, apply the decryption algorithm to the memblock and then load the image from the memblock. This is the best way to do it. People extracting the image files will get garbage.

-- Jim - When is there going to be a release?
Klomy
10
Years of Service
User Offline
Joined: 17th May 2014
Location:
Posted: 19th May 2014 14:52
Yeah that's what I want to achieve. But what I don't understand, is how I can tell AppGameKit to load the image from the memory instead of a file. I only found it accept file name, so how can I do that ?

Thanks !
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 19th May 2014 15:47 Edited at: 19th May 2014 15:49
Hi Klomy and welcome!
I will help you for Apple Tier 2.

1 - Don't encrypt the images, as the Apple package when created already encrypt the images to compress the file. Apple also want to know if you use encryption when you set the app in itunes connect.
Anyway, if you want to encrypt the images, or just doing a single file with all images inside, you can do like Jim said.
Pack the image together, using an array of bytes and unpack them in the original array list.
When you done, use CreateImageFromMemBlock.

2 - Yes you can. I done this in the Karate game to reuse some positions of the fighters.
Do an Animation array, where you can specify the images to use for each frame, and then animate manually the frames using SetSpriteFrame.

Example :

This is the way i manage the animations manually.
You can use other methods too.



Long life to Steve!
Klomy
10
Years of Service
User Offline
Joined: 17th May 2014
Location:
Posted: 19th May 2014 17:00
Thanks xGEKKOx !

It's the CreateImageFromMemBlock part I was missing. Now that I know it exists, that should do the trick

As for the encryption, thanks for the info. Yet I'm not sure if I'll encrypt the files, but I'll keep that in mind when I'll target Apple plarforms.

Thanks again !
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th May 2014 17:18
One thing to keep in mind with memblock images saved or loaded as files, is they would be very easy to retrieve. I mean, a memblock is like saving the raw data with no compression, so that file could be loaded and the images nabbed quite easily - it's just RGBA data after all. In fact, the memblock image format is very close to the standard TGA format, anyone with even a little knowledge would be able to access the images. Just bringing this up in case it's something you might have to be wary off - it can get messy with apps sometimes - certain companies and individuals will rip graphics and re-use them.

I am the one who knocks...
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th May 2014 18:22
I showed some while ago that using XOR can make any file garbage and very hard to crack. Using the memblock, the file will never be saved in any usable format.

-- Jim - When is there going to be a release?
Klomy
10
Years of Service
User Offline
Joined: 17th May 2014
Location:
Posted: 19th May 2014 18:50
It's not that I want to protect the image. I know anyone with decent skill would be able to retrieve it. Nothing is totally safe when you have to decrypt it on the client !

My first goal was only to pack them into one file so it's looks "cleaner" on the disk and peoples can't easily browse them.

So far I don't plan on ecrypting them. What i was considering is signing them so they would be harder to alter.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th May 2014 19:05
I use XOR encryption on many files in Wordspionage. It's pretty simple. I store the keys in arrays that are hardcoded in. You could do something similar and just tag the file with a reference to the key it was encrypted with. I then load the file into a memblock, xor it, then save the file, load it, and then delete it. As long as the file sizes are not large it happens very very quickly.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 20th May 2014 10:44
Hi
I'm interested in encryption (for my file image and save file for example).

Do you know if there is a simple example (in agk tier1) to show how to encrypt/decrypt and load an image (or a text) in our game ?

Thank you

http://www.dracaena-studio.com
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 20th May 2014 19:31
Here's a very basic level for just a data file where you might store game variables (user name, lives, score, etc)
gMEMEBLOCK_ID is global so it can be accessed during the game.
GAME_KEY[8]=[1,2,38,44,250,119,246,117,111] is the XOR encryption key (must be the same when saving or loading).




Here's my library for loading encrypted media:




gosub _init_keys is a sub that contains declarations for all of the key arrays, file names, etc


gosub _kill_keys is a sub to undim all of the keys created in _init_keys to free up memory.


I've attached the tool I used for encrypting the files. It's not really intended for public use so isn't well commented and you'll need to actually read it to figure out how to use it. But it is short. Basically what it does is it takes a file you put in the media folder, generates a random key to encrypt it with, encodes the file with that key. The first byte is the overall key size, then next 3 bytes are the file's true extension. I can't recall if this encodes the head and tail of the files or not. It's at least the head. It actually looks like the entire file is encoded with the key. That's likely overkill, but it doesn't matter much because once you load the file into a memblock the most intensive part is done, the actual iteration through the memblock and XOR is extremely fast. The loading the file and saving the files is the slow part. But now I don't think you even need to save the file if it is an image since there's CreateImageFromMemblock now you could actually skip the saving part, but you'll need to learn the structure of your file types (PNG / JPG / etc) to understand how to load them into a memblock for use as an image. PNG isn't hard to do this with. No clue about doing this with JPG though.

The attached program parses out the arrays and everything for the keys (keys.agc) and undimming the keys (keysundim.agc) so you can just toss your media into this program's media folder, run the program to encode all. Then copy and include the two key files into your own program. Then make the functions for decoding them in your program too. It might be useful to you to go through a tool-building exercise for this kind of program on your own. It's not too hard, just a bit time consuming. Also it's really good logic, algorithm, and tool-building practice.

Attachments

Login to view attachments
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 21st May 2014 01:55
Wow, too long code for encryption.
I done the one i use for my servers in 40 lines of code.
But is ok.

Long life to Steve!
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st May 2014 02:03
The first example is super short. The other stuff is tools for building keys and parsing the data so the keys can be loaded into AppGameKit tier 1 arrays and hardcoded into the bytecode file.
Working with a server would be much easier because the keys can just be stored in a database. The actual encryption/decryption code is only about 20 lines each.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 10th Jun 2014 10:04 Edited at: 10th Jun 2014 10:31
Hi

@Naphier : I have tried your code, but it doesn't work.
I have encrypted file but the size of this file = 0 ko.


Here is the code I use :


http://www.dracaena-studio.com
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th Jun 2014 10:18
A couple things. First your looking to find a file name then you're overwriting that same file. You don't want to do that. Second you're just looking at an empty memblock. If you want to encrypt a file you have to read it into the memblock first, then do the xor. You're probably ending up with some really weird data in a file. Also make sure the memblock id is accessible globally.
The function you are using is meant to save a memblock to an encrypted file. You're just opening an existing file then overwriting it with a memblock that contains god knows what and performing xor. Don't save the file as the same file being encrypted.

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 10th Jun 2014 10:33 Edited at: 10th Jun 2014 11:16
Thank you for your answer .

Here is the code i have use with succes :



@Naphier : I use your function to decrypt the encrypted file and it works. But I don't know how to use the result.

I have tried :

But it doesn't work.

Could tell me how I can use the memblock as an image please or decrypt the file ? (I could save it decrypted, load it as image and delete the decrypted file)

Thank you again.

http://www.dracaena-studio.com

Login to post a reply

Server time is: 2024-11-25 05:28:37
Your offset time is: 2024-11-25 05:28:37