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 / SetSpritePosition - A new guy's quest to understanding through "Games&Graphics in C++"

Author
Message
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 2nd Dec 2016 01:23
Howdy folks. I hate to resort to taking up your time with what I'll expect to be a pretty lame question.

As in the title, I'm trying to work my way through the book "Games & Graphics in C++" (2nd edition).
It's been a chore. A huge tedious blood pressure raising chore, at the portion in which it wants to teach me AGK.
Code is not compatible and is likely written on an out of date platform, or simply not checked a'tall.
In fact it took me two after work evenings just to figure out why it couldn't find libraries.
I've muddled through a bit of it, but I've come to a complete brick wall for information here, now.

It wants me to change the position of a sprite, using of course, SetSpritePosition.
I've tried a few different ways to make it happen, but the sprite always stays in it's original location.
So I'm going to cave and ask some folks who know what they're doing for help.

Here's what I have to work with.
-----------------------------------------------------
// Includes
#include "template.h"

// Namespace
using namespace AGK;

app App;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

const int HOUSE_INDEX = 1;
const int GHOST_INDEX = 2;
const float GHOST_X = 200;
const float GHOST_Y = 150;

void app::Begin(void)
{
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);

agk::LoadImage(HOUSE_INDEX, "haunted_house.png");
agk::CreateSprite(HOUSE_INDEX);
agk::LoadImage(GHOST_INDEX, "ghost.png");
agk::SetSpritePosition(GHOST_INDEX, GHOST_X, GHOST_Y);
agk::CreateSprite(GHOST_INDEX);

}

void app::Loop (void)
{
agk::Sync();
}


void app::End (void)
{

}
----------------------------------------------
I've also tried
agk::SetSpritePosition(GHOST_INDEX, 200, 150);
I've also tried
agk::SetSpriteX(GHOST_INDEX, 200); same for Y.

I'm out of idea's and a forum search turned up less than helpful in this event.

Soo.. Where have I dum'd?

Thanks, guys!
Dave
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Dec 2016 10:35 Edited at: 2nd Dec 2016 10:38
I'm not a C++ coder, but I can see you set the position before you created the sprite.
The sprite must exist before you change its properties.

<EDIT> You might also find Lee Bamber's intro video useful - https://www.youtube.com/watch?v=upZpNwVgEXk
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 2nd Dec 2016 23:29
Thanks for getting back to me. I do appreciate it.
I've moved the line of code, but still get the same result of.. well the same result lol (Stays upper left)
I also tried setting raw co'ordinates.
agk::SetSpriteX(GHOST_INDEX, 200);
agk::SetSpriteY(GHOST_INDEX, 150);
and tried that again.
Is it possible I didn't link to something perhaps?
Nah that would generate a linking error I'd think..

I don't have much brain meat left tonight, so I'll hit up that video tomorrow when I'm fresh.
Skimming over it showed a few commands that I've not yet gotten across in my book, which, I'm starting to think might be useless and I'll simply have to go as you passively suggested, to third party guides.

Well, any suggestions in the mean time, I'll be happy to hear them.

And I do thank you again.
Dave

void app::Begin(void)
{
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);

agk::LoadImage(HOUSE_INDEX, "haunted_house.png");
agk::CreateSprite(HOUSE_INDEX);
agk::LoadImage(GHOST_INDEX, "ghost.png");
agk::CreateSprite(GHOST_INDEX);
agk::SetSpritePosition(GHOST_INDEX, 200, 150); <-- Moved to bottom, after image is called.

}
damothegreat
User Banned
Posted: 2nd Dec 2016 23:38 Edited at: 29th Jan 2017 20:32
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 3rd Dec 2016 22:13
I still get nothing.

The book hasn't gotten to getpointer anything yet, and is only trying to get me to make the picture go from upper left, to 200,150.
Hours of looking for help online (very limited) haven't shown me much, if anything, or anything different.

Otherwise, since I'm not yet familiar with getpointer, best I could do was move my setpos to loop..
Where of course, it does the same thing.

I also tried SetSpriteX and Y, with ghostindex, 200, etc, in main and loop.
Still the same thing.

