Posted: 1st Sep 2011 13:10
Just started a new project to test some code without polluting my main game, and I've got a probelm where sprites are showing up as white blocks. The sprites are PNG files with transparency, and I get the same effect when using the small_ball.png file that ships with the examples.

I've installed the latest version of AppGameKit, but I wouldn't have thought that would cause a problem. My main project runs fine, as do the examples, so it must be something odd that I'm doing, but I'm not sure what.

The code I'm using is:
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )

SetSyncRate(60,1)

Type _myType
    spriteID
EndType

Dim balls[100] as _myType
Global ballCounter = 0

ballImage = LoadImage("small_ball.png")

do
    if GetPointerPressed() = 1
        createBall(GetPointerX(), GetPointerY())
    EndIf

    Sync()
loop

Function createBall(xPos#, yPos#)
    if GetSpriteExists(balls[ballCounter].spriteID) = 0
        balls[ballCounter].spriteID = createSprite(ballImage)
        SetSpritePositionByOffset(balls[ballCounter].spriteID, xPos#, yPos#)

        INC ballCounter
        If ballCounter > 4 Then ballCounter = 0
    EndIf
EndFunction


There's not a lot of point posting a screenshot, as all it will show is a black program window with up to 5 white squares on it where the sprites should be. But I can do it if anyone thinks it will be helpful. The image is located in the 'media' folder under the root of my game, and as expected I get an error if I change the name to one that doesn't exist.

This has got me scratching my head, but odds on it turns out to be something really simple!
Posted: 1st Sep 2011 13:18
I had your same problem. If I used a 100% transparent png, it translated into a white block! Putting a pixel somewhere in the image solved the problem!
Posted: 1st Sep 2011 13:20
No, it's not that - the sprite has content in it. As I said, if I use the small_ball image from the examples, I get the same problem.
Posted: 1st Sep 2011 13:41
I get the same, I'll send it to Paul to investigate!

Rick
Posted: 1st Sep 2011 14:12
I get the same, I'll send it to Paul to investigate!

Cheers, at least I know it's not me!
Posted: 1st Sep 2011 15:31
It is wierd because if you call it straight then it works...
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )

SetSyncRate(60,1)

Type _myType
    spriteID
EndType

Dim balls[100] as _myType
Global ballCounter = 0

ballImage = LoadImage("small_ball.png")

do
    if GetPointerPressed() = 1
        createBall(GetPointerX(), GetPointerY())
    EndIf

    Sync()
loop

Function createBall(xPos#, yPos#)
    if GetSpriteExists(balls[ballCounter].spriteID) = 0
        balls[ballCounter].spriteID = createSprite(LoadImage("small_ball.png"))
        SetSpritePositionByOffset(balls[ballCounter].spriteID, xPos#, yPos#)

        INC ballCounter
        If ballCounter > 4 Then ballCounter = 0
    EndIf
EndFunction



or if you try this
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )

SetSyncRate(60,1)


ballImage = LoadImage("small_ball.png")

do
    if GetPointerPressed() = 1
        createSprite(ballImage)
    EndIf

    Sync()
loop

.... it works as well.

So something is going wrong in the array or the user type.


Edit

The problem seems to be with the create sprite
This code gave an error message that the image did not exist
+ Code Snippet
SetDisplayAspect( 4.0/3.0 )
setvirtualresolution(640,480)

SetSyncRate(60,1)

Type _myType
    spriteID
EndType

Dim balls[100] as _myType
Global ballCounter = 0

ballImage = LoadImage("small_ball.png")
createSprite(1, ballImage)

do
    if GetPointerPressed() = 1
        createBall(GetPointerX(), GetPointerY())
    EndIf

    Sync()
loop

Function createBall(xPos#, yPos#)
    if GetSpriteExists(balls[ballCounter].spriteID) = 0
        balls[ballCounter].spriteID = createSprite(1)
        SetSpritePositionByOffset(balls[ballCounter].spriteID, xPos#, yPos#)

        INC ballCounter
        If ballCounter > 4 Then ballCounter = 0
    EndIf
EndFunction



It says that image 1 does not exist at line 30 but we know that it does.

Then if I used clonesprite it worked...

+ Code Snippet
SetDisplayAspect( 4.0/3.0 )
setvirtualresolution(640,480)

SetSyncRate(60,1)

Type _myType
    spriteID
EndType

Dim balls[100] as _myType
Global ballCounter = 0

ballImage = LoadImage("small_ball.png")
createSprite(1, ballImage)

do
    if GetPointerPressed() = 1
        createBall(GetPointerX(), GetPointerY())
    EndIf

    Sync()
loop

Function createBall(xPos#, yPos#)
    if GetSpriteExists(balls[ballCounter].spriteID) = 0
        balls[ballCounter].spriteID = cloneSprite(1)
        SetSpritePositionByOffset(balls[ballCounter].spriteID, xPos#, yPos#)

        INC ballCounter
        If ballCounter > 4 Then ballCounter = 0
    EndIf
EndFunction



Not sure if this will help any but here it is anyway.
Posted: 1st Sep 2011 15:33
The variable "ballImage" is not global, so inside the function it is equal to 0, which creates a blank sprite.
Posted: 1st Sep 2011 15:40
D'oh! Where the facepalm smiley?

Thanks.
Posted: 1st Sep 2011 15:42
The variable "ballImage" is not global, so inside the function it is equal to 0, which creates a blank sprite.


It still does the same thing even if I deifine it as global...

global ballImage = LoadImage("small_ball.png")


...did you try it paul?

The only thing that worked for me was using a clone instead of creating a sprite in the function (see my snippets above)

Am I the only one that the Global declaration doesn't work for???


Edit
Am I on the pay no mind list or are my posts not showing up?
Anybody????

Declaring the ballImage as global didn't work for me.
Posted: 1st Sep 2011 16:06
It does work if you do:
Global ballImage
ballImage = LoadImage("small_ball.png")

And that's good enough for me
Posted: 1st Sep 2011 16:09
allImage = LoadImage("small_ball.png")


Then what is wrong with

Global ballImage = LoadImage("small_ball.png")

I thought we could declare it as global on the same line as assigning the initial value.
Oh well, let me try that then, because I guess that was my mistake.
I had tried setting it to global before I saw his post, so that is why I thought he hadn't tried it yet.
I didn't know the global declaration had to be on a spearate line.

Thanks


Yeah that worked for me too.
I'll have to remember that thing about the Global being on a separate line.

Sorry guys, I was only trying to help.
Posted: 1st Sep 2011 17:11
I had this happen, when I used Creatsprite I had mispelt the image name.
Posted: 1st Sep 2011 19:10
i was just about to say that paul
Posted: 5th Sep 2011 4:58
When you assign a value to a global statement, the data value is used to initialise the variable before the program begins. I can see why the opposite might be assumed on reading your code. My gut feel is to throw up a compiler error if it finds a non-literal data value on the same line as a global declaration so you know what the compiler is thinking. If you can post this to the new issues board, we won't miss it during our fixes:

http://code.google.com/p/agk/issues/list