It might be on my end. I'm getting a lot of weird, inconsistent crashes on my demo now. I've restarted AppGameKit and it hasn't helped for some reason. I made a function that adds a reflection to the bottom of the image. Only *real* bug I see in my code is a slight misalignment of some pixels. Ok, 2 bugs. I can't call my function more than once. Calling it a second time just returns a black image and I haven't a clue why.
fade# = 0.7
myImage = LoadImage("\media\thundercats.jpg")
mySprite = createSprite(createReflectedImage(myImage, fade#))
Type MyDemo
time as integer
delay as float
c1 as integer
c2 as integer
c as integer
EndType
demo as MyDemo[4]
for i = 0 to 3
demo[i].time = getMilliseconds()
demo[i].delay = random(3000,7000)
demo[i].c1 = makeColor(random(0,255),random(0,255),random(0,255))
demo[i].c2 = makeColor(random(0,255),random(0,255),random(0,255))
next i
do
render()
// randomize background
ms = getMilliseconds()
for i = 0 to 3
t# = (ms - demo[i].time) / demo[i].delay
demo[i].c = getColor(demo[i].c1, demo[i].c2, t#)
if t# >= 1
demo[i].time = ms
demo[i].delay = random(3000,7000)
demo[i].c1 = demo[i].c2
demo[i].c2 = makeColor(random(0,255),random(0,255),random(0,255))
endif
next i
drawBox(1,1,1280,720, demo[0].c,demo[1].c,demo[2].c,demo[3].c, 1)
// position reflection sprite
setSpritePosition(mySprite, getRawMouseX(), getRawMouseY())
if getRawKeyState(40)
fade# = fade# - 0.01
if fade# < 0 then fade# = 0
setSpriteImage(mySprite, createReflectedImage(myImage, fade#))
endif
if getRawKeyState(38)
fade# = fade# + 0.01
if fade# > 1 then fade# = 1
setSpriteImage(mySprite, createReflectedImage(myImage, fade#))
endif
print("Fade: "+str(fade#))
Render2DFront()
Sync()
loop
function getColor(c1, c2, t#)
r = (c1 && 16711680) >> 16
g = (c1 && 65280) >> 8
b = c1 && 255
r2 = (c2 && 16711680) >> 16
g2 = (c2 && 65280) >> 8
b2 = c2 && 255
a = 255
r = r + (r2-r)*t#
g = g + (g2-g)*t#
b = b + (b2-b)*t#
c = (a << 24) + (b << 16) + (g << 8) + r
endfunction c
function createReflectedImage(imageId, rt#)
source = createMemblockFromImage(imageId)
width = getMemblockInt(imageId, 0)
height = getMemblockInt(imageId, 4)
height2 = height*rt#
size = width * (height+height2) * 4 + 12
id = createMemblock(size)
setMemblockInt(id, 0, width)
setMemblockInt(id, 4, height+height2)
copyMemblock(source, id, 12, 12, width*height*4)
offset = width*height*4+12
sy = height
for y = height2-1 to 0 step -1
for x = 0 to width-1
sPos = (sy*width + x)*4
`t# = y/(height2-1.0)
t# = (y*0.7)/(height2-1)
r = getMemblockByte(source, sPos)
g = getMemblockByte(source, sPos+1)
b = getMemblockByte(source, sPos+2)
a = getMemblockByte(source, sPos+3) * t#
pos = ((height2-y)*width + x)*4 + offset
setMemblockByte(id, pos, r)
setMemblockByte(id, pos+1, g)
setMemblockByte(id, pos+2, b)
setMemblockByte(id, pos+3, a)
next x
dec sy
next y
img = createImageFromMemblock(id)
deleteMemblock(source)
deleteMemblock(id)
endfunction img
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds