Working Only In Parts of the Screen?



  • So, a very nice person wrote this for me a while ago:

    http://pastebin.com/km4Rb6fm

    The only problem is is it works only in one section of the screen. The screen size itself is 1024x768. But the object only interacts with the rest of the game within the first 640x480.

    Any ideas how to get it to react with the rest of the screen?

    What I'm doing is trying to make a minimal rts. This is how the object is created:

              public var LoopSelect:SelectionBox;
    
                LoopSelect = new SelectionBox();
    	LoopSelect.scrollFactor.x = LoopSelect.scrollFactor.y = 0;
    	add(LoopSelect);
    

    Use:

            for (unit in PlayerScoutGroup.members)
    	{
    		
    		if (unit.overlaps(LoopSelect.target) )
    		{
    				unit.Selected = true;
    			
    			unit.color = 0xFF0000;
    		}
    	
    		if (FlxG.mouse.justReleasedRight && unit.Selected == true) 
    		{
    			unit.Selected = false;
    			FlxVelocity.moveTowardsObject(unit, mouseCon, zombieSpeed);
    			unit.color = 0x0000FF;
    		}
    	}
    

    Still on 3.55.



  • @xhunterko said in Working Only In Parts of the Screen?:

    SelectionBox()

    I can't see the exact problem. Most likely a mismatch between mouse.screenX/Y and scrollfactors. Can I see SelectionBox()?



  • It's here in the pastebin: http://pastebin.com/km4Rb6fm



  • Oh, silly me, actually checked that one, didn't notice it was the function I mentioned.

    You mean, that you cannot draw the selection box higher than 640x480, or that doesn't actually select your game objects? Are your objects using screen space or world space? Are those UI elements, or entities that move in a world?

    I'm more positive about a mismatch on that. Could you do a .gif to show the problem?



  • Sure. It's a bit long.

    http://www.newgrounds.com/dump/item/30a274d09f4e57636ca9e4277b269dd9

    See it draws across the screen fine. But it's interaction is limited. I added the scrollfactor to see if that'd help at all. I am not sure it did.

    The camera world size itself is 1024x768. The screen(window) size is 640x480.



  • You should probably replace FlxG.mouse.screenX/Y with just FlxG.mouse.x/y – screenX is the position of the mouse pointer in the game window, rather than in the world. Ah, and you'll want to keep scrollFactor at the default (1,1), since you want the selection box to be relative to the camera position ;)



  • Well.

    http://www.newgrounds.com/dump/item/5715e1714d73470cab67687297e070eb

    That occurs when the scrollfactor is 0, 1, or -1. I have been thinking. Right now I am going:

     public var mouseCon:FlxSprite
    
     //Have mouseCon "glued" to the mouse
    

    Then I am using the mouseCon as a mouse cursor.

    But, I've been thinking of instead, putting the mouseCon, in a class. Then I would do:

     class mouseCon extends FlxSprite
     {
      //etc
    }
    
     //Glue the mouseCon to the mouse the same way 
    

    Then, in selection box, instead of:

     startPos.x = FlxG.mouse.x;
     startPos.y = FlxG.mouse.y;
     etc
     endPos.x = FlxG.mouse.x;
     endPos.y = FlxG.mouse.y;			
     //endPos.y = FlxG.mouse.screenY;	
    

    It would be:

      SelectionBox
    
     Public Var Mouse:MouseCon
    
     startPos.x = Mouse.x;
     startPos.y = Mouse.y;
     etc
     endPos.x = Mouse.x;
     endPos.y = Mouse.y;			
     //endPos.y = FlxG.mouse.screenY;	
    

    Or would that not make a difference?



  • I don't think your idea will work, but hey, it's worth a try.
    Also, I noticed that the SelectionBox class resets scrollFactor to 0 every tick in its update() method... So if you haven't changed it in there, that's worth a try too.

    (oh, and a possibly stupid question: What exactly is the SelectionBox.target you check for overlaps with? It doesn't seem to ever be assigned a value :confused:)



  • Ah, it did something for the original as3 flixel version:

    http://forums.flixel.org/index.php?topic=4096.0

    But now it does nothing. And nuts, thought it'd fix something.

    Yes, I did remove that scrollfactor in the update. I thought since in the create wasn't working as thought, I might need to put it in the update.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.