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.
Posted: 21st Nov 2011 13:04
You could do this with code something like this (attached project):
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )

dim health[100] as integer
for s=1 to 100
    spr = createSprite(0)
    setSpriteSize(spr,1,10)
    setSpritePosition(spr,s-1,3)
    n# = s
    a# = n#/100.0
    setSpriteColor(spr,(1.0-a#)*255,a#*255,0,255)
    setSpriteVisible(spr,0)
    health[s] = spr
next

do
    H = getPointerX()
    Print("Health: "+str(H))
    
    for s=1 to H
		setSpriteVisible(health[s],1)
    next
    for s=H+1 to 100
		setSpriteVisible(health[s],0)
    next
    
    sync()
loop
Posted: 21st Nov 2011 13:09
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.
Posted: 21st Nov 2011 13:10
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
Posted: 21st Nov 2011 13:13
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
Posted: 21st Nov 2011 13:26
Try this:
+ Code Snippet
rem
rem AGK Application
rem

rem Landscape App
SetDisplayAspect( 4.0/3.0 )

i = loadImage("health.png")
s = createSprite(i)
setSpritePosition(s,0,3)

rem A Wizard Did It!
do
    H# = getPointerX()
    Print("Health: "+str(floor(H#)))
    
    setSpriteSize(s,H#,10)
    setSpriteUVscale(s,100.0/H#,1.0)
    
    Sync()
loop


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?
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."

+ Code Snippet
HP = 100
PointImg = LoadImage( "Point.png" )
SetImageWrapU( PointImg, 1 )
HPspr = CreateSprite( PointImg )
SetSpriteColor( HPspr, 255, 0, 0, 255 )
SetSpriteScale(HPspr, HP, 1)
SetSpriteUVScale( HPspr, 1.0/HP, 1 )


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
Posted: 21st Nov 2011 13:37
And this is what the above looks like.

Posted: 21st Nov 2011 13:38
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...