How to fade out text after a second in GameMaker - game-maker

In my game, if the player goes through a door, I would like to have text appear for one second and then fade out.
I'm using GameMaker:Studio 1.4

Create an object, for example obj_text, with the following events:
Create event:
alpha = 1;
fade_out = false;
alarm[0] = 60; // Time in frames
Alarm 0 event:
fade_out = true;
Step event:
if (fade_out) {
alpha -= 0.05;
}
if (alpha <= 0) {
instance_destroy();
}
Draw event:
draw_set_alpha(alpha);
draw_text(x, y, "You went through a door");
draw_set_alpha(1);
When the player goes through a door, simply use instance_create(x, y, obj_text) to display the text.

Create a new object for example "obj_text".
Create event:
count = 0
alpha = 1
delay = 1 // in seconds
Step event:
if (count == room_speed * delay) {
alpha -= 0.05
draw_set_alpha(alpha)
if (image_alpha <= 0) {
instance_destroy();
}
}
else {
count += 1
}
draw_text(x, y, "You went through a door")
draw_set_alpha(1);
When the player goes through the door you simply use
instance_create( x, y, obj_text)
to display the text.
You can change the value of delay to define how long the text should be shown until it starts to fade out.

Related

QCustomPlot vertical line at axis

I am working QCustomPlot with Qt and need to change the color of a particular vertical grid line within the graph please let us know how we can change that I attached the image of my requirement.
The bleo code solve the issue
GraphTesting(QCustomPlot * customPlot)
{
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i = 0; i < 101; ++i)
{
x[i] = i; //i / 50.0 - 1; // x goes from -1 to 1
y[i] = x[i]/2; // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
customPlot->rescaleAxes();
QCPItemLine *step = new QCPItemLine(customPlot);
step->setPen(QPen(QColor(140, 0, 0)));
double begin = 25;
double first = customPlot->yAxis->range().lower;
double end = customPlot->yAxis->range().upper; //example values
step->start->setCoords(begin, first);
step->end->setCoords(begin, end);
customPlot->replot();
}

PixelWriten canvas won't display on screen

