473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple question about using += (sorry about posting in the wrong group)

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

Mar 25 '06 #1
10 1699
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!!!
Mar 25 '06 #2
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.
Mar 25 '06 #3
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...
}
}

Mar 25 '06 #4
to**********@hotmail.com wrote:
ok thanks for the info, this is my first post.
Have a read of <http://cfaj.freeshell.org/google/> if you are using google.
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.

class CAnimation
{
private:
int frame; //identifier for current
I expect this should be

static int frame;

Somewhere in your code you will have:

int CAnimation::frame = 0;
sprite
char Sprites[2][25] //Array to hold image
filenames

public:
CAnimation( ); //Constructor
Avoid self evident comments, they add nothing.
};

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


Or just ++frame;

--
Ian Collins.
Mar 25 '06 #5
Thanks for your post Ian, I tried the modifications that you mentioned
but it still does not increment properly, Any more ideas?

Mar 27 '06 #6
to**********@hotmail.com wrote:
Thanks for your post Ian, I tried the modifications that you mentioned
but it still does not increment properly, Any more ideas?


First, please try to include some context. If you are posting from
google, click the "show options" link and then click the "reply"
link that shows up after that. That way you get quoted text.

Next, in what way "does not incremetn properly?" It's hard to
know what you want it to do, and what it does instead. Specially
since you didn't show the code you used, and didn't say what
you wanted it to do.
Socks

Mar 27 '06 #7
to**********@hotmail.com wrote:
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...
}
}


Mar 27 '06 #8
to**********@hotmail.com wrote:
Thanks for your post Ian, I tried the modifications that you mentioned
but it still does not increment properly, Any more ideas?

Care to elaborate, with code?

Please quote context in your reply.

--
Ian Collins.
Mar 27 '06 #9

Ian Collins wrote:
to**********@hotmail.com wrote:
Thanks for your post Ian, I tried the modifications that you mentioned
but it still does not increment properly, Any more ideas?
Care to elaborate, with code?

Please quote context in your reply.

--
Ian Collins.


The outcome is the same as the original way I had coded. The result is
that the second image in the array is loaded. I am after it to run
through all the filenames so as to create the animation. Lets say I add
extra images, it still wont continually increase the variable, frame.
private:
static int frame;
char Sprites[2][25]
public:
CAnimation( );


CAnimation( )::CAnimation( )
{
char Sprites[4][25] = {"image1.tga", "image2.tga", "image3.tga",
"image4.tga};
frame = 0;
++frame;
}
// frame should go, 0,1,2,3,4,etc...
// instead it now equals 1

I tried using a for loop but no joy
Thanks

Mar 27 '06 #10
to**********@hotmail.com <to**********@hotmail.com> wrote:
The outcome is the same as the original way I had coded. The result is
that the second image in the array is loaded. I am after it to run
through all the filenames so as to create the animation. Lets say I add
extra images, it still wont continually increase the variable, frame.
private:
static int frame;
char Sprites[2][25]
public:
CAnimation( );
CAnimation( )::CAnimation( )
{
char Sprites[4][25] = {"image1.tga", "image2.tga", "image3.tga",
"image4.tga};
frame = 0;


Here, you always reset frame to 0 before incrementing it, so you always
get 1.
++frame;
}
// frame should go, 0,1,2,3,4,etc...
// instead it now equals 1

I tried using a for loop but no joy
Thanks


--
Marcus Kwok
Mar 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fishboy | last post by:
Howdy, Sorry if this is a double post. First try seemed to go into hyperspace. I'm working on a personal project. It's going to be a multipart binary attachment downloader that will search...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
12
by: =?Utf-8?B?Q2Fubm9kYWwxOQ==?= | last post by:
I'm having a problem getting the accurate information to the guide.. Its saying its soposted to be this one show, and its somthing else.. I've double check my setting for what general area, and I...
3
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.