Skip to main content

News

Topic: How do you change character walking speed with AttachInput? (Read 8326 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Mooch
  • [*][*][*]
How do you change character walking speed with AttachInput?
I'm slapping together a town planner/designer tool for Harvest Moon: Magical Melody. It's basically the entire map of the game, and you'll be able to place rocks and trees and grass and stuff, to plan out how you want to design your town.

Since it's a simple thing, I'm not doing anything fancy -- I'm just using AttachInput to let the user scroll around the map. The default walking speed is stone-slow, however. Is there a way to change it, or do I have to use a custom movement script? I Searched the API, Wiki and forum and couldn't find anything.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: How do you change character walking speed with AttachInput?
Reply #1
This is what you need.  Speed is in pixels per frame (with subpixel precision).

Code: (text) [Select]

SetPersonSpeed(name, speed);
SetPersonSpeedXY(name, new_speed_x, new_speed_y);
GetPersonSpeedX(name);
GetPersonSpeedY(name);

  Gets or sets the person's speed in two dimensions. SetPersonSpeed(name, speed)
  is shorthand for SetPersonSpeedXY(name, speed, speed).
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Mooch
  • [*][*][*]
Re: How do you change character walking speed with AttachInput?
Reply #2
Thanks! That is not on the Wiki, haha.

Another two quick questions, rather than make a whole 'nother topic -- how do I manage the depth of images? There's no z-coordinate in the arguments. Trying to manage the HUD.

And is there an option somewhere that I'm missing to enable the mouse cursor? Or do I just have to draw an image at the cursor location using GetMouseX/Y and images?

Re: How do you change character walking speed with AttachInput?
Reply #3

Thanks! That is not on the Wiki, haha.

Another two quick questions, rather than make a whole 'nother topic -- how do I manage the depth of images? There's no z-coordinate in the arguments. Trying to manage the HUD.


You will usually just render an image last to show it on top over everything. In a way, the Z coordinate is just the order you draw things. If you are using the map engine, be sure you are drawing via SetRenderScript rather than SetUpdateScript.


And is there an option somewhere that I'm missing to enable the mouse cursor? Or do I just have to draw an image at the cursor location using GetMouseX/Y and images?


Yes, you will usually just draw your own cursor.

  • Mooch
  • [*][*][*]
Re: How do you change character walking speed with AttachInput?
Reply #4
Ah, dang. I thought I remembered Z-control of images. Guess not. Alright, thanks.

Another pair of questions.

First off, is there any way to do non-rectangular Zones? Or at least, merge multiple Zones into one? The map of Magical Melody looks like this...

http://flanqer.deviantart.com/art/Harvest-Moon-Magical-Melody-map-v2-1-471226548

Notice how each property is very irregularly-shaped. I wanted to just have each property have its own Zone, because as you can see, each property has a name, and I have a little text box in the corner and I wanted to change the text to reflect what property you're hovering over.

Well, I can do that, but the zones can't have complex shapes like that, as far as I can tell.

I mean, it's a small program, I probably COULD just draw a dozen plus Zones per property and have them all run the same script and not suffer any slowdown, but I'd prefer to do something more elegant.

I've also considered making multiple identical-looking tiles, one for each Zone, and have the message display based on that. That's more labor-intensive for only slightly less of a hacked-together mess.

Second question. How the heck do I stop the cursor from going outside the game when playing in windowed mode?

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: How do you change character walking speed with AttachInput?
Reply #5

I've also considered making multiple identical-looking tiles, one for each Zone, and have the message display based on that. That's more labor-intensive for only slightly less of a hacked-together mess.


This is what I'd say is the standard solution for Sphere. I'd check the tile names as the player moves around and then do things based on which tile you are on.


Second question. How the heck do I stop the cursor from going outside the game when playing in windowed mode?


Not sure... Windows can't limit the cursor to the bounds of a single app. I generally haven't found that an issue, though.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: How do you change character walking speed with AttachInput?
Reply #6

Not sure... Windows can't limit the cursor to the bounds of a single app. I generally haven't found that an issue, though.


Actually it can:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648383(v=vs.85).aspx

I wouldn't recommend any developer do that though, the user will likely just consider it an annoyance.  I don't know how many times I've been annoyed by some program or other getting stuck in window-moving mode and therefore not being able to get the cursor onto the taskbar.
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: How do you change character walking speed with AttachInput?
Reply #7


Not sure... Windows can't limit the cursor to the bounds of a single app. I generally haven't found that an issue, though.


Actually it can:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648383(v=vs.85).aspx


Ok, I  actually didn't look that up since I never thought... Jeez, that's kinda scary, to know that someone has used it sometime before.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: How do you change character walking speed with AttachInput?
Reply #8
I've seen it done in Sphere before, in Beaker's Particle of Infinite Free Will.

I had thought it was done by simply warping the cursor to the center of the screen every frame. Like this:

Code: [Select]
FlipScreen();

// Right after your flipscreen...
SetMousePosition(GetScreenWidth()/2, GetScreenHeight()/2);

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: How do you change character walking speed with AttachInput?
Reply #9

I've seen it done in Sphere before, in Beaker's Particle of Infinite Free Will. I had thought it was done by simply warping the cursor to the center of the screen every frame.


I thought of that too but didn't use the example, because he needed to contain the mouse so your Wii-Mote doesn't track the cursor off of the window, or hit the edge of the screen. Looking at that code, it seems the mouse will always be constrained to the middle after every frame rendered.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: How do you change character walking speed with AttachInput?
Reply #10
Both The Particle of Infinite Free Will as well as RTD:E had code to contain the mouse's position inside the window.  In the case of RTD:E it was optional but if enabled allowed for mouse sensitivity to be configurable.  Since RTD:E used a modified executable, it also had access to check if the sphere window was in focus, so unlike TPIFW, if you managed to click outside the window, then the game would detect that and pause the game while letting go of the mouse, which made the mouse capturing more reasonable.

  • FBnil
  • [*][*]
Re: How do you change character walking speed with AttachInput?
Reply #11


I've also considered making multiple identical-looking tiles, one for each Zone, and have the message display based on that. That's more labor-intensive for only slightly less of a hacked-together mess.

This is what I'd say is the standard solution for Sphere. I'd check the tile names as the player moves around and then do things based on which tile you are on.

I would do it like this: Create the map as you see fit, then add a new transparant top-layer.
Create some coloured tiles, THEN, start drawing on that toplayer each zone a color. One with green, and another zone with red, etc. This way, you can easily see what part of the map is in which zone.
Now make the toplayer invisible. Done.

Once in-game, you need to know which zone you are in, take the position X and Y of your player, divide by the tilesize to get the tile number. If your tiles are 16 pixels, the fastest way is GetPersonTileX=GetPersonX()/16 or the faster  GetPersonTileX=GetPersonX()>>4, then myzone=GetTile(GetPersonTileX, GetPersonTileY, toplayer). Where toplayer is calculated each time you enter a new map:  toplayer=GetNumLayers(). myzone has a the index number of the tile and will change when you walk into another zone.

edit: Added demo for that.

Note2: You can ALSO name tiles, so each colored tile can immediately have the name of the zone with GetTileName().

In fact some games use this, like, all tiles made out of water are named "water", when in water (i.e. in the same layer the person is in), the spriteset of the character is swimming. This is easier than having triggers determining if we are going into or out of the water and having bugs where you can walk over water (because you can always forget it somewhere).
If you can get into the water... you are swimming. And if you are walking over a tile that is "high grass", your feet are in grass.

edit2: removed attachment. See next post for the updated version.
  • Last Edit: December 26, 2015, 10:36:35 am by FBnil

  • FBnil
  • [*][*]
New version of example Terrain and Region/Area
Reply #12
@Mooch: Ok, this is the most simple I can make it.
So you have a tileset. I gave some tiles names. These represent terrain. so water, grass, pavement, etc. you can change the spriteset to reflect a new terrain, like high grass on your feet, or swimming, climbing, walking slower when on mud, etc. (the function to do that, however, is empty). Give me some spritesets that have this feature and Ill give you a proper demogame.

Then, you have that non-visible toplayer which has area names. As the area is not the same as terrain, these do not need to change together.

note: The names of the tiles can be changed ONLY if you have a map with embedded tileset (create a new map, embed the tileset, edit the names, save, close the map, open the map, then export the tileset.... to change the names for the current map with external tileset...)

note2: try walking off the map. the game crashes: make sure to make SetRenderScript() empty if you allow such thing.

note 3: make that top layer visible to see the regions/areas

note4: rightclick on the tiles overview to edit their properties, like obstruction, rotation/animation and name/label.

Also, maybe you like other examples:
http://members.chello.nl/n.castillox/chibitutorials/index.html

if there is something that is not clear, or you have other questions, do not be afraid to ask.
  • Last Edit: December 26, 2015, 11:06:54 am by FBnil