I have an intArray of ints corresponding to pixel RGB values and am trying to write them to an image that I then add to a canvas displayed in a view.
I have followed the JavaFX docs guideline for using a pixelWriter and I know my syntax for adding a canvas to the view is correct cause I have done the same elsewhere I my app and tested putting a different canvas here correctly.
I've tried the context way:
View class:
vbox(20.0, Pos.BOTTOM_CENTER) {
if (controller.t > 100) { //same results with or without this
label("IR camera view title")
children.add(controller.rPiSensors.canvasIR)
}
}
Model class:
val canvasIR = Canvas(lIR_WIDTH_RES.toDouble(), lIR_HEIGHT_RES.toDouble())
val gc: GraphicsContext = canvasIR.graphicsContext2D
var lIRPixelWriter = gc.pixelWriter
for (y in 0 until 32) {
for (x in 0 until 24) {
lIRPixelWriter.setPixels(0,0,lIR_WIDTH_RES,lIR_HEIGHT_RES, PixelFormat.getIntArgbInstance(), lIRHeatMapPixelInts, 0 , lIR_WIDTH_RES)
}
}
I've also tried the WritableImage way as mentioned in this SO post Creating a Javafx image from a int array:
View class:
vbox(20.0, Pos.BOTTOM_CENTER) {
if (controller.t > 100) { //same results with or without this
label("IR camera view title")
//tested this too controller.rPiSensors.imageView.show()
children.add(controller.rPiSensors.imageView)
}
}
Model class:
var lIRHeatMapPixelInts = IntArray(768) //24*32
//write to this in calculateIRPixelHelper below
var lIRHeatImage = WritableImage(lIR_WIDTH_RES, lIR_HEIGHT_RES)
var lIRPixelWriter = lIRHeatImage.pixelWriter
val imageView = ImageView(lIRHeatImage)
for (y in 0 until 32) {
for (x in 0 until 24) {
lIRPixelWriter.setPixels(0,0,lIR_WIDTH_RES,lIR_HEIGHT_RES, PixelFormat.getIntArgbInstance(), lIRHeatMapPixelInts, 0 , lIR_WIDTH_RES)
}
}
function to get IR RGBInt from float value of temperature (shown to be correct on RasPi that acquires data, and I have compared my received data vs snet RasPi data)
fun calculateIRPixelHelper(x : Int, y : Int, v : Float) {
//float color[NUM_COLORS][3] = { {0;0;0}; {0;0;1}; {0;1;0}; {1,1,0},{1,0,0}, {1,0,1}, {1,1,1} }
val color : Array<FloatArray> = arrayOf(floatArrayOf(0.0f,0.0f,0.0f), floatArrayOf(0.0f,0.0f,1.0f), floatArrayOf(0.0f,1.0f,0.0f), floatArrayOf(1.0f,1.0f,0.0f), floatArrayOf(1.0f,0.0f,0.0f), floatArrayOf(1.0f,0.0f,1.0f), floatArrayOf(1.0f,1.0f,1.0f))
var outputV = v
val idx1 : Int
val idx2 : Int
var fractBetween = 0.0f
val vmin = 5.0f
val vmax = 50.0f
val vrange = vmax-vmin
outputV -= vmin
outputV /= vrange
val ir : Int
val ig : Int
val ib : Int
val pixelRGBInt : Int
if (outputV <= 0) {
idx1= 0
idx2= 0
} else if (outputV >= 1) {
idx1 = (NUM_COLORS-1)
idx2 = (NUM_COLORS-1)
} else {
outputV *= (NUM_COLORS-1)
idx1 = truncate(outputV).toInt()
idx2 = idx1+1
fractBetween = outputV - idx1
}
ir = ((((color[idx2][0] - color[idx1][0]) * fractBetween) + color[idx1][0]) * 255.0).toInt()
ig = ((((color[idx2][1] - color[idx1][1]) * fractBetween) + color[idx1][1]) * 255.0).toInt()
ib = ((((color[idx2][2] - color[idx1][2]) * fractBetween) + color[idx1] [2]) * 255.0).toInt()
pixelRGBInt = (ir shl 16) or (ig shl 8) or ib
for(py in 0 until IMAGE_SCALE) {
for(px in 0 until IMAGE_SCALE) {
lIRHeatMapPixelInts[x + px + IMAGE_SCALE*(y + py)] = pixelRGBInt
}
}
}
Here are the float values of the temperature
the pixel ints, which are all 0 beyond the first ~50
And part of the list of values saved in the canvas
For the first method, there are 133K dirty bits written in the canvas and when I use the debugger it seems that PixelWriter.setPixels is writing over bits on almost every call but slowly progressing in increasing values (the trend is like this:
write val pos = 12, 30, 62, 12, 30, 62, 78, 99, 10 ...
I can copy down the exact numbers if this is suspected to be the issue)
In both cases I thought the issue was in updating the canvas once it's populated but I have eliminated this theory by only adding the canvas once a flag is set in the models--still nothing appears besides the title of the canvas.
I have spent about a full workday on trying to display this, any help would be GREATLY appreciated :)
Alpha bits were set to zero, must set them in the pixelRGBint high bits to non-zero for a non transparent pixel!

WebGL Walkthrough, Move around the 3D scene

I'm new to WebGL, and I'm trying to create a walk-through for a website, I have taken my Maya model into WebGL with the help of inka3D, but when I apply the following code for the movement, it doesn't work as it explains. Only the left arrow works fine.
function resize()
{
var width = canvas.offsetWidth;
var height = canvas.offsetHeight;
canvas.width = width;
canvas.height = height;
aspect = width / height;
}
var cameraTargetX = 37.2878151;
var cameraTargetY = 12.846137;
var cameraTargetZ = 7.17901707;
var dx = 5;
var dy = 5;
window.addEventListener('keydown',doKeyDown,true);
function doKeyDown(evt){
switch (evt.keyCode) {
case 38: /* Up arrow was pressed */
if (cameraTargetY - dy > 0){
cameraTargetY -= dy;
}
break;
case 40: /* Down arrow was pressed */
if (cameraTargetY + dy < height){
cameraTargetY += dy;
}
break;
case 37: /* Left arrow was pressed Fine*/
if (cameraTargetX - dx > 0){
cameraTargetX -= dx;
}
break;
case 39: /* Right arrow was pressed */
if (cameraTargetX + dx < width){
cameraTargetX += dx;
}
break;
}
}
};
If only the left arrow works this means that difference of (cameraTargetX - dx ) > 0. Thats why you can translate. The reason is cameraTargetX is 37 diff of 5 make it 32 and on key press you can visualize this in 5X7(loop). Key is pressed 7 times until the value become lesser than zero
But when var cameraTargetY = 12.846137; and dy is 5 it take only 5x2(loop) just a fraction and the value become lesser than zero and you can visualize the diff.
Solution is as stated dx and dy are delta values means this should be very small as variable convection so try with
var dx = 0.05;
var dy = 0.05;
You will get answer. If any doubt feel free to ask

