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.

Code Snippets / [DBP] - Simple code library

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 23rd Feb 2012 02:21
Hi all. I'm starting to put this together more of a way of keeping snippets of code that I will probably recycle over and over safe more than anything else, but feel free to add anything you want to it, and use whatever I post here myself. Maybe we'll get a mini "code base" going and everyone can benefit. And please...these will be sections of code I am using that are made for my purpose - if they don't exactly fit yours then you'll have to adapt them yourselves.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 23rd Feb 2012 02:25 Edited at: 23rd Feb 2012 02:32
Anyway, first up is a sprite placement routine. It works as follows:



Once this function is added, you need only call it with the relevant line
for each sprite. The advantage here is that the sprite will hold it's exact proportions and position regardless of the screen resolution (more or less). I use it for my menu screen. and also for placing on screen text such as time limits, scores etc so that resolution changes aren't an issue. I suppose in theory it could be used for all the sprite placement work of a 2d game too, but it may be slow if you're calling hundreds of sprites 60 times a second - I don;t know, not tried it.

Attached is an example screen of the menu screen of my project, the level selection handled by sprites. In the comparrisons, the same exact same screen coords were passed at different resolutions - as you can see, placement is pretty good.

Attachments

Login to view attachments
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 28th Feb 2012 01:26
http://forum.thegamecreators.com/?m=forum_view&t=187462&b=2

This thread explains what I did



now lets keep it pretty

I am not sure but is not the codebase there for a reason?

if your answer is that we can debate code here prior to adding it to the codebase then I agree...

I hope I can contribute something here eventually...

Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 22nd Mar 2012 22:50
Ok, here's entry 2 - a very simple file selector. PLEASE NOTE: this does NOT have all the functionality of the windows selector, but it is made for my specific purposes so alter as you see fit if you wish.

Few things to note: the varibale selection$ is the result of the selection, so either make it global or alter the function to pass it to it and back (i use it elsewhere so global suits). It reads the starting path, but isn't used at that point. Text should be Arial 18 or equivolent or adjust the list spacing to suit. The sprite can be "skinned" as you see fit, but please keep the buttons position/dimensions etc identical - everything else is based on this. Remember to load the image first, and change the sprite number/image number as needed.

Feel free to improve it - I may as my need of it grows.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-28 13:53:03
Your offset time is: 2024-03-28 13:53:03