C++ :: Draw The Same Sprite Multiple Times (SDL)?

Sep 7, 2014

I have a question about SDL and drawing sprites (SDL surfaces). My idea is that the user can create a wall of separate sprites by create one sprite each time in the current mouseX and mouseY position, when the user push down the e-key. The problem is that I have no idea how I could draw the same sprite multiple times without to delete the previous one.

View 3 Replies


ADVERTISEMENT

C/C++ :: Draw Sprite On The Window Of Third Party Application

May 8, 2014

How can I draw a sprite/graphic on the window of an third party application? E.g. I want to draw a graphic beneath each tab of Firefox for additional information. The position of the sprite needs to be relativ to the position of firefox, so if you move firefox, the sprite moves with it.

The solution needs to work on mac and pc. So I'll use a crossplatform framework like c++ boost or something.

Of course I can get the position and then just redraw it. But what's the best way to draw it?

Just found a tool which does what I need. Basically a HUD like this: [URL] .... The boxes with the numbers are what I need.

View 2 Replies View Related

C# :: Draw Multiple Rectangles With Mouse In Picturebox

Jun 6, 2014

I am trying to build a WinForm application that will allow you to load an image into a picturebox and then draw multiple rectangles (empty or translucent) to kind of highlight areas. I want all the rectangles to stay on the image (i can take care of a clear method later). The code below has the latest two attempts I've tried. One is all commented out and the other is not. Both will load the image just fine but neither will allow me to draw/select rectangles on the image.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;

[Code] ....

View 14 Replies View Related

Visual C++ :: Draw Multiple Lines And Move Them On Screen

Jul 28, 2013

I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines.

I have created rectangle region for each line and trying to move the line.

When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen.

How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC.

View 4 Replies View Related

C :: Reading File Multiple Times?

Apr 5, 2014

so i have to read a text file with an unknown number of lines and allocate memory to for the number of items in the text file.currently i read the entire file(counting the number of lines). i allocate memory according to the number of lines read and then use fseek() with an offset of zero to allow for the second read .

View 5 Replies View Related

C++ :: Using Getline Multiple Times On One Line Of Input

Sep 15, 2014

I've been stuck on this for hours, and have scoured the internet for any insight on this particular issue with no luck.

I'll simplify the problem here. I have a lines in an input file:

John Smith 1234 Main St New York
Carol Thomas 5678 5th Ave Columbus
...
and I am reading into character arrays using code like this:

infile.getline(name,20);
infile.getline(street,15);
infile.getline(city,10);

but when I print the output using something like this:

outfile << "Owner Name: " << name << endl;
outfile << "Address: " << street << city << endl;