AutoHotkey Detecting PixelColor for longer then x Seconds

I'm on version AHL_L 32Bit 1.1.05.06
I'm looking for a logical way to detect on AutoHotkey if a pixel is up for x amount of time, after 15 seconds, I'm assuming it crashed and we're gonna refresh.
My current code is like this:
CrashCheck:
if stuckinbonus = 0x1D001A
{
if(FoundCrash = 0) {
FirstFound := A_Tickcount
FoundCrash = 1
} else {
CrashCheckTime := A_Tickcount - FirstFound
}
if(CrashCheckTime >= 15000){
SetTimer,CrashCheck,off
MsgBox,Refreshing page (Pseudo Code)
}
}
return
I've tried putting the variables as global like this at the start of the script, but I'm running into issues with the CrashCheckTime just being 0 :/ Any ideas?
Global FoundCrash := ""
Global FirstFound := "0"
Global CrashCheckTime:= ""
Would this do the job?
#SingleInstance Force
#installKeybdHook
#Persistent
SetTimer, CrashCheck, 1000 ; run CrashCheck every second
MyAlert := 0
Return
CrashCheck:
PixelGetColor, Color, 100, 100
If (Color = 0x1D001A)
{
MyAlert++
}
Else
{
MyAlert := 0
}
If (MyAlert > 15)
{
MyAlert := 0
Refresh Page
}
Return
With regard to your own code. Could it be that you do not set the FoundCrash := 0 before running the CrashCheck? This way you will NEVER get true for the If (FoundCrash = 0) and thus ALWAYS jump to the Else choise.
Example:
#SingleInstance Force
#installKeybdHook
#Persistent
;FoundCrash := 0 ; Script fails when this line is commented out!
stuckinbonus = 0x1D001A
!t:: ; [Alt]+t to simulate CrashCheck
If (stuckinbonus = 0x1D001A)
{
If (FoundCrash = 0)
{
SoundBeep, 500, 500 ;(Low beep)
FirstFound := A_Tickcount
FoundCrash := 1
}
Else
{
SoundBeep, 1500, 500 ;(High beep)
CrashCheckTime := A_Tickcount - FirstFound
}
If (CrashCheckTime >= 15000)
{
;SetTimer,CrashCheck,off
FoundCrash := 0
MsgBox,Refreshing page (Pseudo Code)
}
}
Return
I suggest you run this in debug mode inside SciTE4AutoHotKey, to see which branches are taken and what the variable values are during step by step execution.
I wrote a little function that loops, waits, and keeps looping until it sees the desired pixel colour at the desired coordinates. Maybe this is helpful?
;This function checks the Pixel at the provided coordinates and waits until the colour matches the provided parameter
WaitForLoad(PixelColorX,PixelColorY,PixelColorValue)
{
CycleCount = 0
PixelGetColor SearchPixel, PixelColorX, PixelColorY
;msgbox "Found Pixel %SearchPixel% at %PixelColorX%, %PixelColorY%, Looking for %PixelColorValue%" ;DEBUGG ASSISTANT
While (SearchPixel != PixelColorValue)
{
CycleCount = CycleCount + 1
sleep 100
; Tooltip Waiting to detect pixels HERE!, PixelColorX, PixelColorY ; Doesn't work
PixelGetColor SearchPixel, PixelColorX, PixelColorY
}
sleep 500
;Debug
;msgbox Exiting Function with %PixelColorValue% at %PixelColorX%, %PixelColorY% after %CycleCount% Cycles.
SearchPixel = 0
PixelColorValue = 1

Tournament Brackets algorithm

I need to create an asp.net page that auto generate a brackets tournament tennis style.
Regarding the managing of match in database, it's not a problem.
The problem is the dynamic graphics creation of brackets.
The user will be able to create tournament by 2-4...32 players.
And i don't know ho to create the graphics bracket in html or gdi...
Using Silverlight, and a Grid, You can produce something like this:
To do it, define a regular UserControl containing a Grid. (This is the default when you build a silverlight app in VS2008 with the Silverlight 3.0 SDK).
Then, add a call to the following in the constructor for the user control:
private void SetupBracket(int n)
{
var black = new SolidColorBrush(Colors.Gray);
// number of levels, or rounds, in the single-elim tourney
int levels = (int)Math.Log(n, 2) + 1;
// number of columns in the Grid. There's a "connector"
// column between round n and round n+1.
int nColumns = levels * 2 - 1;
// add the necessary columns to the grid
var cdc = LayoutRoot.ColumnDefinitions;
for (int i = 0; i < nColumns; i++)
{
var cd = new ColumnDefinition();
// the width of the connector is half that of the regular columns
int width = ((i % 2) == 1) ? 1 : 2;
cd.Width = new GridLength(width, GridUnitType.Star);
cdc.Add(cd);
}
var rdc = LayoutRoot.RowDefinitions;
// in the grid, there is one row for each player, and
// an interleaving row between each pair of players.
int totalSlots = 2 * n - 1;
for (int i = 0; i < totalSlots; i++)
{
rdc.Add(new RowDefinition());
}
// Now we have a grid of the proper geometry.
// Next: fill it.
List<int> slots = new List<int>();
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("Bridge.png", UriKind.Relative));
// one loop for each level, or "round" in the tourney.
for (int j = 0; j < levels; j++)
{
// Figure the number of players in the current round.
// Since we insert the rounds in the reverse order,
// think of j as the "number of rounds remaining."
// Therefore, when j==0, playersThisRound=1.
// When j == 1, playersThisRound = 2. etc.
int playersThisRound = (int)Math.Pow(2, j);
int x = levels - j;
int f = (int)Math.Pow(2, x - 1);
for (int i = 0; i < playersThisRound; i++)
{
// do this in reverse order. The innermost round is
// inserted first.
var r = new TextBox();
r.Background = black;
if (j == levels - 1)
r.Text = "player " + (i + 1).ToString();
else
r.Text = "player ??";
// for j == 0, this is the last column in the grid.
// for j == levels-1, this is the first column.
// The grid column is not the same as the current
// round, because of the columns used for the
// interleaved connectors.
int k = 2 * (x - 1);
r.SetValue(Grid.ColumnProperty, k);
int m = (i * 2 + 1) * f - 1;
r.SetValue(Grid.RowProperty, m);
LayoutRoot.Children.Add(r);
// are we not on the last round?
if (j > 0)
{
slots.Add(m);
// Have we just inserted two rows? Then we need
// a connector between these two and the next
// round (the round previously added).
if (slots.Count == 2)
{
string xamlTriangle = "<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' "+
"xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' " +
"Data='M0,0 L 100 50 0 100 Z' Fill='LightBlue' Stretch='Fill'/>";
Path path = (Path)System.Windows.Markup.XamlReader.Load(xamlTriangle);
path.SetValue(Grid.ColumnProperty, 2 * (x - 1) + 1);
path.SetValue(Grid.RowProperty, slots[0]);
path.SetValue(Grid.RowSpanProperty, slots[1] - slots[0] + 1);
this.LayoutRoot.Children.Add(path);
slots.Clear();
}
}
}
}
}
In the above, the connector is just an isosceles triangle, with the apex pointing to the right. It is generated by XamlReader.Load() on a string.
You would also want to pretty it up, style it with different colors and fonts, I guess.
You can insert this silverlight "user control" into any HTML web page, something like embedding a flash app into a page. There are silverlight plugins for IE, Firefox, Opera, Safari, and Chrome.
If you don't want to use Silverlight, you could use a similar approach to construct an HTML table.

Resources