bladeO's Forum Posts

  • 9 posts
  • I'm imagining a function that returns an array of acceptable coordinates, given arguments:

    var array = function mitchellBC(numDesiredCoordinates, kSamples, minDistance, canvassDimensions, canvassOffsets) [/code:oh0lkr4g]
    
    in which canvassDimensions [x,y] and canvassOffsets [x,y] allow for the return of an array of coordinates within a defined space (rather than scene-wide- a bit more control).
    
    I could probably write that function in javascript (since most of it is in my link), but I'm not sure how to integrate with event sheet using the SDK, and I don't know how to build the function using only the event sheet (which seems more confusing than just figuring out the javascript code, honestly- think I could better follow a hybrid approach to events).
    
    A bridson function would also be nice, that I could compare
  • It's following what the code you posted does.

    aka take a number of random points and find their distance to a closest other point. Finally just keep the closest of them all.

    In the capx it just creates a bunch of sprites, and destroys all but one.

    Sorry, but I'm not seeing that it does. In your example (viewing in IE), if I change 'Repeat 200' to 'Repeat 24', I'm still seeing ~200 objects, and if I further change the project window size to 1280, 960, I'm seeing over 800 dots which are still spawning after over a minute. This isn't a behavior I understand, expect or want.

    The code I posted returns the furthest candidateDot of var "sample" = 50 randomly generated dots from the nearest placed dot 'control' (in placedDots [ ]). I'm of the opinion that building (and saving) that placedDots array first, then drawing/spawning from it lastly (or separately, later), might be a better approach than creating/destroying sprites.

    FYI for anyone interested, an example of Bridson’s poisson-disc sampling method I linked to in last post. Supposedly more efficient and tightly-packed.

  • Thanks for the quick replies.

    Here's one way to do it:

    https://dl.dropboxusercontent.com/u/542 ... ibute.capx

    Sorry, I'm still a bit unfamiliar with events. Is the 200 repeat for drawing 200 sprites? I assume that's the case, but changing it to a smaller number had no visible effect. It's also still trying to draw new sprites after a number of seconds. (Just looking at it in debug mode. I may well be misunderstanding it though.)

    I think in my case it may be more beneficial to create this sprite distribution in the editor (via a plugin, I assume), though on the fly creation also has application for me as well. (These 12-24 sprites I envision will serve as portals to other levels, so each will have unique properties.)

    Btw, here (pdf) is another, related method described without code.

  • I was searching for a method to place a relatively small N number of (identical square) sprites within the scene via random seed, such that the sprites maintain a minimum distance from each other and have a more natural looking distribution.

    This link is the nearest and clearest example of such I could find. (You can edit values and rerun.) In my case, a sprite would be centered at each dot (rather than dot drawn), and the "dotRadius" would that of a circle containing the sprite plus padding.

    I was curious as to whether this would be a suitable solution for Construct 2 and how one might implement it. Below is the code from the above link:

    /*
    
    Inspiration: http://bl.ocks.org/mbostock/d7bf3bd67d00ed79695b
    
    Amazingly, even with high numbers of dots and high levels of smoothing,
    finding the ideal position for a new dot never takes takes longer than
    a millisecond. I was sure the brute-force approach would lag and I'd 
    have to implement a quadtree or something.
    
    */
    
    (function (canvas) {
        'use strict';
    
        var ctx = canvas.getContext('2d'),
            cw = canvas.width,
            ch = canvas.height,
            twoPi = Math.PI * 2,
            dotRadius = 32,
            dotColor = '#0AA594',
            dotCount = 30,
            samples = 50, // candidate dots attempted, higher is better
            placedDots = [], // a dot is represented as [x, y]
    
            initialize = function () {
                var dotsDrawn = 0,
                    interval = setInterval(function () {
                        // var elapsed = (new Date()).getTime();
                        placeNewDot();
                        // elapsed = (new Date()).getTime() - elapsed;
                        dotsDrawn++;
                        // console.log('Dot #' + dotsDrawn + ' drawn in ' + elapsed + 'ms.');
                        if (dotsDrawn === dotCount) clearInterval(interval);
                    }, 20);
            },
    
            generateRandomPosition = function () {
                return [
                Math.round(Math.random() * cw),
                Math.round(Math.random() * ch)];
            },
    
            getDistanceToNearestDot = function (dot) {
                var shortest;
                for (var i = placedDots.length - 1; i >= 0; i--) {
                    var distance = getDistance(placedDots[i], dot);
                    if (!shortest || distance < shortest) shortest = distance;
                }
                return shortest;
            },
    
            getDistance = function (dot1, dot2) {
                var xDistance = Math.abs(dot1[0] - dot2[0]),
                    yDistance = Math.abs(dot1[1] - dot2[1]),
                    distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
                return Math.floor(distance);
            },
    
            generateBestDot = function () {
                var bestDot, bestDotDistance;
                for (var i = 0; i < samples; i++) {
                    var candidateDot = generateRandomPosition(),
                        distance;
                    if (!placedDots.length) return candidateDot;
                    distance = getDistanceToNearestDot(candidateDot);
                    if (!bestDot || distance > bestDotDistance) {
                        bestDot = candidateDot;
                        bestDotDistance = distance;
                    }
                }
                return bestDot;
            },
    
            placeNewDot = function () {
                var dot = generateBestDot();
                placedDots.push(dot);
                drawDot(dot);
            },
    
            drawDot = function (dot) {
                ctx.fillStyle = dotColor;
                ctx.beginPath();
                ctx.arc(dot[0], dot[1], dotRadius, 0, twoPi);
                ctx.fill();
            };
    
        initialize();
    
    }(document.getElementById('canvas')));[/code:2j133ne4]
  • Here's a simplified template:

    Conversation xmlns:xsi="can't post urls" xmlns:xsd="can't post urls">
      <subNodes>
        <ContentNode idNum="1" orderNum="1" linkTo="0" nodeType="npc">
          <conversationText>NpcEntry</conversationText>
          <conversationComments>NpcEntryComment</conversationComments>
          <subNodes>
            <ContentNode idNum="2" orderNum="1" linkTo="0" nodeType="pc">
              <conversationText>PlayerReply</conversationText>
              <conversationComments>PlayerReplyComment</conversationComments>
              <subNodes />
              <additionalData />
              <infoObjects />
            </ContentNode>
          </subNodes>
          <additionalData />
          <infoObjects />
        </ContentNode>
      </subNodes>
      <additionalData />
      <infoObjects />
      <VersionNumber>2</VersionNumber>
    </Conversation>
  • Hi,

    I'm working towards implementing a dialog system utilizing xml files generated by the Flamewind Conversation Editor (@nwvault- free, standalone) and was curious as to the best way forward, in a general sense. Below is a sample conversation output xml.

    I've taken a look at the dialog info linked in the "How do I?" FAQ, but since this editor is free and easy to use, I figured to work from it to employ a system that others might be able to implement, without an encumbered workflow.

    FWIW, I see the npc text as a text or (uneditable) textbox object, and the player replies as listbox object items (only way i see to add/subtract reply options).

    My questions are:

    1. Should I parse the xml as is within events (pulling text and resolving conditions/actions directly from its content), or should I load its content into another form(s) (array and/or otherwise) and use that/those to resolve events? I'm not clear on the advantages of one over another or whether the xml would readily conform to a better format. Also, My personal implementation would be on a desktop browser, so I suppose I'm less concerned about cross-functionality at the moment, but...

    2. Would a transformation (XSLT) of the output xml (into another xml) be wise before attempting #1? It's not exactly the most followable xml. Idk if transforming would help coding/XPath expressing.

    Here is the code

    <?xml version="1.0" encoding="utf-8"?>
    <Conversation xmlns:xsi="can't post urls" xmlns:xsd="can't post urls">
      <subNodes>
        <ContentNode idNum="2" orderNum="1" linkTo="0" nodeType="npc">
          <conversationText>Nice to see you again!</conversationText>
          <conversationComments>This greeting should appear if Player has already spoken to Npc</conversationComments>
          <subNodes>
            <ContentNode idNum="3" orderNum="1" linkTo="0" nodeType="pc">
              <conversationText>I have that thing you wanted.</conversationText>
              <conversationComments>Appears when Player has accepted quest and has item</conversationComments>
              <subNodes>
                <ContentNode idNum="11" orderNum="1" linkTo="0" nodeType="npc">
                  <conversationText>Awesome! Here's some gold.</conversationText>
                  <conversationComments>Give gold to Player</conversationComments>
                  <subNodes />
                  <additionalData />
                  <infoObjects />
                </ContentNode>
              </subNodes>
              <additionalData />
              <infoObjects />
            </ContentNode>
            <ContentNode idNum="12" orderNum="2" linkTo="0" nodeType="pc">
              <conversationText>I'm still looking for that thing you wanted.</conversationText>
              <conversationComments>Appear only when Player has quest but not item.</conversationComments>
              <subNodes>
                <ContentNode idNum="13" orderNum="1" linkTo="0" nodeType="npc">
                  <conversationText>Good luck!</conversationText>
                  <conversationComments />
                  <subNodes />
                  <additionalData />
                  <infoObjects />
                </ContentNode>
              </subNodes>
              <additionalData />
              <infoObjects />
            </ContentNode>
            <ContentNode idNum="0" orderNum="3" linkTo="5" nodeType="pc">
              <conversationText />
              <conversationComments />
              <subNodes />
              <additionalData />
              <infoObjects />
            </ContentNode>
            <ContentNode idNum="0" orderNum="4" linkTo="6" nodeType="pc">
              <conversationText />
              <conversationComments />
              <subNodes />
              <additionalData />
              <infoObjects />
            </ContentNode>
          </subNodes>
          <additionalData />
          <infoObjects />
        </ContentNode>
        <ContentNode idNum="1" orderNum="2" linkTo="0" nodeType="npc">
          <conversationText>Hello Player!</conversationText>
          <conversationComments>Appears if Player is speaking to Npc for first time</conversationComments>
          <subNodes>
            <ContentNode idNum="4" orderNum="1" linkTo="0" nodeType="pc">
              <conversationText>What is your name?</conversationText>
              <conversationComments />
              <subNodes>
                <ContentNode idNum="10" orderNum="1" linkTo="0" nodeType="npc">
                  <conversationText>Bob</conversationText>
                  <conversationComments />
                  <subNodes>
                    <ContentNode idNum="0" orderNum="1" linkTo="5" nodeType="pc">
                      <conversationText />
                      <conversationComments />
                      <subNodes />
                      <additionalData />
                      <infoObjects />
                    </ContentNode>
                  </subNodes>
                  <additionalData />
                  <infoObjects />
                </ContentNode>
              </subNodes>
              <additionalData />
              <infoObjects />
            </ContentNode>
            <ContentNode idNum="5" orderNum="2" linkTo="0" nodeType="pc">
              <conversationText>Got any quests?</conversationText>
              <conversationComments>Appears if player has not accepted quest</conversationComments>
              <subNodes>
                <ContentNode idNum="7" orderNum="1" linkTo="0" nodeType="npc">
                  <conversationText>Yes, fetch me something.</conversationText>
                  <conversationComments />
                  <subNodes>
                    <ContentNode idNum="8" orderNum="1" linkTo="0" nodeType="pc">
                      <conversationText>Ok</conversationText>
                      <conversationComments>Player accepts quest</conversationComments>
                      <subNodes />
                      <additionalData />
                      <infoObjects />
                    </ContentNode>
                    <ContentNode idNum="9" orderNum="2" linkTo="0" nodeType="pc">
                      <conversationText>No thanks</conversationText>
                      <conversationComments />
                      <subNodes />
                      <additionalData />
                      <infoObjects />
                    </ContentNode>
                  </subNodes>
                  <additionalData />
                  <infoObjects />
                </ContentNode>
              </subNodes>
              <additionalData />
              <infoObjects />
            </ContentNode>
            <ContentNode idNum="6" orderNum="3" linkTo="0" nodeType="pc">
              <conversationText>Goodbye</conversationText>
              <conversationComments />
              <subNodes />
              <additionalData />
              <infoObjects />
            </ContentNode>
          </subNodes>
          <additionalData />
          <infoObjects />
        </ContentNode>
      </subNodes>
      <additionalData />
      <infoObjects />
      <VersionNumber>2</VersionNumber>
    </Conversation>

    About the xml:

    A couple elements are superfluous (as a standalone application), such as "<additionalData />" and "<infoObjects />". They're always empty.

    An "idNum" value of 0 means that an element is copied (as a link) from another element (whose idNum is expressed in the "linkTo" value)

    The comment element provides an opportunity to insert condition|action parameters

    Any general thoughts/suggestions would be appreciated. I've begun working on it, and I'll post my capx progress once I've locked onto a directin. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's also possible C2 will notice the image fits in to a 16-bit format, like 1-5-5-5 ARGB, or 5-6-5 RGB. This reduces the memory usage by half, and can actually render faster too (since less data is involved). However it's usually pretty rare for images to be able to be marked as a 16-bit format, since C2 only does so when it's truly lossless. A single pixel that can't be losslessly represented by, say, 5-bit values instead of 8-bit values, means the image must be encoded back to 32-bit ARGB - and this happens at the level of an entire spritesheet.

    Is it possible to design images to fit this format, say by using a Highcolor palette (pulled from wikipedia) when creating them, or converting to 16-bit.bmp (then back to jpg or png before import)?

    Does this 16-bit memory savings only affect mobile devices?

  • Hello World,

    I purchased Construct2 a couple months back after looking through various game editors. Seemed like a good, affordable fit with an active community.

    I'm new to full-fledged game design, but I find the process and all the tools people have created and shared intriguing.

    I've designed levels, scripts, UIs and mods for Neverwinter Nights 1 & 2, largely because my wife is a big rpg nerd. :) NWscript is my only coding experience, but I was able to make a relatively accurate ephemeris based on are solar system. (It's called "Realmspace Astrology", on the NWN IGN vault)

    I have a few ideas for games: one card, one rpg brawler, one space rpg/turn-based board (not unlike Spelljammer in ways), and one rpg survival strategy. I don't know which to pursue. Full of ideas without direction I suppose.

    Anyway, I have a topic on the general forum about utilizing OpenStreetMaps, so take a look and share your thoughts. I've been lurking without comment bc, well, I don't know what I'm talking about!

    Cheers!

  • Hello,

    I'd like to create a top-down game based upon a map of my modest home town, and I'm curious as to the feasibility and/or wisdom of importing (via plugin) or building layouts within Construct2 from the data and imagery OpenStreetMap, JOSM, TileMill et al. can provide.

    OpenStreetMap (OSM) is simply that. Open. Editable. (I'd post urls but don't have rep :/ )

    JOSM is an offline OSM editor which allows extended customization and export of OSMs (.osm or .xml)

    TileMill and Maperative allow maps to be rendered as tile images (and packaged in an SQLite db as .mbtiles.

    In a perfect world, I would like to customize, add attributes and create the image library of my town using the tools above, then have Construct2 create layouts from it- background layers from image tiles, building collisions as separate (transparent) objects constructed from node data (each possibly assigned attributes created in JOSM).

    Is that dumb?

    I realize that:

    1) such ease of integration would be a complex undertaking by person(s) more skilled than I.

    2) The practicality may be greatly limited by performance/other constraints.

    For example, while my town ~4 km square can be fit in a ~5 MB database (at 1 zoom level of 18), the number of 256x256 tiles is in the thousands. That number can be reduced by decreasing boundary scope and/or zoom level and/or increasing tile size (png-8 available), but that impacts design...

    I'm sure others have wondered but searching for terms didn't reveal any posts. I think there are a number of games people could make from osm data, were it feasible to implement. To be clear, I'm talking about using it to build a project, not accessing Runtime from MapBox or similar server- although I'm curious about that as well.

    Anyway, before I continue trying to construct a hokey approximation by hand using Construct's "tiled background" objects, I thought I'd pose the thought.

    Even if layers are built by hand from the tile image library, are the cons too great to bother?

    Thanks for reading! (first post, recently bought)

    <img src="smileys/smiley5.gif" border="0" align="middle" /> <img src="smileys/smiley5.gif" border="0" align="middle" /> <img src="smileys/smiley5.gif" border="0" align="middle" /> <img src="smileys/smiley5.gif" border="0" align="middle" />

  • 9 posts