R0J0hound's Recent Forum Activity

  • Well, mode7 can be done with an effect for the visual portion.

    http://www.scirra.com/forum/effect-mode7_topic61959.html

    adtodeg(arctan2(vec1.y - vec2.y, vec2.x - vec1.x));

    The calculation to find the angle from one point to another is made simple with the angle() function in c2. So to get the angle from the player to the enemy the expression would be:

    angle(player.x, player.y, enemy.x, enemy.y)

    I take it you want a "knockback" like collision response. With a quick search I found:

    http://www.scirra.com/forum/how-to-make-a-simple-sprite-knockback-in-8-dir_topic53242.html

    In my opinion it's not necessary to utilize the SDK unless there is something that you can't do with events. One typical situation that comes to mind is the need to interface with an outside library of some kind. Another reason could be to assist in some graphic effect that you can't do with existing plugins. However outside of that you can do pretty much anything in events.

  • This topic could be useful:

    http://www.scirra.com/forum/sprite-movement-8-dir-troubles_topic47201.html

    Anyway discard all your events and i'll show you how to get it working with just two events.

    You can get the direction the sprite is moving with the expression:

    Link.8Direction.MovingAngle

    You can then convert the angle into a number from 0-3 where

    0 right

    1 down

    2 left

    3 up

    Here is the formula. it's explained somewhat in the link.

    int(((self.8Direction.MovingAngle+360+45) %360)/90)

    One more bit. The numbers 0-3 can be converted to the direction names with this: where "dir" is a integer from 0 to 3.

    tokenat("right,down,left,up", dir, ",")

    OK,down to business, add an instance variable to Link and call it "dir". Then make these two events:

    Link| 8Direction is moving

    --- Link| set dir to int(((self.8Direction.MovingAngle+360+45) %360)/90)

    --- Link| set animation to "walk" & tokenat("right,down,left,up", self.dir, ",")

    System| Else

    --- Link| set animation to "idle" & tokenat("right,down,left,up", self.dir, ",")

  • Yes. Look in the xml manual entry:

    https://www.scirra.com/manual/139/xml

    Specifically the links about xpath, you can reference anything to loop over.

    ex.

    XML For each node key "/test/question"

    --- Text set text to XML.StringValue("option")

  • If you have one sprite that is frame 1 already, you can make it spread in eight directions by putting the sprite in a family then making an event like this:

    every 5.0 second

    family1 animation frame=1

    sprite animation frame=0

    family1 is overlapping sprite

    --- sprite set animation frame to 1

    Of course that is a very general case. For your current setup you could do something simple like this to make the sprites turn red from the right to left with 5 seconds in between.

    Start of layout

    For each sprite ordered by sprite.x descending

    --- wait 5*(1+loopindex) seconds

    --- sprite set animation frame to 1

  • A while back I came up with a way of doing a game like Quilox, which is very similar to qix. It was slow and unfortunately the capx doesn't work the same with newer versions of C2 due to a breaking change.

    Anyway for such a game the idea of doing a flood fill from all the enemies works well to indicate the play area, and anything not flood filled can be safely erased to show what's underneath. The second hurdle is having a way to draw and cut up the play field. Ideally pixels would be used as thousands of 1x1 sprites will drag down performance. The canvas object could be used and there are per pixel collision detection capx' around the forums that will also prove useful. One caveat is I don't think it's flood fill action will work for this problem, so it may have to be done manually. Or if you don't mind it much coarser you could use a bunch of larger sprites. Just find a balance between performance and detail.

    For objects only moving on the unrevealed area the idea is basically this:

    . if object is on play field.

    . then move object

    . if object is now not on the play field

    . then undo the move and pick a new direction to move.

    . repeat

    Here's an unpolished example to pick apart using vanilla c2 events:

    https://dl.dropboxusercontent.com/u/5426011/examples19/qix_like.capx

  • newt

    It should be working, re-download it. I fixed it after MadFactory reported it in the second post.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is an example somewhat following vee41's idea of using a flood fill:

    https://dl.dropboxusercontent.com/u/5426011/examples19/wall_build.capx

    In a nutshell it marks every grid as EMPTY then marks all grids with walls as FILLED. After that an eight direction flood fill is done starting at the top left corner (0,0), and finally the grid array is looped over and any grid positions still EMPTY are enclosed and can be drawn blue.

    It has a lot of room for improvement but should give a basic overview of the concept.

  • As far as I can tell when creating an object at runtime the first instance you inserted at edit time is used to the object's created state. It can be a problem to find that instance unless you put it on an asset layout first. I usually just manually set the object state manually when creating at runtime though and completely disregard the edit time values.   It would be useful if there was a way at edit time to pick the initial object or even make a certain instance the reference for default values.

  • The sdk manual describes what they do here:

    https://www.scirra.com/manual/23/runtime-functions

    under "draw(ctx) and drawGL(glw)"

    And it's the runtime that calls them. For more detail: in preview.js the runtime calls the layout draw function in layout.js whenever a frame is to be drawn. From the layout draw function each layer draw function is called (same file) and from there each instance's draw function is called.

    You can't control when the plugin's draw functions are called but you don't have to draw anything when they are. It's quite doable to do as you mentioned to wait a time interval between draws by saving the current time and comparing against it every time the draw funtion is called. However it would only cause your object to flash one frame before the background and other objects would overdraw it after that until it flashes again.

    Here's how you could do it.

    1. add a variable to instanceProto.onCreate so you can save the current time.

    this.oldTime = 0;
    this.timeInterval = 1; //in seconds

    2. add this to the top of your draw and drawgl functions:

    var currentTime = this.runtime.kahanTime.sum;
    if (currentTime >= this.timeInterval + this.oldTime)
        this.oldTime = currentTime;
    else
        return;
    // add drawing code below

    But as I said you'd only get a passive flash of the object every interval.

  • cesisco

    That error is caused by pasting the paster to itself. C2 had a change that no longer permits this as it won't work on some exports as I understand it. I should change the example capx as it's affected by this.

  • retrodude

    I've got it working with chrome and firefox on my pc and on my android tablet. Webrts, which peerjs is based on is still in an experimental state and I think mainly google and mozilla are still working on getting a standardized spec for it. But yeah, eventually it should be useable everywhere. 50 connections at once is the limit for the peerjs server. Which is fine, as if you really needed more you could make your own server based on peerjs' server's source. A game will probably slow long before 50 players though. The main draw of peerjs is it's supposed to be fast since all the server does is act as a broker to connect two devices and then the devices can communicate directly without a server. My example is unfortunately very wip and i'm sure there are superior ways to setup the events I used.

  • So I decided to take the plunge and tinker around with some networking in C2. I found a javascript library PeerJS which uses webrtc on browsers that support it (aka Chrome and FireFox). It seemed appealing to me, as once I got a wrapper working I wouldn't need to write any server side code to get multiple devices connected together.

    So here's a relatively simple tech test of it in action. The first person becomes the host and all others connect to him. Each player has a box to drag around and all the other players box's positions are updated at an arbitrary 20fps. Supposedly I can have up to 50 players connected at once.

    So without further ado, join the box dragging nonsense:

    http://tinyurl.com/kherptw

    [EDIT]

    Nonsense indeed, after further testing I noticed quite a few things I did wrong with handling the networking events. On top of that my internet and pc are pretty slow right now.

R0J0hound's avatar

R0J0hound

Member since 15 Jun, 2009

Twitter
R0J0hound has 157 followers

Connect with R0J0hound