void app::Loop (void)
{
agk::SetSpritePosition(GHOST_INDEX, GHOST_X, GHOST_Y);
agk::Sync();
}

Using Visual Studio for the lot, which means C++ and tier 2, so there is I'm sure some syntactical changes compared to tier 1.

But otherwise, my head has run into a wall, and I can't progress.
I have a worthless book. A terribly worthless book lol.
I imagine this will only get worse for me, when more advanced happenings come in, likely also, incorrectly.
I guess I'll have to throw in the towel on this one for now, and find a different approach to learning.
AGK is just smarter than I am right now.

I appreciate your help, folks. I really do.
Can't 'thank you enough for taking your time with me.
But I think I'm just going to be wasting it at this point.
damothegreat
User Banned
Posted: 3rd Dec 2016 22:26 Edited at: 29th Jan 2017 20:32
damothegreat
User Banned
Posted: 3rd Dec 2016 22:40 Edited at: 29th Jan 2017 20:32
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 3rd Dec 2016 23:22
Well, aighty.
I can do that.

You can get it at : nonetforyou.com/various/WASworking.zip
You'll have to leave out the www. I might've apache'd wrong somewhere.
It's just a random throw junk in to share folder anyway, so not really worth tweaking configs lol.

It'll extract to a folder with the same name.
'Bout 14 megs, no real meat to it.

Using visual studio community (so it's 2015).

(also can't see any of my recent replies. reckon just admin approval thingies.)

Anyways, thanks for sticking with me.
I'll return due diligence and press on if I can clear this hurdle.

I can say one thing, it's forcing me to remember things, arguing with this book for correct solutions lol
damothegreat
User Banned
Posted: 3rd Dec 2016 23:31 Edited at: 29th Jan 2017 20:33
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 4th Dec 2016 00:14
In 'teh C++, leaving functions (or prototypes) above main creates it as a global.
I can't call them into loop, unless they're global (above main: aka: app begin), just to clarify.
I don't know the full syntax to AGK::GLOBAL, or I might otherwise give it a shot... buuut...
I think I'm going to cry lol...
It still won't sing for me..

If I could get a functional cheat sheet to see where I am dumbing at, that would work wonders.
Whatever the answer is, I just know it's going to be dreadfully simple.
And I know I'm going to slap the !@#$ out of myself for not seeing it lol.
I'm also probably going to wind up rewriting this guys book, eventually, and posting it under his danged amazon page lol

#include "template.h"
using namespace AGK;
app App;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int HOUSE_INDEX = 1;
const int GHOST_INDEX = 2;
const float GHOST_X = 200.0f;
const float GHOST_Y = 150.0f;

void app::Begin(void)
{
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);

agk::LoadImage(HOUSE_INDEX, "haunted_house.png");
agk::CreateSprite(HOUSE_INDEX);

agk::LoadImage(GHOST_INDEX, "ghost.png");
agk::CreateSprite(GHOST_INDEX);
agk::SetSpritePosition(GHOST_INDEX, 200.0f, 150.0f);
agk::SetSpritePosition(GHOST_INDEX, GHOST_X, GHOST_Y);
(I've tried both of them, and I've tried them in loop. I've even tried them everywhere all at once because it's the equivalent of hitting it with a hammer lol)
}

void app::Loop (void)
{
(I had them here too, honest..)
agk::Sync();
}



Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 4th Dec 2016 14:05
Try calling agk::SetErrorMode( 2 ); at the top of the Begin.
This will kick an error and show you the problem.

Make sure you have a folder called media in the exe directory and put the image in it.
I believe the problem is with this line which should read like this.
agk::LoadImage(HOUSE_INDEX, "/media/haunted_house.png");



By default if AppGameKit cannot find the image to load it will continue on without crashing or showing the error unless you set the error mode.
The next line agk::CreateSprite(GHOST_INDEX); will do nothing because it never loaded the image.
Always set the error mode to 2 while writing code.

The coffee is lovely dark and deep,and I have code to write before I sleep.
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 4th Dec 2016 20:00
Well, definitely narrowing it down now lol.
Will absolutely include error mode from now on.

I am now when attempting to setspriteposition, getting sprite 2 does not exist.
Removing that line will load the images, now from media folder, and put that ghost right back in the default upper left of course, as I'm no longer setting position.

Now the question posed to me is.. why no werkey? Am I settingposishuneng wrong?

#include "template.h"
using namespace AGK;
app App;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int HOUSE_INDEX = 1;
const int GHOST_INDEX = 2;
const float GHOST_X = 200.0f;
const float GHOST_Y = 150.0f;

void app::Begin(void)
{
agk::SetErrorMode(2);
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);
//agk::SetFolder("/media") <-- learned about this here just now, too.
agk::LoadImage(HOUSE_INDEX, "/media/haunted_house.png");
agk::CreateSprite(HOUSE_INDEX);
agk::LoadImage(GHOST_INDEX, "/media/ghost.png");
agk::CreateSprite(GHOST_INDEX);
(things I tried)
//agk::SetSpritePosition(GHOST_INDEX, GHOST_X, GHOST_Y);
//agk::SetSpritePosition(GHOST_INDEX, 200.0f, 150.0f);
//agk::SetSpriteX(GHOST_INDEX, GHOST_X);
//agk::SetSpriteY(GHOST_INDEX, GHOST_Y);
(end things I tried)
agk::SetSpriteX(GHOST_INDEX, 200.0f);
agk::SetSpriteY(GHOST_INDEX, 150.0f);
}