(let's pretend I included spaces between the address components, which I omitted to save space)

I get an output file of:

Owner Name: John Smith
Address:

The output stops after the name variable, which I believe is stored correctly. I don't think anything is storing in the address pieces, this is the problem.

I think it's because I'm not using getline() properly in this case. Can you string together multiple getline()s like that?

If this was my design, I'd read in strings instead, but that is not possible in this case.

View 6 Replies View Related

C++ :: Private Inheritance Multiple Times From Same Class

Sep 19, 2014

I've been working on a program that uses a reference counting class that I've written which works fine for objects that inherit from it however I now need to have the following setup:

class SBComponent : private Refcounted { /*stuff*/}
class ProxiedComponent : public SBComponent, private Refcounted {/*stuff*/}

The compiler gives the following warnings

warning: direct base ‘Refcounted’ inaccessible in ‘ProxiedComponent’ due to ambiguity

And then several repeats of the error:

error: request for member ‘bk’ is ambiguous
Back *b = bk<ProxiedComponent>();

bk is a templated function that's defined in Refcounted and returns a pointer of type <template arg>::Back (ProxiedComponent::Back in this case).

I don't understand why the call to bk is ambiguous as although there's two instances of Refcounted (there needs to be with the way I've designed it so I can't make it virtual) it's inheritance is private in both cases so there should only be one instance of it visible in ProxiedComponent.

View 7 Replies View Related

C/C++ :: Object Is Being Added To A List Multiple Times?

Nov 6, 2014

I've been struggling with an object when trying to add it to a list with [Listname].push_back. You see, I have a list with some objects that will be rendered in the screen (Called objects) and a function to create a text box with some text. The function in question is the following:

void reprEv(int evNum, ALLEGRO_BITMAP *txtbxim) //Event to call, default text box image.
{
textBox *txtBox = new textBox("Line 1 ", "Line 2 ", "Line 3 ", "Line 4 ", "Line 5 ", textboximage);
objects.push_back(txtBox);

[Code]....

(txtNum is increased then space is pressed, and when certain screen (maxScreen) have been shown, then it will go to the playing state)

My problem begins when the text box is created, because it's supposed to add only 1 text box to objects list, but instead adds hundreds of text boxes to objects.

View 1 Replies View Related

C++ :: Using Malloc / Free Multiple Times Leaves Less Memory?

Apr 17, 2014

My application calls malloc in multiple subroutines, finally releasing all using free. This is done using my zalloc library (see my other post: [URL] .....

Somehow, when the applications tries to detect the available ammount of memory at the end of the test (allocating, freeing, testing), the freemem function gives me about 4-6MB less memory than at the start of the test? (out of 21MB available on the device at the start).

All memory is allocated and freed using the malloc/free routines within the library, with the exception of the SDL functions, which are registered externally on allocation and release.

View 3 Replies View Related

C++ :: Writing Data On A File In Binary Mode Multiple Times

Oct 20, 2013

When you have to write data on a file in binary mode multiple times (without closing the file), is the put pointer left where you ended writing the last time, or do you have to use tellp() or seekp() again and again to make sure you write at the right place?

I would have the same question about the get pointer, does he stay in place after you're done reading something (without closing the file, of course), or do you have to set it back at the right place with seekg() ??

View 5 Replies View Related

C++ :: 2D Sprite Shakes While Being Followed By Camera

Jan 28, 2013

I'm making my view follow around my players ship, so it is always in the center, however at any angle other than 0/90/180/270 the player sprite starts shaking, more so when speed is increased and when the angle is closer to 45/135/225/315

I'm using SFML2, I would take a screenshot but it only captures one frame, which doesn't actually show it shaking.

void ViewFollowPlayer(sf::View& View, sf::RenderWindow& Window, double Delta)
{
double pSpeed = Player.getSpeed();

[Code].....

View 3 Replies View Related

C++ :: Getting Sprite To Animate With SFML

Dec 10, 2013

So this is my first try animating on my own, without a reference right in front of me. It's not working, I did check some of the projects I've made in the past, but for one those were done with Allegro, and really it should be able to move over to SFML quite easily, but it's not. It does display on the window in the correct place, but there are 3 pictures in the file and I want it to cycle through them, but it shows all three at the same time, and it only works once. if I press space a second time, only one of the pictures shows up, and it doesn't cycle at all. Here is my .cpp file :

#include "headers.h"
#include "SwordSprite.h"
int top = 0;
int left = 88;
int right = 132;
int bottom = 35;
SwordSprite::SwordSprite() {

[Code] .....

View 2 Replies View Related

C++ :: How To Move Sprite Depending On Rotation

Jan 13, 2015

how I want my sprite movement to work: if my sprite is faced upwards and i press W, it will move up. If my sprite is faced to the right and i press W, it will go right. etc. // It doesn't work like that right now and how to do it.The sprite's rotation works fine.

if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
playerSprite.rotate(-0.08 * dt);
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
playerSprite.rotate(0.08 * dt);

[code]....

My question is how do I move the character depending on the rotation?

Also, you might see the "if(havePlayersCollided == false) {playerSprite.move(yadiyada)}" . yes i dont need the haveplayerscollided function because it doesnt work the way I want it to. I might make a thread for it in the future, but right now I need to get the rotation movement fixed before I move onto the collision detection between players.

View 7 Replies View Related

C++ :: Make Object Rotate Until It Looks At The Sprite?

Oct 10, 2013

Is there a way to make an object rotate until it looks at the sprite?

View 1 Replies View Related

C++ :: Allegro Sprite Is Not Showing Up In Right Spot

Jun 8, 2013

So I have a small game I'm making using OOP principles, I know it's a little bit of overkill but it's just for educational purposes. I have a sprite character that can be moved around with no problems, but I made a sword for him as a separate sprite that doesn't follow him. The sword sprite is supposed to cover his arm and his body as it swings, but it just stays in the upper left corner.

I messed around with the initialization of the sword in the main.cpp and I changed in sword.cpp and sword.h and it still is showing up in the same place. I even looked at the GetX() and GetY() statements I made and they seemed to work fine and when I debugged it, the variable values showed up correctly, but the sword doesn't move.

View 3 Replies View Related

C++ :: 2D RPG Game - Smooth Sprite Movement (SDL)

Feb 7, 2015

I'm making a 2D rpg game, but I have some problem with the sprite movement. The sprite movement feels choppy. That's because I move the sprite 5 pixels per seconds. I now that I need somthing that have to do with SDL_getTicks and deltatime, but I dont know how to use/implement it.

Here is a little part of my code:

float spriteDstY;
float spriteDstX;
float speed = 5;
while(SDL_PollEvent(&event)!= 0) {
if (event.type == SDL_QUIT)

[Code] ....

View 8 Replies View Related

C++ :: How To Get Smooth Sprite Movement In SDL By Using Delta Time

Nov 30, 2014

I'm trying to get smooth sprite movement in SDL by using delta time. The way I'm calculating it is

long last = 0;
float deltaTime = 0.0;
...
long now = SDL_GetTicks();
//deltatime is in seconds
if (now > last) {
deltaTime = ((float)(now - last)) / 1000;
last = now;
}

And I'm updating the sprite like this:

virtual void update(float deltaTime) {
float dx = 100*deltaTime;
transform->position.x += dx;
}

But the movement is still noticeably jerky. Also, if I'm correct, my sprite should move 100 pixels to the right every second using this method, so it should take the sprite 8 seconds to reach the end of my window, since it's 800 pixels wide, but it takes it way longer than that. In other words the delta time I'm calculating can't be correct. Am I doing something horribly wrong? I'm guessing it has something to do with rounding, but I'm not sure.

View 2 Replies View Related

C++ :: How To Draw A Polygon

Nov 16, 2013

I am fairly new to c++, and I want to be able to draw a polygon. When I have searched for how to draw one, the only thing i can find is scripts doing things like this:

*
**
***
****
*****

I doubt that c++ is that primitive, and I'm looking for something like the c++ equivalent of this python script:

Syntax: draw.polygon((20,20)(30,30)(50,30)(20,40)(20,20), fill(green))

I am using a mac os 10.9

View 2 Replies View Related

C :: Draw A Grid Using The Characters?

Aug 20, 2013

I'm trying to create a grid using the following characters: !, @, #, $, &.

It's an 8 x 8 grid, and should contain the characters in no particular order (trying to create a Bejeweled-like game).

I already defined the width and length to be 8, so:

#define WIDTH 8
#define LENGTH 8

Code:

void makegrid(char grid[])
{
int j;
int k;
for ( j = -1; j < LENGTH; j++ )
{
for ( k = -1; k < WIDTH; k++ )
{
/* I don't know what to type here anymore :( */
}
} }

View 14 Replies View Related

C++ :: OpenGL - Draw On Top Of Image

Jun 22, 2014

This is my first time using opengl and I am experimenting with adding/drawing polygons/points/etc. on top of a PPM image. The image is already loaded when the application runs. My attempt to draw a square is from lines 30 - 35. The program runs but the square is not present. Just the image.

#include<windows.h>
#include <stdio.h>
#include <stdlib.h>
#include<Gl/gl.h>
#include<GL/glut.h>

int n;
int m;
int *image;

[Code] ....

View 5 Replies View Related

C++ :: How To Draw A 3D Snake In OpenGL

Jan 3, 2014

i want to draw a 3D snake in opengl.. i can't get nothing out of my search to make a start.. how it is made

View 4 Replies View Related

C++ :: How To Draw Lines With Different Colors

Nov 8, 2014

I want to write a function called DrawLineSegments.This function must change the color of lines at every corner where the corner angle is greater than 60 deg (Assume that there is a function called checkangle). The color sequence must be black, red, green, blue, and repeat this sequence after the fourth color.

View 1 Replies View Related

C++ :: Draw 2D Bar Chart According To 10 Or 15 Numbers?

Nov 26, 2013

I want to draw a 2D bar chart according to 10 or 15 numbers in c++. How can i do it? Which i need components?

View 1 Replies View Related

C++ :: How To Draw A Magnifying Glass

Jul 11, 2013

I want to draw a magnifying glass using graphics.h which is used mostly as "Search" icon. But, I am having problems in making the rectangle attached to the two circles (one inscribed on another) . I have also included the screenshot (made in powerpoint) on how the output will look like, enen I've made most of the part, except the search icon (magnifying glass).

The Link for the screenshot is : [URL] ....

View 3 Replies View Related

C/C++ :: How To Draw Shapes Using Loop

Apr 11, 2014

How can I draw thus shape using loop for
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5

Also this shape
1*****
12****
123***
1234**
12345*
123456

View 6 Replies View Related

C# :: How To Draw More Than One Line In WPF Using Array

Jul 8, 2014

I used the following code. I called a method named lets_draw

private void lets_draw() {
int i,z;
z = 40;
Line[] line = new Line[20];
for(i=1;i<=10;i++) {

[Code] ....

But it showed the following message

"An unhandled exception of type 'System.NullReferenceException' occurred in SkeletalTracking.exe
Additional information: Object reference not set to an instance of an object."

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved