Object - Mouse - Graphic Image. (Solved)

Started by Dualnames, Sat 06/02/2010 21:02:46

Previous topic - Next topic

Dualnames

I'm wondering how is it possible to get an object's graphic image, even if scaled and put it into the mouse?
I have no idea on how to actually handle the scaling thing. I've searched a bit, but I'm really into a dead-end. I'm sure it's something really obvious but for the life of me i can't really see it.

I want to:
1)Get the image the object has (even scaled or somehow find a way to scale it (apparently with function DynamicSprite.Resize I guess))
2)Put it into the mouse image, or even better constantly update an inventory item's cursor image (if that's possible by the Engine)

I think the best way would be to get the area scaling by GetWalkableArea(object.X-1,object.Y); function?

What exactly you want to do Dualnames?

Ethan said
Quote from: Ethan Damschroder on Sat 06/02/2010 21:25:54
I'm a little confused by what your asking.  But if you just want to set the mouse sprite to what a certain object's sprite is then this should work:

mouse.ChangeModeGraphic(eModeInteract, object.Graphic);

Just use whatever name you have for the object and whatever mode you want to change.  

I could be way off on what your asking though...  :-\

And replying to that:

QuoteWhat you're suggesting will indeed do half of what I want. But it doesn't access the image the object is having if it's like scaled 120%, but instead finds the 100% size of that image, because .Graphic property redirects to the sprite manager sprite slot.

Plain:

object graphic: sprite 1 != object graphic sprite 1 if object scale is !=100%

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ethan D

I'm a little confused by what your asking.  But if you just want to set the mouse sprite to what a certain object's sprite is then this should work:

mouse.ChangeModeGraphic(eModeInteract, object.Graphic);

Just use whatever name you have for the object and whatever mode you want to change. 

I could be way off on what your asking though...  :-\

Dualnames

What you're suggesting will indeed do half of what I want. But it doesn't access the image the object is having if it's like scaled 120%, but instead finds the 100% size of that image, because .Graphic property redirects to the sprite manager sprite slot.

Plain:

object graphic: sprite 1 != object graphic sprite 1 if object scale is !=100%
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ethan D

#3
So are you wanting the sprite that the mouse is using to change size while the mouse is moving? (If you move the mouse up then the image gets smaller)

Sorry for my lack of understanding  ;)

EDIT: Best I can tell right now I don't think scaling can affect things other than objects and character but I'll keep looking.

EDIT AGAIN:  Guess I was wrong!   :'(

monkey0506

#4
Like this:

Code: ags
// outside of all functions
DynamicSprite *cursorSprite = null;

void ChangeModeGraphicToObjectGraphic(this Mouse*, CursorMode mode, Object *theObject) {
  if ((mode < 0) || (mode >= Game.CursorModeCount)) AbortGame("You gave me an invalid cursor mode you jerk...what were you thinking??");
  if (theObject == null) AbortGame("What am I supposed to do with this? You didn't give me an object to work with...HUMANS, ugh!!");
  if ((cursorSprite != null) && (mouse.GetModeGraphic(mode) == cursorSprite.Graphic)) {
    mouse.ChangeModeGraphic(mode, 0);
    cursorSprite.Delete();
    cursorSprite = null; // just because
  }
  int graphic = theObject.Graphic;
  if (theObject.View) {
    // I'm actually not 100% sure if the Graphic property reflects the current graphic if a view is set
    // this method makes sure we get the current graphic
    ViewFrame *frame = Game.GetViewFrame(theObject.View, theObject.Loop, theObject.Graphic);
    graphic = frame.Graphic;
  }
  int scale = GetScalingAt(theObject.X, theObject.Y);
  if ((!theObject.IgnoreScaling) && (scale != 100)) {
    cursorSprite = DynamicSprite.CreateFromExistingSprite(graphic, true);
    int width = (Game.SpriteWidth[graphic] * scale) / 100;
    int height = (Game.SpriteHeight[graphic] * scale) / 100;
    cursorSprite.Resize(width, height);
    graphic = cursorSprite.Graphic;
  }
  mouse.ChangeModeGraphic(mode, graphic);
}