Thanks for hanging in with me guys.
damothegreat
User Banned
Posted: 4th Dec 2016 20:31 Edited at: 29th Jan 2017 20:33
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 4th Dec 2016 20:48
Nah, that won't work in C languages.
\ is used to indicate an escape sequence, such as \n newline \t tab, etc.
(eg cout << "Hello I'm\n" << "on a new line.";
/ has to be used for file paths.

As it stands, the images WILL Load, if I'm not attempting to set position.
It's when I tell it to set position, it somehow, suddenly thinks the sprite doesn't exist.

Confusing thing is confusing lol
damothegreat
User Banned
Posted: 7th Dec 2016 22:09 Edited at: 29th Jan 2017 20:33
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 7th Dec 2016 23:48
I'm actually pleasantly surprised.
I wasn't about to pry on the matter.

Haven't 'had much time myself to tinker with it, this (last)week. Mandatory emissions tests coming up and I'm weathering through a lot of tune-up/replacement parts.
Can't gripe too much. I stretched factory gear out for ten years, but things' is gett'n a bit expensive.. Probably because I stretched factory parts out for ten years.

I was wondering if I'd missed a library or some such, but did not seem to be the case.
I'll step by step start over with a new project config this weekend, in case I did miss something, though I'm certain the thing would have yelled at me.

Thanks for hangin' in there with me.
Don't put yourself out too hard though. I know you've got your own projects to deal with, so I won't do any *pokes* *bumps* lol

I have been itching to get back to the learnin.
damothegreat
User Banned
Posted: 8th Dec 2016 00:14 Edited at: 29th Jan 2017 20:33
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 8th Dec 2016 01:44
GREAT SUCCESS!!
I did tweak it a bit to finally duplicate what the dang book wanted me to do.
I've not not only learned how to do what that thing said, I've learned a better way to call images, AND, a little bit about GetPointer!

Thank you SOOOOOO much for getting my head screwed back on right lol
I'd buy you a beer if I could, but I can't, so lots of thanks instead!

WOOHOO!
I can go back to learnin things!

THANKYOUTHANKYOUTHANKYOUTHANKYOUTHANKYOU

(If I did the snippet thing right)
damothegreat
User Banned
Posted: 8th Dec 2016 08:56 Edited at: 29th Jan 2017 20:33
Methlon
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location:
Posted: 9th Dec 2016 00:27
Will do for sure.
Glad to see I inadvertently returned the favor lol

When I get a good fresh brain going again, I'm sure this'll be my Saturday morning.
Thanks again!

Login to post a reply

Server time is: 2024-11-24 15:30:41
Your offset time is: 2024-11-24 15:30:41