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 / Can someone help me look at my code?

Author
Message
nickydemon
4
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 20th Nov 2018 10:20
I am using tier2 to create a space ship game. I have the constructor of my player class that set its position to middle of the screen but it just appear at left top. Also, i wrote a move function for my player class but it just doesnt move.

template.h



template.cpp



Player.h


Player.cpp

Ortu
DBPro Master
11
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 20th Nov 2018 18:09 Edited at: 20th Nov 2018 18:11
I'm not much familiar with c++ syntax, but in most languages y could be considered a local variable here:

void Player::move_up()
{
y -= move_speed;
}

And needs something like this to indicate you are referring to the player y

void Player::move_up()
{
this.y -= this.move_speed;
}

Would explain why your move functions are having no effect.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 21st Nov 2018 06:36
Hi,

here you should load an image, not a Sprite.

template.cpp (line: 18)

Change to ...


Maybe this will help
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
nickydemon
4
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 21st Nov 2018 08:42
Hi Ortu and MadBit, thank you for your help.

Madbit, you were right I should use LoadImage instead of LoadSprite. But I don't understand what is the difference between these two commands.
c0d3r9
1
Years of Service
User Offline
Joined: 2nd Oct 2017
Location:
Posted: 21st Nov 2018 12:35 Edited at: 21st Nov 2018 12:36
Because you create in yuzr player constructure a sprite with CreateSprite(image). And it needs an image and not a sprite.
I think you can not create a sprite with the handle of another sprite.
MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 21st Nov 2018 12:58
LoadImage

LoadSprite


You can also use an image as texture for 3D objects.
In addition, the ID mapping are separated between sprites and images. Image ID 1 does not necessarily have to be equal to Sprite ID 1.
If you load a sprite directly, no image ID will be created.

In the program you showed us. Loads a sprite without creating an image ID. Then you try to create another sprite with an image ID that does not exist. All movements then refer to the sprite which could not be created because the image ID was missing.

I hope this gives you a little more clarity.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2019-09-18 13:09:18
Your offset time is: 2019-09-18 13:09:18