David's Recent Forum Activity

  • We'll probably add a right click menu in the event wizard so you can arrange your objects there and then.

    Just like adding private variables, its most likely that the time you'll think 'man this object really shouldn't be listed in the event wizard' is when you're actually in the event wizard

  • Damn gradients dont render too well with float scrolling positions. I guess thats because they use the bouncing box co-ordinates. If you replace all the gradients with sprites the scrolling looks fine.

  • Just tried out single player, its really fun! I was like pfff another tanks game but this one is really good! Sadly its 2am and I got work tomorrow morning so I better go! Night!

  • You do not have permission to view this post

  • I figured I'd write a quick tutorial that goes over the basics of writing a pixel shader.

    The first turial will just be a quick overview of an existing shader so you understand how it works.

    Open the directory or its equiv: C:\Program Files\Scirra\Construct\Effects\

    This is where all the effects are. Each effect is a single *.fx file which can be opened in any text-based editor. I would personally recommend notepad++ because its free, simple, has syntax colouring, and multiple undos. Anyway it doesn't really matter for this tutorial, we are simply going to be reading over the file.

    Open Multiply Plus.fx

    Lets take a look at the first few lines of the file:

    // Multiply
    // Ashley Gullen
    // PS 2.0
    // Multiplication blend with intensity.[/code:2lblvyj0]
    The first line is the name of the effect, the second is the Author, the third is the Pixel Shader version, and the fourth is its description. The // means this text is a comment, and therefore not part of the fx file...however Construct reads these specific lines and obtains information from them, so your fx files MUST contain these comments
    
    Next we have our parameter for our effect
    
    [code:2lblvyj0]//#PARAM percent intensity 1 : Intensity : Intensity of the effect.
    float intensity;[/code:2lblvyj0]
    
    The first line is a Construct definition, which goes in the form:
    #param type fxvariablename initialValue : nameInConstruct : Description
    
    For type we can either use percent or float. Currently these are all that are supported, but later we may include more (such as a texture!)
    
    Next we have any declared variables that are needed for our shader. 
    [code:2lblvyj0]
    // Foreground texture
    texture ForegroundTexture;
    
    // Background texture
    texture BackgroundTexture;
    [/code:2lblvyj0]
    
    Constructs runtime will check to see if certain variables are declared in the effect file, and will pass appropriate values to them. Here is a complete list:
    [ul]ForegroundTexture
    BackgroundTexture
    SourceTexture
    PreviousTexture
    frameCounter
    boxLeft
    boxTop
    boxRight
    boxBottom
    boxWidth
    boxHeight
    hotspotX
    hotspotY
    pixelWidth
    pixelHeight
    bgStart
    bgEnd
    [/ul]
    Other shaders such as 'wave' use most of these variables, but multiply doesn't require them so they aren't declared.
    
    Now we have our sampler definitions:
    [code:2lblvyj0]// Foreground sampler
    sampler2D foreground = sampler_state {
        Texture = (ForegroundTexture);
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = Point;
    };
    
    // OriginalTexture sampler
    sampler2D background = sampler_state {
        Texture = (BackgroundTexture);
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = Point;
    };[/code:2lblvyj0]
    
    In a pixel shader, samplers determine how the computer calculates the colour value of a point in the texture. If you use 'point', it will go to the nearest pixel, if you use linear, it does a linear interpolation between pixels. We tend to only use these two. Point is faster than linear, so we tend to only use linear when its possible we are looking up pixels that are between pixels. Magnify uses linear so that the magnified image looks smooth rather than 'pixelly'.
    
    Now we have our effect definition. 
    
    [code:2lblvyj0]// Effect function
    float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
    {
        float4 front = tex2D(foreground, Tex.xy);
        float4 back = tex2D(background, Tex.xy);
        front.a *= back.a;
        front.rgb *= back.rgb * intensity;
        return front;
    }[/code:2lblvyj0]
    
    This is the actual function which calculates every single pixel. It's best to write the function as simple as possible, because the fx file is converted into a machine language which is optimised and the shaders read. 
    
    [code:2lblvyj0]tex2D(foreground, Tex.xy);[/code:2lblvyj0]
    the tex2D function obtains a pixel colour from a sampler. 
    
    float4 structures are awesome. You can write stuff like: front *= 2 and the a,r,g,b values all get doubled, or front.rgb * 2 will multiply only red, green, blue, or you can refer to them individually as front.r, front.g, front.b, etc.
    
    these float values are all between 0-1, and if you want to add two colours together you simply write
    front.rgb + back.rgb.
    
    Finally we have our effect definition
    
    [code:2lblvyj0]// ConstructEffect
    technique ConstructEffect
    {
        pass p0
        {
            VertexShader = null;
            PixelShader = compile ps_2_0 EffectProcess();
        }
    }[/code:2lblvyj0]
    
    All our shaders tend to either be ps_2_0 or ps_1_4
    
    The pixel shader definition determines what functions can be used, and how many lines of instructions you can have per shader.
  • This kind of behaviour sounds like it would be rather simple, and could be a good tutorial for writing behaviours

  • Yeah we need more info

    You could just have an object 'Achievement' with a string private variable for 'name'. And then like:

    pick up achievement code:

    Create object Achievement at

    Set Achievement variable 'name'

    And then in another event somewhere else, you could display the achievements by loop eaching achievement, possibly having a string object contained with it so you can display a name as well

  • I'm really surprised people are getting slowdown....if you dont mind me asking how is your scene being rendered ? Are there any pixel shaders? It looks beautiful btw!

  • Heh we should make a list of 'common game design questions' which we can provide simple 'event-wise methods' of achieving stuff in the simplest way possible...enemy 'waves' and spawning positions in general is a good topic to add!

  • Lets take the simple example of animations. The problem with having a dropdown is if you have the object as a family, then the animations could be anything. Also, in the future we want to add the ability to change with animation 'package' a sprite uses. So just like you can have gradients with separate colours, you could have a single object like 'background tile' have different animations. So having a combo box of animation names isn't really possible

    The best solution I can think of right now is having a combo box somewhere which fills up with the name of every single animation name used in the application...or in the expression wizard you could select an object and there'd be a combo box saying 'animation names' which you select and it add in the string for it.

    Controls could be done...they are per application

    Layer names though is a bit of a problem because you dont know which layout an event sheet could be refering to...so the only solution is to list every layer in every layout of the application....

    Anyway it's something that requires some though and time...and right now is not the time coz i'm drinking woodstock

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ahaha nice idea for a game You could have lots of fun with it....each level starts in a completely random place beginning with the caption 'where am I...ugh my head...'

David's avatar

David

Member since 21 May, 2007

None one is following David yet!

Trophy Case

David has no trophies yet!

How to earn trophies