tulamide's Recent Forum Activity

  • Can't reproduce that. Works as expected for me. Maybe something else is interfering in your cap (maybe using escape also for another action, something like that)?

  • It's just an initial space allocated for effects. Add a few other effects and you will see, that just with the first one the VRAM usage raises that much, the others only take a few kb.

  • No, it isn't. It's just that the zooming takes place centered, and (at least I) didn't take that into account.

    + MouseKeyboard: Mouse is over Box
    -> Cursor_MapEditor2: Set position to int((116 - ((ScrollXRight - MouseX) * (ZoomX / 100))) / 8) * 8 + Box.Left, int((480 - ((ScrollYBottom - MouseY) * (ZoomY / 100))) / 8) * 8 + Box.Top[/code:37rfkk1v]
    
    This works. The visible width of the box is 116, although the total width is 120. If you change the position or size of the box, you need to adjust this value, too. And of course the same has to be done to the (visible) height value 480.
    
    EDIT: It works on the original cap you posted (Just wanted to make sure about it  )
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I haven't tested it, but from my head:

    If zooming in to 200%, the area (virtually) represents double the size. Theoretically

    Cursor.x = int(MouseX * (Zoom/100)/8) * 8

    should work.

  • I wasn't sure if you were looking for "Start of layout" or if there are issues with "on load". That's why my answer was cautious

    Yes, you're right, "Start of layout" is what you are looking for. Using it makes sure all expressions and subevents will be executed at the very first tick of the layout.

    ...And welcome to the forums

  • I need it to get the initial state of the game going.

    On load does not trigger at game start, but after having loaded a save file. If that is what you want, you should be able to use it by doing a Load from disk (or Quickload) followed by on load.

  • Thank you for the comments, really appreciate it

    Unfortunately, I uploaded the wrong version, which was calculating the positions wrong in the array example. I updated the link, to the (hopefully) correct version. I'm terribly sorry

  • Use the function object for repetetive events/actions.

    For example, instead of your globals you could setup a function

    + On function "AttackConditions"
    ++ Player.Value('Reserve') greater than 0
       global('Distance') less than 2
    -> Set return value to "True"
    ++ Else
    -> Set return value to "False"
    [/code:1cy20mdp]
    Call that function on key press:
    
    [code:1cy20mdp]+ key A pressed
    ++ Function.AttackConditions equal to "True"
    -> set player animation to "Attack"
    -> substract 1 from Player.Value('Reserve')[/code:1cy20mdp]
    
    The advantage is that you only check the function in your main events. You can group your functions or place them in their own event sheet, and, more important, you can easily change a function or add other code to it etc., without touching the main events.
    
    This makes it easily maintainable. (and btw saves you a lot of globals  )
  • Here we go again. This time I have made a rather simple example cap, showing one scope of application for both, arrays and hash tables, and setting them side by side, to compare them and see, where they are of advantage.

    NEW VERSION (19.02.2011):

    Array_Hash.cap

    You may want to first download the cap and then switch back and forth between Construct and this post.

    I. Array

    I.1 Demands

    The base for the example is a map editor. Imagine you want to create one for your game. It is tile-based, so you know the exact dimensions of the map and you know the tile dimensions. In this example the map has 256x256px, and the tiles have 64x64px. That's a map size of 4x4 in tiles.

    You might want to have a little variation for the tiles as well. In this example, every tile has 4 animation frames, which can be freely selected.

    Now we need to manage and save the informations. The easiest way is to save the frame number of a tile to its position expressed in tiles. That does give the advantage that we could later change the size of the tiles without affecting the map layout. This is a perfect job for an array.

    I.2 Effect

    Run the cap now and click on 'Array'. You will see a red-colored area. Use the mouse wheel to change the animation frame of the tiles. When satisfied, click on 'menu' and then on 'Save array'. Click 'menu' again and select 'Main menu' this time. Click 'Array' again. You will notice that your map is automatically loaded. Change some frames and select 'Load array'. It is reverted to its last saved state.

    I.3 Cause

    Have a look at the event sheet of the layout 'Array'. Open the group 'Array'.

    Event 21 and its subevents are initializing the array. First it is set to 4 in x-dimension and 4 in y-dimension. Then every "cell" of the array (16 in total) is set to the value 1. This is needed, because the first animation frame is 1, but the array is initialized to 0. The next event loads a saved array file, if there is one. This is just a convenience. The last subevent loops through the map and creates the 4x4 tiles.

    Event 26 and its subevents changes the frames of the tiles and updates the array with the new frame numbers.

    Open the group 'Menu'. Events 16 and 19 take care of loading and saving the array. When loading, it is needed to loop through all tiles and set the frame number to the one stored in the array.

    For all accessing of array "cells", some simple math is used to get the tile position. The map starts at (0, 32), a tile has a size of 64x64 and its hotspot is centered. Therefore the tile at array value {1, 1} is located at (32, 64) in pixel values. With (mapobject.X - 32) / 64 + 1 we get (0) / 64 + 1 = 1, and with (mapobject.Y - 64) / 64 + 1 its 1 again, as expected. The tile at array value {3, 4} is located at (160, 256). Just try the math above with that pixel values, you will get the correct tile position. You just need to substract all offsets from the origin, then divide by the tile's size and add 1, to shift the range from [0, 3] to [1, 4].

    II. Hash Table

    II.1 Demands

    Again the base for this example is a map editor. But in difference to the first example it now is object-based. A map object can be placed anywhere on the map, not just on a grid, and it can be deleted or moved. The map size still is 256x256px, and the map objects have a size of 64x64px. And all objects also have the same variations as in the first example.

    To manage and save the informations, we need something to store the coordinates of an object and its animation frame, and those informations may change at any time, or the object may even be deleted. Using an array as we did in the first example is not very effective. First, we would need to make it have 256x256 cells, even if we only place one object in the map. Second, everytime an object is moved we sould need to clear one cell and set another. Third, if two objects are placed at the same coordinates we couldn't store the informations for the second one, the cell is already used for the first one.

    It is much better to have an object-oriented approach. This is a good (but not perfect) job for a hash table.

    II.2 Effect

    Run the cap now and click on 'Hash Table'. You will see the empty map area and some text in the upper left. This text will keep you informed over your objects. Left-click anywhere on the map to create an object. Hold the shift-key and click and hold the left mouse button over an object to change its position. Right-click over an object to delete it. Use the mouse wheel when over an object to change its animation frame. When satisfied, click on 'menu' and then on 'Save hash table'. Click on 'menu' again and select 'Main menu'. Click 'Hash Table' again. Click on 'menu' and select 'Load hash table'. Your last saved map is restored.

    II.3 Cause

    Have a look at the event sheet of the layout 'Hash Table'. Open the group 'Hash Table'.

    Event 23 initializes the hash table by inserting the key 'pid' with the value 0. Event 32 creates a new map object, sets the object's pid to the value of the hash table's 'pid', raises the hash table's 'pid' by 1 and inserts a new key into the hash table. This key represents the new object and it has the following structure:

    key = object's pid, value = a string in the form objectXxobjectY;animationframe (e.g. "128x64;3")

    Event 28 moves an object to a new position. The value of the key that corresponds to the object's pid is set to the new position, by just creating a string from the coordinates and the frame number again.

    Event 29 deletes an object and the key that corresponds to the object's pid.

    Events 30 and 31 change the animation frame of an object and sets the value of the corresponding key to a string created from the coordinates and the frame number again.

    Open the group 'Menu'. Event 16 and its subevents take care of loading and creating the map from a file. If there is no file, the content of the hash table keeps its current state, else it is replaced by the data from the file. Either way, all objects on the map are deleted. We then loop through every key that is not named "pid" and create an object based on the string value of the key. The coordinates and the frame number are retrieved using GetToken, which returns a substring of a string by interpreting a given letter as a delimiter. For the coordinates the delimiter is "x" and for the frame number the delimiter is ";". See the comment in event 20 for more information.

    I'm working on other examples for hash table use, so check this thread from time to time.

  • It depends on the kind of mechanic you use for your game.

    But there is one concrete thing you can rely on: If you go to a layout it is in its initial state. And nothing prevents you to call the same layout that is currently running (effectively restarting it). It is the system action "go to layout" that you need.

    What you need to take care of are the global variables, because of their nature they don't reset, and the timer, because the timer starts when the game starts and keeps counting up.

    My example project "Verve!" covers all of your questions, you might want to have a look at it:

    http://www.scirra.com/forum/viewtopic.php?f=8&t=8011

  • Found this today and think it would be a nice thing to use it for C2...visualization is always fascinating

    http://code.google.com/p/gource/

  • Also, I'm having issues with my EXP formula. If I raise it manually 1 point at a time, it adds up.

    So let's say, I need 97 yo reach level 6. If add it 1 point at a time to my current Xp, I'll get me to level 6 when I get 97 XP. However, I just add 97 XP, it would put me at level 8.

    Try adding 1 point at a time (left click) until you reach level six. The restart and hit right click.

    I maybe wrong, but are you now trying to raise the exp needed per level according to some curve? If so, just take the cap I gave to you in the other thread and change event 41 to... ah, it's easier to show it in the cap. Of course, you need to adapt the change rate, this example simply starts with 1 exp needed for level 1, another 2 for level 2 (3 in total), another 3 for level 3 (6 in total) and so on. Just paste your own values.

    stats4.cap

tulamide's avatar

tulamide

Member since 11 Sep, 2009

Twitter
tulamide has 3 followers

Trophy Case

  • 15-Year Club
  • Coach One of your tutorials has over 1,000 readers
  • Email Verified

Progress

17/44
How to earn trophies