confused..

This topic contains 3 replies, has 2 voices, and was last updated by  davidthecoder 2 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
February 9, 2012 at 8:29 am #239044

davidthecoder
Participant
@davidthecoder

okay I’m not the best programmer and I’m still in the process of learning, I’ve been looking this over and i haven’t figured out whats wrong with it and i was hoping maybe somebody could point something out to help me out a bit.

I am trying to get a object to spawn after a collision but after the collision it doesn’t spawn

sprite = (Sprite*) [self getChildByTag:kSpriteTagValue];

if (sprite != nil) {
if ([sprite characterState] == kstateChanging)
{
[self createAtLocation:ccp(150,150)];

CCLOG(@"spawned...");
}
}

hmmm… i also ran the test below (changed to check if it wasn’t equal, !=)..

sprite = (Sprite*) [self getChildByTag:kSpriteTagValue];

if (sprite != nil) {
if ([sprite characterState] != kstateChanging)
{
[self createAtLocation:ccp(150,150)];

CCLOG(@"spawned...");
}
}

the test shows the sprite spawning correctly!

I’m confused because when the characterState of the sprite does = KstateChanging the sprite does not spawn…

The output shows me a message saying that the characterState has changed to KstateChanging.

Please go easy on me I’m still a beginner and any help would be wonderful. Thank you :)

February 9, 2012 at 9:06 am #364921

breskit
Participant
@breskit

if (sprite == nil) is true then the sprite object will not exist and therefore none of the properties will exist, so you would not have access to the characterState property.

So [sprite characterState] != kstateChanging would always be true, so your second test would actually work.

February 9, 2012 at 9:27 am #364922

davidthecoder
Participant
@davidthecoder

AH! my bad i actually had if(sprite != nil). I didn’t copy it correctly but i just updated it.

do you know what could be making the [sprite characterState] == kstateChanging not work?

KstateChanging is activated when a collision happens but for some reason it doesn’t see it…

i have another question, what would be the best way to make an object spawn after a collision?

February 9, 2012 at 9:55 am #364923

davidthecoder
Participant
@davidthecoder

i got it to work Correctly, i had that chunk of code in the wrong place.

this has been solved.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.