R0J0hound's Forum Posts

  • You don't always need an expert to answer every question. If the question isn't directly tied with c2 the internet is a vast resource that can provide solutions or tips on how things are done. Even if it isn't then you can expiriment with the lab which is c2. My computer is filled with examples I've done to figure out how things work.

    I'm not saying you shouldn't ask questions, rather there are ways to figure it out on your own.

    Also keep in mind that most experts don't just know an answer, but if it sparks their interest and they have the time they sometimes can find a solution. The key word being "time". And all users, including you and even the brand new users can be one of the "contributing experts" if you take the time to find an answer to a question.

  • QuaziGNRLnose

    Ok, I found where the webgl texture handle is in the __webglTexture attribute of WebGLRenderTarget.

    var rendertexture = new THREE.WebGLRenderTarget(100,100 );
    //texture to use with setTexture()
    rendertexture.__webglTexture[/code:2w4vnv08]
    
    The problem that I've found after that is the texture still won't work since by default textures aren't shared between different contexts.  But there is a way to share it:
    [url]http://www.khronos.org/webgl/wiki/SharedResouces[/url]
    
    From that page I found this tidbit of code that shows what needs to be done to share textures:
    [code:2w4vnv08]var gl1 = someCanvas.getContext('webgl');
    var sg1 = someCanvas.getExtension("WEBGL_shared_resources");
    var gl2 = someOtherCanvas.getContext('webgl', {
        shareGroup: gl1.shareGroup
    });
    var sg2 = someOtherCanvas.getExtension("WEBGL_shared_resources");
    var tex = gl1.createTexture();
    sg1.releaseSharedResource(tex);
    sg2.acquireSharedResource(tex, gl.READ_ONLY, function() {
       gl2.bindTexture(gl.TEXTURE_2D, tex);
    });[/code:2w4vnv08]
    
    I'm still working out the details for getting it working but a few points I have so far.
    1. The first context doesn't need to be created, we can get it from this.runtime.gl.
    2. For the second context it seems we have to create the canvas and context for WebGLRenderer first and then pass them as parameters like this: [code:2w4vnv08]var renderer = new WebGLRenderer({"canvas":mycanvas, "context":mycontext});[/code:2w4vnv08] The context creation can likely be copied basically from what threejs already does plus the shareGroup stuff.
    3. The bindtexture() function should be replaceable by the set Texture() function.
    
    I hope to have it more ironed out later.
    
    Edit:
    Well it seems that resource sharing isn't implemented as of yet...
    
    Edit2:
    After further testing the idea won't work.  I also tried making threejs use the same canvas and context as c2 but it's giving errors, probably due to conflicts in gl states from the two.  So Ashley's solution is probably the best you can get at the moment.
  • I did about the same thing in my canvas plugin to get a webgl texture and had the same effect of being slow.

    If you look in the text object it uses a function from Glwrap that just copies the pixels from a canvas to a webgl texture instead of loading a new texture each time. I haven't used it yet but it should be a bit faster especially since it should give less for the gc to collect.

    That sounds interesting that three.js can render directly to a texture. As far as I'm aware c2 uses just a standard webgl texture handle. I'll try to investigate furthur when I get to my PC.

  • anticloud

    Feel free, I don't have any restrictions on the use of my plugins.

  • The closest you can do is perhaps use the canvas plugin (third party). With it you can get individual pixels from just the object's image. Besides that there isn't a way currently to get the color under the mouse for the whole game area.

  • I'd imagine the performance would be better after exporting. It's hard to design for this since the texture atlas is done automatically and you're still bound by a maximum texture size.

    To see if your idea would be faster you'd need to make a test either way and measure the performance. This is assuming that's where the bottleneck is at in your game. My machine is weak with html5/javascript so logic is often the bottleneck instead of rendering. Well I have a slow rendering issue as well since my graphics card is in driver limbo, so I'm hit by both sides.

  • Ashley can probably answer more precisely and you can find some more info on C2's renderer on Ashley's blog, but I can give some overview. Basically images are moved to video memory once and when rendering webgl is told which texture to use, the opacity and the quad's four corners' xy and uv coordinates. C2 uses sprite batching to group sprites with the same texture together and reduce the draw calls to lesstexture switching and sending bigger chunks of the quad vertices. Now as to your question I imagine if you had only two instances of one object and each had a different frame then that would be two draw calls. However on export C2 creates texture atlas' of the frames if it can, so then it may take only one call. To be more exact about a draw call, it is only done once per frame in webgl. Everything else is just sending info to webgl to use when the frame is drawn.

  • Look in the pin behavior. At least I think that's the behavior that does it, there are others. The function was called tick2() but now it's called posttick or something like that. The function is usually right after the tick function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use Browser.ExecJS("'\x41'") to do any ascii letter from a two digit hex. In this case it's "A".

    It's not needed though since you can use " " and newline. Backspace seems it would be useful but it does nothing in javascript. You'll have to do something link set text to left(text, len(text)-1) instead.

  • Here's something that works.

    https://dl.dropboxusercontent.com/u/5426011/examples21/clearWhite.capx

    To make it work with an imgUrl change the executeJs in event 2 to something like this:

    "this.clearFill('"& Canvas.imageUrl&"'," & int(TextBox.Text) &");"

  • It's possible to do with the canvas plugin since as a basic requirement you need to be able to get and set pixels. The issue is the plugin doesn't have a direct way to erase pixels. Currently the only way to erase a pixel is to paste a 1x1 sprite with the destination out blend.

    You'll have to do your own flood fill which is simple enough. Wikipedia has some useful info on how to do one.

    The tolerance can be done with a 3d distance from color to color.

    So a pixel is only flood filled if

    Sqrt((255-r)^2 + (255-g)^2 + (255-b)^2) <= tolerance

    There is a capx that does a simple flood fill with just events. It is rather slowish so it would be better if the whole bit was done with javascript for speed.

    I haven't put much time aside as of late to make examples or tinker with much coding, so I can't help much furthur ATM.

  • One way to get the height of the first line:

    GetToken(ListBox.LineText(0), 1, " ")

    2nd:

    GetToken(ListBox.LineText(1), 1, " ")

    3rd:

    GetToken(ListBox.LineText(2), 1, " ")

    ...

  • You mean like the arcade mario bros or the 2player battle mode of super mario 3?

    One way that come to mind is to add another dummy player sprite that you position at the opposite side of the screen. For example If the player is near the right of the screen the dummy sprite is a screen width left of the player.

  • You could look in the "exporters" folder to look at the source code of the pin behavior. If you want to do it in Construct Classic I think in the examples section there is an example of arrows sticking into an object, which does basically the same thing as the pin behavior.

    Off the top of my head you could do pin like this:

    1 Create two sprites, childSprite and parentSprite.

    2 Give childSprite four instance variables: parent,dist,ang,relAng.

    Parent will store the uid of the parentSprite to be pinned to, use -1 for none.

    Dist and ang are the distance and angle to position from the parent.

    RelAng is the relative angle between the parent and child.

    3 Here's an example of an event to setup a pin.

    On ChildSprite collides with parentSprite

    • --childSprite: set parent to parentSprite.uid
    • --childSprite: set dist to distance(parentSprite.x,parentSprite.y,self.x,self.y)
    • --childSprite: set ang to angle(parentSprite.x,parentSprite.y,self.x,self.y)
    • --childSprite: set relAng to self.angle-parentSprite.angle

    4 Then position the pinned objects with:

    For each childSprite

    Pick parentSprite by uid childSprite.parent

    ---childSprite: set position to parentSprite

    ---childSprite: move self.dist pixels at angle self.ang

    ---childSprite: set angle to parentSprite.angle+self.relAng

    Edit

    The collision response will be interesting, you have choice of either doing the motion yourself or seeing if you can bend the physics behavior to your own devices. Either way you'll want the center of mass. Instead of just finding an average of the positions you need to incorporate mass which is simple enough.

    COMx =(mass1*x1+mass2*x2...)/(count*total_mass)

    COMy =(mass1*y1+mass2*y2...)/(count*total_mass)

    And then you can calculate the force and torque to apply to it with roughly this:

    Linear force =applied force magnitude* dist from com to applied force loc * cos(angle of applied force- angle from applied force to com)

    Angular torque is the same as above except use sin instead of cos.