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 / Image/Sprite question

Author
Message
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Nov 2011 12:19
Not sure what to call this so I couldn't come up with a better subject.

Normally when you scale a sprite the image is stretched to the new sprite size. But instead I would like the image to be repeated. I'm working on a health bar with separate icons for each HP and I don't want to use a single sprite for each. This would also be handy for scrolling backgrounds etc.

Is this currently possible? If not, it should be included ASAP.

I found references to SetImageWrapU and SetImageWrapV but they are not listed in the image commands so I don't know what they do or how to use them. I've never worked with UV coordinates before so this is all new to me.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Nov 2011 13:04
You could do this with code something like this (attached project):


Attachments

Login to view attachments
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Nov 2011 13:09
Quote: "I found references to SetImageWrapU and SetImageWrapV but they are not listed in the image commands so I don't know what they do or how to use them. I've never worked with UV coordinates before so this is all new to me."

Those commands are located in the 'Core' commands set and I understand what you mean about having the image repeated. The Games Factory 2 had a feature like that. I don't know much about the UV coordinates system either so I don't know if this is currently possible or not.

@ baxslash: nice snippet, I just might use that.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Nov 2011 13:10 Edited at: 21st Nov 2011 13:11
baxslash:
My point was to avoid using multiple sprites for a single health bar. That has to be more efficient than using separate sprites.

Hodgey:
I'll take a look. Thanks

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Nov 2011 13:13
Quote: "My point was to avoid using multiple sprites for a single health bar. That has to be more efficient than using separate sprites."

OK give me ten more minutes

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Nov 2011 13:26 Edited at: 21st Nov 2011 13:36
Try this:


EDIT: You can't currently use multiple separate images in one sprite but couldn't you just make one image combining the separate images and use my code above?

Attachments

Login to view attachments
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Nov 2011 13:34
Here's what I came up with myself, works like a charm. You need to use the SetImageWrapU command to make the image repeat. According to the text the best result on all devices is to use an image like this:

"Due to these possibilities it is recommended that UV coords only be modified on sprites that are using whole images (not atlas textures) and which are a power of 2 size in both width and height. With these constraints it is possible to use UV values outside 0-1 to clamp or repeat the texture successfully."



I have attached the image I use, feel free to use it yourself. It's in black and white with alpha so you can change the color by code.


Thanks baxslash but I solved it myself

Attachments

Login to view attachments
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Nov 2011 13:37 Edited at: 21st Nov 2011 13:38
And this is what the above looks like.



Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Nov 2011 13:38
Quote: "Thanks baxslash but I solved it myself"

Looks like we both came to the same conclusion for the scaling issue too

Great minds and all that...

Login to post a reply

Server time is: 2024-03-28 21:57:53
Your offset time is: 2024-03-28 21:57:53