Actor changing glitch

toaster

  • Posts: 21
Hello, I'm working on a game where you collect items, which causes the character to change to a different actor every point scored.  However, when I collect an item, it the character changes, but doesn't seem to work.  Here is the code I made for changing character.  Can anyone tell me what I am doing wrong? Thank you.
http://imgur.com/i3QKf

rob1221

  • *
  • Posts: 9472
Try creating the new actor before killing self.

toaster

  • Posts: 21
I tried that, but it still keeps freezing.

rob1221

  • *
  • Posts: 9472
If it's freezing, I suspect the problem is overlapping collision shapes.  I experienced that in a game I'm working on, and I got around it by changing the previous actor's animation to one with no collision shape 0.02 seconds before creating the new actor and killing self.

Nomosoft

  • Posts: 122
Does it need to be a different actor? What if you just made a bunch of different animations for one actor, and enabled/disabled/set the variables for any behaviors after switching the animation?

toaster

  • Posts: 21
@rob1221 I'm not too good at Stencyl, do you think you can post a picture of what it would look like?

@Nomosoft It probably doesn't, but I'm using the default Run and jump kit, would that work with it?

rob1221

  • *
  • Posts: 9472
It's pretty simple really.  When the player's death is triggered, switch animation, and then after 0.02 seconds create the new actor and kill self.

toaster

  • Posts: 21
Can you tell me what I'm doing wrong?  I tried and got this error

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at stencyl.api.engine.actor::Actor/getX()[/Users/jon/Desktop/stencyl/plaf/flash/root/stencyl/api/engine/actor/Actor.as:1432]
   at Function/<anonymous>()[C:\Program Files (x86)\StencylWorks\preview\scripts\Design_219_219_LevelUp.as:45]
   at stencyl.api.engine::TimedTask/update()[/Users/jon/Desktop/stencyl/plaf/flash/root/stencyl/api/engine/TimedTask.as:40]
   at stencyl.api.engine::GameState/innerUpdate()[/Users/jon/Desktop/stencyl/plaf/flash/root/stencyl/api/engine/GameState.as:1461]
   at stencyl.api.engine::GameState/postUpdate()[/Users/jon/Desktop/stencyl/plaf/flash/root/stencyl/api/engine/GameState.as:1395]
   at stencyl.api.engine::GameState/update()[/Users/jon/Desktop/stencyl/plaf/flash/root/stencyl/api/engine/GameState.as:1377]
   at org.flixel::FlxGame/update()[/Users/jon/Desktop/stencyl/plaf/flash/flixel/org/flixel/FlxGame.as:400]

This is my code: http://imgur.com/EUwzW

rob1221

  • *
  • Posts: 9472
If you're going to do that under "Always" you need to use a boolean to stop the blocks from executing more than once.

toaster

  • Posts: 21
i changed it to "when this collides with something else" then added a block to execute only if it collides with another actor, and it seems to work.  Thank you for help.