Author Topic: Possible Bug (i have no github, sorry)  (Read 1587 times)

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Possible Bug (i have no github, sorry)
« on: Wed, Nov 16, 2011 »
So, I think there may be a bug in the update somewhere.

The problem occurs in the same way as I made my forum post about my level edtior. If I want to create an object at update, I not only have to create it at create the create state, but in the update too. Usually, if I don't want the object created at create used, I just call kill on it. Now, in the update, whenever I use

if (something)

object = new objectclass(0,0);
add(object);


Now, whenever I call object.kill(), and there's four or five of the same type, only the last object created will have the kill code called on it. Not any of the others. I've watched this and checked to see if whether or not it was flixel power tools fault or flixels fault. Both the extended sprites and the regular sprites have this issue. In the watch, I was clued into that the exists flag was set to false after each creation and the newest one was on. So, I set the class exist to true at anytime, and the issue still manifested itself. So, I don't know what I'm doing wrong here. So it could be a bug or something.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

goshki

  • Active Member
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
    • Vigeo Games
Re: Possible Bug (i have no github, sorry)
« Reply #1 on: Thu, Nov 17, 2011 »
I'm not sure if I understand you well so I'll recap: you create several objects calling object = new objectclass(0,0); in your PlayState.update() and add them to the state. Then you call object.kill() and you expect that all of them get killed. Is that right?

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: Possible Bug (i have no github, sorry)
« Reply #2 on: Thu, Nov 17, 2011 »
I was trying to create a level editor.  I had the following working:

-Have a menu icon (let's call it a key:keyclass object)
-Click the menu icon to attach an object to the mouse (the same object)
-Click anywhere on the playstate to create a representive object (key1:keyclass)

Not working:
-Moving the mouse over an object and pressing a key to delete any of the single key1 objects, instead, only the last key1 object created is deleted.
-Killing all at once by key press was an idea but that didn't work either. For a quick clear of the room

Here's what I'm trying to do in code:

-Bare bones basic example
Code: [Select]
package 
{

import org.flixel.*;
import org.flixel.plugin.*;


public class TitleScreen extends FlxState
{
//The mouse Icon
private var mouseCon:FlxSprite;

//The object that is placed
public var key:Key;
public var key1:Key;

override public function create():void
{
key = new Key(0, 0);
add(key);

                        //creating the key1 at start so Flixel doesn't throw a hissy fit
key1 = new Key(0, 0);
add(key1);
                        key1.kill()


}

override public function update():void
{
if (FlxG.mouse.justReleased())
{
key = new Key(FlxG.mouse.x, FlxG.mouse.y);
add(key);
}

if (FlxG.keys.D && mouseCon.overlaps(key))
{
key.kill();

}

super.update();


}



}

}
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha

goshki

  • Active Member
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
    • Vigeo Games
Re: Possible Bug (i have no github, sorry)
« Reply #3 on: Thu, Nov 17, 2011 »
Take a look at the source-code of Game Saves demo at http://flixel.org/features.html.

Especially those lines in the update() method show how to detect currently mouse-clicked object:
Code: [Select]
if (FlxG.mouse.justPressed()) {
for each(var a:FlxButton in boxGroup.members) {
if (a.status == FlxButton.PRESSED) {
dragOffset.x = a.x - FlxG.mouse.x; //The offset is used to make the box stick to the cursor and not snap to the corner
dragOffset.y = a.y - FlxG.mouse.y;
dragging = true;
dragTarget = a;
}
}
}

The bottom line is: you've got to have an array of all created objects and an auxilliary variable that stores the target object.

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: Possible Bug (i have no github, sorry)
« Reply #4 on: Fri, Nov 18, 2011 »
Hmm. ok. I think I know how to do that. I have that in an earlier project. I'll give that a try. Thanks.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha