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.

Newcomers AppGameKit Corner / Program can load one image but not the other?

Author
Message
Bobojo
8
Years of Service
User Offline
Joined: 16th Jun 2016
Location:
Posted: 18th Jan 2017 08:18
Hey guys I just started using AppGameKit tier 2 and I ran into this problem where I can load image 1, however I believe image 2 is not being loaded. When creating my sprite for image 1 the image appears. When creating the sprite for image 2, I receive the red x. The two pictures are in the same media folder and I'm using the exact same method of calling them. I'm sure this is a easy fix but I can't seem to find the solution. I'll put a snippet of my code down below. Sorry if my code burns anybody's eyes.

app App;
ball pong;
paddle lPaddle;
paddle rPaddle;

void app::Begin(void) {

// Creating window and background

agk::SetClearColor( 0,0,0 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
agk::SetOrientationAllowed(1, 1, 1, 1);
agk::SetDisplayAspect(1024/768);

// Load paddle and ball images
agk::LoadImage(0, "paddle.png");
agk::LoadImage(1, "pong.png");

}

int app::Loop (void) {


if (agk::GetOrientation() == 1 || agk::GetOrientation() == 2) {
agk::CreateText(0, "Please turn your device into landscape mode");
agk::SetTextPosition(0, 3.5, 45);
agk::SetTextColor(0, 255, 255, 255);
agk::SetTextSize(0, 3.5);

}

// If game is in landscape mode, use these parameters
if (agk::GetOrientation() == 3 || agk::GetOrientation() == 4) {
//Delete warning txt
agk:eleteText(0);

// If Paddle doesn't exist: create
if (agk::GetSpriteExists(lPaddle.iD) == false) {
lPaddle.iD = agk::CreateSprite(0);
agk::SetSpritePosition(lPaddle.iD, -30, 50);
agk::SetSpriteSize(lPaddle.iD, lPaddle.pWidth, lPaddle.pHeight);
}
if (agk::GetSpriteExists(rPaddle.iD) == false) {
rPaddle.iD = agk::CreateSprite(0);
agk::SetSpritePosition(rPaddle.iD, 125, 50);
agk::SetSpriteSize(rPaddle.iD, rPaddle.pWidth, rPaddle.pHeight);
}
if (agk::GetSpriteExists(pong.iD) == false) {
pong.iD = agk::CreateSprite(1);
agk::SetSpritePosition(pong.iD, 50, 50);
agk::SetSpriteSize(pong.iD, pong.bWidth, pong.bHeight);
}


// Make sure app stays in landscape mode
agk::SetOrientationAllowed(0, 0, 1, 1);
}

agk::Sync();

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Jan 2017 17:53
Is the second file "pong.png", or could it be "Pong.png".
File names are case sensitive on Android, Apple, Linux...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Bobojo
8
Years of Service
User Offline
Joined: 16th Jun 2016
Location:
Posted: 18th Jan 2017 20:40
They are both all lower case. It's strange because when it creates the sprite it will create "paddle.png" however when attempting to create pong.png it says "failed to create sprite, image 1 does not exist". (0 being image 1 and 1 being image 2).
Bobojo
8
Years of Service
User Offline
Joined: 16th Jun 2016
Location:
Posted: 18th Jan 2017 21:44
Something weird is up since I switched the two images and the second image is still the one not loaded. So it's not a problem with the image file but rather with the loadimage()? Sometimes the red x doesn't even show up.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Jan 2017 22:39
I'm not a Tier 2 coder so I didn't fully read the code. It may be that you have used image number 0, which is a special case. CreateSprite(0) creates a sprite with no image.
I realise your issue is with the second sprite but you may have broken something by loading image 0.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Bobojo
8
Years of Service
User Offline
Joined: 16th Jun 2016
Location:
Posted: 18th Jan 2017 23:15
Hmm I just tried changing them so they all start at the 1st index. I have the same problem as before... I tried to create an sprite on a new template and now it's not working at all even with a simple loadImage and create sprite. Could there be something wrong with my settings? I'm on Xcode 8.2.1 if that makes any difference. Thanks for taking the time to help me out btw
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Jan 2017 07:55
I'm out of my depth now, Tier 2 and X-code are not things I have dabbled with.
Hopefully somebody with experience in these areas can help.


One other test I can think of is to LoadImage and immediately SaveImage to see if it loaded. This will help work out if it is an image or sprite problem.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
damothegreat
User Banned
Posted: 19th Jan 2017 09:10
Try

if (agk::GetSpriteExists(rPaddle.iD) == false) {
rPaddle.iD = agk::CreateSprite( agk::LoadImage("paddle.png"));

agk::SetSpritePosition(rPaddle.iD, 125, 50);
agk::SetSpriteSize(rPaddle.iD, rPaddle.pWidth, rPaddle.pHeight);
}
if (agk::GetSpriteExists(pong.iD) == false) {
pong.iD = agk::CreateSprite( agk::LoadImage(1, "pong.png"));
agk::SetSpritePosition(pong.iD, 50, 50);
agk::SetSpriteSize(pong.iD, pong.bWidth, pong.bHeight);
}

Loading images from Loadimage() along into a pointer variable wont work in Tier 2... Load the image directly into the create sprite function

Let me know how get on

Damo



Using Tier 1 AppGameKit V2
Started coding with AMOS
Works with a Lenovo IdeaPad 700, 1TB SSD (Data), 128GB HD (System), 12GB Ram, GeForce Nvdia 950M, Windows 10, 2.3Ghz (Turbo to 3.2ghz when required)
Bobojo
8
Years of Service
User Offline
Joined: 16th Jun 2016
Location:
Posted: 19th Jan 2017 21:54
I finally got it thanks for all the help guys! I tried loading the image within the createSprite() but ended up with an error saying I couldn't find the paddle.png. It would still load which threw me off for a while. Then I added media/paddle.png and it worked out...

if (agk::GetSpriteExists(lPaddle.iD) == false) {
lPaddle.iD = agk::CreateSprite(agk::LoadImage("media/paddle.png"));
agk::SetSpritePosition(lPaddle.iD, -45, 50);
agk::SetSpriteSize(lPaddle.iD, lPaddle.pWidth, -1);

}

Login to post a reply

Server time is: 2024-11-25 03:13:59
Your offset time is: 2024-11-25 03:13:59