// wherever
mouse.ChangeModeGraphicToObjectGraphic(mouse.Mode, object[OBJECT_ID]);


The DynamicSprite only gets used if necessary (if scaling is applied) so it's even optimized a bit. :P

Edit: I changed it into a function to make it more flexible. You can modify the error handling (to be more human- user-friendly) if you wish. ::)

Dualnames

#5
Quote from: Ethan Damschroder on Sat 06/02/2010 21:42:50
So are you wanting the sprite that the mouse is using to change size while the mouse is moving? (If you move the mouse up then the image gets smaller)

Sorry for my lack of understanding  ;)

It's ok, I knew it was a little hard to explain exactly so, glad you managed to. I did some edit on my first post, to help out people. :D

EDIT: Wow monkey!

EDIT2: Wow AGS Engine!

I got this:
Error: LoadRoom: unexpected end of file while loading room
Version: AGS 3.1.2.81

Code: ags

AGS.Types.AGSEditorException: LoadRoom: unexpected end of file while loading room
   at ThrowManagedException(SByte* message)
   at load_room_file(SByte* )
   at load_crm_file(UnloadedRoom roomToLoad)
   at AGS.Native.NativeMethods.LoadRoomFile(UnloadedRoom roomToLoad)
   at AGS.Editor.Components.RoomsComponent.LoadNewRoomIntoMemory(UnloadedRoom newRoom, CompileMessages errors)
   at AGS.Editor.Components.RoomsComponent.LoadDifferentRoom(UnloadedRoom newRoom)
   at AGS.Editor.Components.RoomsComponent.LoadRoom(String controlID)
   at AGS.Editor.Components.RoomsComponent.CommandClick(String controlID)
   at AGS.Editor.ProjectTree.ProcessClickOnNode(String nodeID, MouseButtons button)
   at AGS.Editor.ProjectTree.projectTree_NodeMouseDoubleClick(Object sender, TreeNodeMouseClickEventArgs e)
   at System.Windows.Forms.TreeView.OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
   at System.Windows.Forms.TreeView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


It has to do with compiling because the code worked initially..
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

Try clicking "Build -> Rebuild all files" and see if any compile errors crop up that way. I can't think of any reason you would get a run-time EOF for a room script and not get a compile-time error...unless you externally modified the room's ASC file and the editor didn't detect the script as having changed...or something.

Dualnames

#7
Quote from: monkey_05_06 on Sat 06/02/2010 22:01:14
Try clicking "Build -> Rebuild all files" and see if any compile errors crop up that way. I can't think of any reason you would get a run-time EOF for a room script and not get a compile-time error...unless you externally modified the room's ASC file and the editor didn't detect the script as having changed...or something.

It has to do with something Crimson said on the AGS RC 3 Topic. It's a bug for AGS 3.2.1. too as it seems though. And I've reproduced again twice.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Dualnames

#8
Sorry for the double post, but it's a sort of a bump.


EDIT: Solved.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

Glad to hear you got it sorted. You removed that function you were asking about, but I didn't really see any major points of optimization that jumped out at me...

What it all really boils down to with the script though is just knowing how to speak to the engine and let it know what you want. It's very easily persuaded if you know the right words... :D

Dualnames

Quote from: monkey_05_06 on Mon 08/02/2010 03:07:25
Glad to hear you got it sorted. You removed that function you were asking about, but I didn't really see any major points of optimization that jumped out at me...

What it all really boils down to with the script though is just knowing how to speak to the engine and let it know what you want. It's very easily persuaded if you know the right words... :D

I know, and to say, well, I did some changed so the code ended up useless..(:P). I just get a headache when I'm working scripts for a certain downfalled individual!  :D

Thanks anyway, Monkey!
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk