Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Small improvements in samples' code
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Sep 3, 2016
1 parent facdb57 commit 621e856
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 253 deletions.
6 changes: 2 additions & 4 deletions samples/pixi/basic/basic.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ let gameDiv = document.getElementById("game")
gameDiv.appendChild( renderer.view )

// create the root of the scene graph
let stage = new Container()
let stage = Container()

// create a texture from an image path
let texture = Texture.fromImage("public/assets/bunny.png")

// create a new Sprite using the texture
let mutable bunny = Unchecked.defaultof<Sprite>
bunny <- Sprite(texture)
let bunny = Sprite(texture)

// center the sprite's anchor point
bunny.anchor.x <- 0.5
Expand All @@ -57,6 +56,5 @@ let rec animate (dt:float) =
// render the container
renderer.render(stage)


// start animating
animate 0.
33 changes: 15 additions & 18 deletions samples/pixi/blur-filter/blur-filter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ let gameDiv = document.getElementById("game")
gameDiv.appendChild( renderer.view )

// create the root of the scene graph
let stage = new Container()
let stage = Container()

let bg = Sprite.fromImage("./public/assets/depth_blur_BG.jpg")
bg.width <- renderer.width
bg.height <- renderer.height
stage.addChild(bg)

let mutable littleDudes = Sprite.fromImage("./public/assets/depth_blur_dudes.jpg")
let littleDudes = Sprite.fromImage("./public/assets/depth_blur_dudes.jpg")
littleDudes.position.x <- (renderer.width / 2.) - 315.
littleDudes.position.y <- 200.
stage.addChild(littleDudes)
Expand All @@ -41,26 +41,23 @@ littleRobot.position.x <- (renderer.width / 2.) - 200.
littleRobot.position.y <- 100.
stage.addChild(littleRobot)

let mutable blurFilter1 = filters.BlurFilter()
let mutable blurFilter2 = filters.BlurFilter()
let blurFilter1 = filters.BlurFilter()
let blurFilter2 = filters.BlurFilter()

littleDudes.filters <- Some(ResizeArray[|blurFilter1 :> AbstractFilter|])
littleRobot.filters <- Some(ResizeArray[|blurFilter2 :> AbstractFilter|])

let mutable count = 0.

let rec animate (dt:float) =

count <- count + 0.005

let blurAmount = Math.cos(count)
let blurAmount2 = Math.sin(count)

blurFilter1.blur <- 20. * (blurAmount)
blurFilter2.blur <- 20. * (blurAmount2)

window.requestAnimationFrame(FrameRequestCallback animate) |> ignore
renderer.render(stage)
let rec animate =
let mutable count = 0.
let rec animate (dt:float) =
count <- count + 0.005
let blurAmount = Math.cos(count)
let blurAmount2 = Math.sin(count)
blurFilter1.blur <- 20. * (blurAmount)
blurFilter2.blur <- 20. * (blurAmount2)
window.requestAnimationFrame(FrameRequestCallback animate) |> ignore
renderer.render(stage)
animate

// start animating
animate 0.
16 changes: 7 additions & 9 deletions samples/pixi/dragging/dragging.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let gameDiv = document.getElementById("game")
gameDiv.appendChild( renderer.view )

// create the root of the scene graph
let stage = new Container()
let stage = Container()

let texture = Texture.fromImage("./public/assets/bunny.png")

Expand All @@ -46,11 +46,10 @@ type MyBunny(texture) =
this?dragging <- false

member this.mousemove() =
let isDragging = unbox<bool> this?dragging
if isDragging then
if unbox this?dragging then
let newPosition = this?data?getLocalPosition(this?parent)
this.position.x <- unbox<float> newPosition?x
this.position.y <- unbox<float> newPosition?y
this.position.x <- unbox newPosition?x
this.position.y <- unbox newPosition?y

member this.touchstart = this.mousedown
member this.touchend = this.mouseup
Expand All @@ -59,7 +58,7 @@ type MyBunny(texture) =
member this.touchmove = this.mousemove

let createBunny x y =
let mutable bunny = MyBunny(texture)
let bunny = MyBunny(texture)
bunny.interactive <- true
bunny.buttonMode <- true
bunny.anchor.set(0.5)
Expand All @@ -68,10 +67,9 @@ let createBunny x y =
bunny.position.y <- y
stage.addChild(bunny)


for i in 0..9 do
let x = float( Math.floor( Math.random() * 800.))
let y = float( Math.floor( Math.random() * 600.))
let x = Math.floor(Math.random() * 800.)
let y = Math.floor(Math.random() * 600.)
createBunny x y |> ignore

let rec animate (dt:float) =
Expand Down
74 changes: 41 additions & 33 deletions samples/pixi/graphics/graphics.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ open Fable.Import.PIXI
open Fable.Import.Browser
open Fable.Import.JS


let options = [
Antialias true
]
Expand All @@ -29,9 +28,9 @@ let gameDiv = document.getElementById("game")
gameDiv.appendChild( renderer.view )

// create the root of the scene graph
let mutable stage = new Container()
let mutable stage = Container()

let graphics = new Graphics()
let graphics = Graphics()

// set a fill and line style
graphics.beginFill(float 0xFF3300)
Expand Down Expand Up @@ -75,44 +74,53 @@ graphics.lineTo(600., 300.)
stage.addChild(graphics)

// let's create a moving shape
let mutable thing = new Graphics()
let thing = Graphics()
stage.addChild(thing)
thing.position.x <- 620. / 2.
thing.position.y <- 380. / 2.

let onClick() =
graphics.lineStyle( Math.random() * 30., Math.random() * float 0xFFFFFF, 1.) |>ignore
graphics.moveTo(Math.random() * 620.,Math.random() * 380.) |>ignore
graphics.bezierCurveTo((Math.random() * 620.),Math.random() * 380.,
Math.random() * 620.,Math.random() * 380.,
Math.random() * 620.,Math.random() * 380.) |> ignore
()
graphics.lineStyle(
Math.random() * 30., Math.random() * float 0xFFFFFF, 1.) |>ignore
graphics.moveTo(
Math.random() * 620., Math.random() * 380.) |>ignore
graphics.bezierCurveTo(
Math.random() * 620., Math.random() * 380.,
Math.random() * 620., Math.random() * 380.,
Math.random() * 620., Math.random() * 380.) |> ignore

stage.interactive <- true
// Just click on the stage to draw random lines
stage?on("click", fun e -> onClick())
//stage.on_click(fun e -> onClick()) // you can use this too
stage?on("tap", fun e -> onClick())

let mutable count = 0.

let rec animate (dt:float) =

thing.clear() |> ignore
count <- count + 0.1
thing.clear() |> ignore
thing.lineStyle(10., float 0xff0000, 1.) |> ignore
thing.beginFill(float 0xffFF00, 0.5) |> ignore

thing.moveTo(-120. + Math.sin(count) * 20., -100. + Math.cos(count)* 20.) |> ignore
thing.lineTo( 120. + Math.cos(count) * 20., -100. + Math.sin(count)* 20.) |> ignore
thing.lineTo( 120. + Math.sin(count) * 20., 100. + Math.cos(count)* 20.) |> ignore
thing.lineTo( -120. + Math.cos(count)* 20., 100. + Math.sin(count)* 20.) |> ignore
thing.lineTo( -120. + Math.sin(count) * 20., -100. + Math.cos(count)* 20.) |> ignore

thing.rotation <- count * 0.1
window.requestAnimationFrame(FrameRequestCallback animate) |> ignore
renderer.render(stage)
stage.on_click(fun _ -> onClick())
stage.on_tap(fun _ -> onClick())

let animate =
let mutable count = 0.
let rec animate (dt:float) =
thing.clear() |> ignore
count <- count + 0.1
thing.clear() |> ignore
thing.lineStyle(10., float 0xff0000, 1.) |> ignore
thing.beginFill(float 0xffFF00, 0.5) |> ignore
thing.moveTo(
-120. + Math.sin(count) * 20.,
-100. + Math.cos(count)* 20.) |> ignore
thing.lineTo(
120. + Math.cos(count) * 20.,
-100. + Math.sin(count)* 20.) |> ignore
thing.lineTo(
120. + Math.sin(count) * 20.,
100. + Math.cos(count)* 20.) |> ignore
thing.lineTo(
-120. + Math.cos(count)* 20.,
100. + Math.sin(count)* 20.) |> ignore
thing.lineTo(
-120. + Math.sin(count) * 20.,
-100. + Math.cos(count)* 20.) |> ignore
thing.rotation <- count * 0.1
window.requestAnimationFrame(FrameRequestCallback animate) |> ignore
renderer.render(stage)
animate

// start animating
animate 0.
Loading

0 comments on commit 621e856

Please sign in to comment.