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.

DarkBASIC Professional Discussion / Paste part of an image

Author
Message
Liopriwo
16
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 15th Mar 2010 19:31
Is it possible to paste just a part of an image?
For example you have small pictures of items for an inventory and these are stored in one big image.
Because I think loading each picture itself would take much time (compared to loading one big file) and high image numbers would slow down the game.
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 15th Mar 2010 20:16
What you need exactly is CREATE ANIMATED SPRITE read about it in help files of dbpro.It`s pretty good explained, how to work with this.Most people maybe use it for their 2D games for animating characters, making of buttons, animated menus and etc.But there is no rule what to contain every frame of the animated sprite.I personally do not agree that few small pictures will drop performance, but anyway there is few diferent paths to do what you need.What suits you best is what you need most.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Mar 2010 20:23
Yes, I do this quite a lot with sprites. It is very handy, for fonts, for lots of item images, for animations. Lots of uses and it's quite straightforward:

set sprite texture coord spr_cur,0,xa#,ya#
set sprite texture coord spr_cur,1,xb#,ya#
set sprite texture coord spr_cur,2,xa#,yb#
set sprite texture coord spr_cur,3,xb#,yb#

To calculate the XA etc parts, I would use a grid reference then convert, like say you want image 4,5 on a 8x8 grid...

x=4
y=5
sz#=1.0/8.0
xa#=x/8.0
ya#=y/8.0
xb#=xa#+sz#
yb#=ya#+sz#

Untested, but I find that's the best way to work, especially when you want to use different grid sizes.

Remember to size your sprite after creating it, then set the UV coords, and then I'm sure you'd even be able to paste the sprite - although it might be easier to use sprites. It depends really, but having entities moving around might be easier than doing it all yourself with paste image. Plus you can do all the other spritey things, like change colours, rotate, fade, scale... lots of handy things for GUI's, inventory screens.

I think it's all win.


Health, Ammo, and bacon and eggs!
Liopriwo
16
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 15th Mar 2010 21:26 Edited at: 15th Mar 2010 21:42
Thanks for the answers.

I have thought about animated sprites but I don't know if it slows down the system because it has to do all the object management.
But I will check if I can paste a sprite several times in the same loop (with the built-in commands or with the advancedSprites Plugin).
Because if I just need one sprite, then I have just one more sprite number to manage instead of 100+ image numbers.

Edit: I tested it and I can paste a single sprite several times with both systems (advancedSprites and DBP sprite commands). So this problem is solved, thank you.

Login to post a reply

Server time is: 2026-07-26 21:12:15
Your offset time is: 2026-07-26 21:12:15