关于使用+ =的简单问题(抱歉在错误的组中发帖) [英] Simple question about using += (sorry about posting in the wrong group)

查看:58
本文介绍了关于使用+ =的简单问题(抱歉在错误的组中发帖)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有一个类,其私有成员变量名为''int frame''。

然后我有一个构造函数将它设置为0.现在,在

构造函数中我想通过使用:frame + = 1来增加它;


我使用框架来加载图像从一个创建动画的数组。

但是,当在构造函数或任何成员声明上面的内容时,它没有正确递增。它将会增加一个但不会继续增加。


如果有人知道如何做到这一点会有很大的帮助。

谢谢

Jay

解决方案

todd_montana写道:


我有一个类,它有一个名为''int frame''的私有成员变量。
然后我有一个构造函数将它设置为0.现在,在
构造函数中我想增加它通过使用:frame + = 1;




我怀疑你不理解构造函数。


然而,我不知道,因为你没有发布任何代码。请阅读这个

欢迎信息......

http://www.slack.net/~shiva/welcome.txt


....然后再次发布(不道歉)并且有一些代码,所以我们可以

查看它。


我们喜欢代码。


-

Phlip
http://www.greencheese.org/ ZeekLand < - 不是博客!!!


到********** @ hotmail.com 写道:

你好,

我有一个班级有私有成员变量名为''int frame''。
然后我有一个构造函数将其设置为0.现在,在
构造函数中我想通过使用:frame + = 1; <来增加它br />
我正在使用框架从创建动画的数组中加载图像。
然而,当dec在构造函数或任何成员内部执行上述操作,它不会正确增加。它会增加一个但不会继续增加它。

如果有人知道如何做到这一点会有所帮助。




发布示例!


-

Ian Collins。


好的谢谢对于这些信息,这是我的第一篇文章。

这里是类和构造函数。这个想法是这样的:一旦我初始化

变量''frame''

和文件名数组,我使用构造函数来设置我的

纹理和绑定。这意味着当我创建

类的实例时,它将允许我有多个精灵,所有精灵都可以生成

相同。


注意:如果我在main()中有一个变量,那就像

这样增加:Frame + = 1;

然后我将它传递给输入参数到构造函数,

精灵将正确动画,但我不想传入它,如果有另外的方式



class CAnimation

{

private:

int frame; //当前的标识符

sprite

char Sprites [2] [25] //保存图像的数组

文件名


public:

CAnimation(); //构造函数

};


CAnimation():: CAnimation()

{

char Sprites [2] [25] = {" image1.tga"," image2.tga"};

frame = 0;

frame + = 1;


//将加载的图像取决于帧变量

if(STGAInstance.loadTGA(Sprites [frame]))

{

//使用openGL生成并绑定纹理...

}

}


Hi there,

I have a class that has the private member variable called ''int frame''.
I then have a constructor that sets it to 0. Now, inside the
constructor i want to increment it by using: frame += 1;

I am using frame to load images from an array that creates animation.
However, when declaring the above inside the constructor or any member
function for that matter, it doesnt increment properly. It will
increase by one but not continue like it should.

If anyone knows how I can do this it would help a lot.
Thanks
Jay

解决方案

todd_montana wrote:


I have a class that has the private member variable called ''int frame''.
I then have a constructor that sets it to 0. Now, inside the
constructor i want to increment it by using: frame += 1;



I suspect you don''t understand constructors.

However, I don''t know, because you didn''t post any code. Please read this
welcome message...

http://www.slack.net/~shiva/welcome.txt

....then post again (without apologies) and with a little code so we can
review it.

We like code.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


to**********@hotmail.com wrote:

Hi there,

I have a class that has the private member variable called ''int frame''.
I then have a constructor that sets it to 0. Now, inside the
constructor i want to increment it by using: frame += 1;

I am using frame to load images from an array that creates animation.
However, when declaring the above inside the constructor or any member
function for that matter, it doesnt increment properly. It will
increase by one but not continue like it should.

If anyone knows how I can do this it would help a lot.



Post an example!

--
Ian Collins.


ok thanks for the info, this is my first post.
here is the class and constructor. The idea is this: Once I initialize
the variable ''frame''
and the filenames array, I use the constructor to also setup my
texturing and binding. This means that when I create instances of the
class, it will allow me to have multiple sprites that all animate the
same.

NOTE: If I have a variable in the main( ), that is incrememnted like
this: Frame += 1;
And then I pass it as an input parameter to the constructor, the
sprite will animate correctly, but I dont want to pass it in if there
is another way.
class CAnimation
{
private:
int frame; //identifier for current
sprite
char Sprites[2][25] //Array to hold image
filenames

public:
CAnimation( ); //Constructor
};

CAnimation( )::CAnimation( )
{
char Sprites[2][25] = {"image1.tga", "image2.tga"};
frame = 0;
frame += 1;

//The image that will be loaded depends on the frame variable
if (STGAInstance.loadTGA(Sprites[frame]))
{
//Generate and bind Texture using openGL...
}
}


这篇关于关于使用+ =的简单问题(抱歉在错误的组中发帖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