disposed sprite once again <.< [Resolved] type error FTW

Started by Apidcloud, March 28, 2011, 01:06:47 pm

Previous topic - Next topic

Apidcloud

Hey there XD

I've created a class that is 'son' of Sprite class.

The class simply does some src's and that so I don't need to do the process to all the pictures <.<
But, when using:
@variable = Bitmap.new(200, 200)
self.bitmap = @variable


Well, when im going to enter the game, it appears' Disposed sprite' <.<

Can someone help me? xD Blizzard helped me once with this but its giving me error on this class now lol
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

Where are you doing this? In initialize? In that case you should first call super.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

Yes, with super it works <.< But I don't understand why I need super lol
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

When you call "super", the superclass' method with the same name is called. Before you call the initialize method of Sprite, it is considered non-existent (and disposed). If you try to assign a bitmap to a disposed Sprite instance, you get an error, that's why you first have to call the initialize method of Sprite through "super".
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

so, basically, am i calling initialize method from Sprite class? (by using super in this especiafically case)
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

Yes. You should always call super if you derive from a class and override an already existing method (such as initialize).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

hmm...I see...imagine that a class have 2 arguments.
If I use super in a 'son' class, then it will be with the same 2 arguments right?
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

Yes. Though you can change the number of arguments in the method of the derived class, the superclass' method still needs to be called with the proper number of arguments through super. Just keep in mind that for 0 arguments you have to call explicitly "super()". Calling "super" calls the supermethod with the exact same arguments that you got in the current method.

BTW, it's called child class.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

Well xD, in this case of Sprite, my super is 'super(nil)' xD

So, in the arguments, I just do as i do in a window... xD ok I think I finally get it now xD


thanks a lot, and for 'child class' information xD
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Jragyn

I know this is fully resolved, but I read it and I am just impressed with Blizzard's knowledge and patience to explain in ways you can understand. If there was a facebook-like button, Blizzard, you'd be pretty popular in my book by now XD
A bright light can either illuminate or blind, but how will you know which until you open your eyes?